Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion authors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ jhall-openai:
name: "Josh Hall"
website: "https://www.linkedin.com/in/jhall14/"
avatar: "https://avatars.githubusercontent.com/u/198997750?v=4"

charlie-openai:
name: "Charlie Weems"
website: "https://wee.ms"
Expand Down
51 changes: 13 additions & 38 deletions examples/codex/Autofix-github-actions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"id": "e2884696",
"metadata": {},
"source": [
"# Autofix CI failures on GitHub with Codex-cli\n",
"# Autofix CI failures on GitHub with Codex CLI\n",
"\n",
"## Purpose of this cookbook\n",
"\n",
Expand Down Expand Up @@ -44,7 +44,7 @@
"metadata": {},
"source": [
"\n",
"## Step 3: Insert Codex in your CI pipeline\n",
"## Step 1: Add the Github Action to your CI Pipeline\n",
"\n",
"The following YAML shows a GitHub action that auto triggers when CI fails, installs Codex, uses codex exec and then makes a PR on the failing branch with the fix. Replace \"CI\" with the name of the workflow you want to monitor. "
]
Expand All @@ -55,7 +55,6 @@
"metadata": {},
"source": [
"```yaml\n",
"\n",
"name: Codex Auto-Fix on Failure\n",
"\n",
"on:\n",
Expand All @@ -80,14 +79,13 @@
" FAILED_HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}\n",
" FAILED_HEAD_SHA: ${{ github.event.workflow_run.head_sha }}\n",
" steps:\n",
" - name: Check prerequisites\n",
" - name: Check OpenAI API Key Set\n",
" run: |\n",
" if [ -z \"$OPENAI_API_KEY\" ]; then\n",
" echo \"OPENAI_API_KEY secret is not set. Skipping auto-fix.\" >&2\n",
" exit 1\n",
" fi\n",
"\n",
" - name: Checkout failing ref\n",
" - name: Checkout Failing Ref\n",
" uses: actions/checkout@v4\n",
" with:\n",
" ref: ${{ env.FAILED_HEAD_SHA }}\n",
Expand All @@ -102,34 +100,13 @@
" - name: Install dependencies\n",
" run: |\n",
" if [ -f package-lock.json ]; then npm ci; else npm i; fi\n",
"\n",
" - name: Prepare Codex prerequisites\n",
" shell: bash\n",
" run: |\n",
" # Ensure python3 exists for Codex' login helper\n",
" if ! command -v python3 >/dev/null 2>&1; then\n",
" sudo apt-get update\n",
" sudo apt-get install -y python3\n",
" fi\n",
"\n",
" # Ensure Codex config dir exists and is writable\n",
" mkdir -p \"$HOME/.codex\"\n",
" # (Optional) pin an explicit home for Codex config/logs\n",
" echo \"CODEX_HOME=$HOME/.codex\" >> $GITHUB_ENV\n",
"\n",
" - name: Install Codex CLI\n",
" run: npm i -g @openai/codex\n",
"\n",
" - name: Authenticate Codex (non-interactive)\n",
" env:\n",
" # if you set CODEX_HOME above, export it here too\n",
" CODEX_HOME: ${{ env.CODEX_HOME }}\n",
" OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}\n",
" run: codex login --api-key \"$OPENAI_API_KEY\"\n",
"\n",
" - name: Run Codex to fix CI failure\n",
" run: |\n",
" codex exec --full-auto --sandbox workspace-write \"You are working in a Node.js monorepo with Jest tests and GitHub Actions. Read the repository, run the test suite, identify the minimal change needed to make all tests pass, implement only that change, and stop. Do not refactor unrelated code or files. Keep changes small and surgical.\"\n",
" - name: Run Codex\n",
" uses: openai/codex-action@main\n",
" id: codex\n",
" with:\n",
" openai_api_key: ${{ secrets.OPENAI_API_KEY }}\n",
" prompt: \"You are working in a Node.js monorepo with Jest tests and GitHub Actions. Read the repository, run the test suite, identify the minimal change needed to make all tests pass, implement only that change, and stop. Do not refactor unrelated code or files. Keep changes small and surgical.\"\n",
" codex_args: '[\"--config\",\"sandbox_mode=\\\"workspace-write\\\"\"]'\n",
"\n",
" - name: Verify tests\n",
" run: npm test --silent\n",
Expand All @@ -144,10 +121,8 @@
" title: \"Auto-fix failing CI via Codex\"\n",
" body: |\n",
" Codex automatically generated this PR in response to a CI failure on workflow `${{ env.FAILED_WORKFLOW_NAME }}`.\n",
"\n",
" Failed run: ${{ env.FAILED_RUN_URL }}\n",
" Head branch: `${{ env.FAILED_HEAD_BRANCH }}`\n",
"\n",
" This PR contains minimal changes intended solely to make the CI pass.\n",
"```\n"
]
Expand All @@ -157,7 +132,7 @@
"id": "8148024b",
"metadata": {},
"source": [
"## Step 4: Actions Workflow kicked off\n",
"## Step 2: Actions Workflow kicked off\n",
"\n",
"You can navigate to the Actions tab under Repo to view the failing jobs in your Actions workflow. \n",
"\n",
Expand All @@ -181,7 +156,7 @@
"id": "d08a3ecc",
"metadata": {},
"source": [
"## Step 5: Codex generated PR for review\n",
"## Step 3: Verify that Codex Created a PR for Review\n",
"And after the Codex workflow completes execution, it should open a pull request from the feature branch codex/auto-fix. Check to see if everything looks good and then merge it.\n",
"\n",
"<img src=\"../../images/codex-pr.png\" width=\"700\"/>\n",
Expand Down
3 changes: 2 additions & 1 deletion registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2542,12 +2542,13 @@
- images


- title: Codex CLI to automatically fix CI failures
- title: Use Codex CLI to automatically fix CI failures
path: examples/codex/Autofix-github-actions.ipynb
date: 2025-09-30
authors:
- himadri518
- alwell-kevin
- charlie-openai
tags:
- codex

Expand Down