From be247d5ba1d7faeca7e05e064ca986aec1014a47 Mon Sep 17 00:00:00 2001 From: Charlie Weems Date: Fri, 3 Oct 2025 03:30:58 -0700 Subject: [PATCH 1/2] Refactor to use github action --- authors.yaml | 4 ++ examples/codex/Autofix-github-actions.ipynb | 47 ++++++--------------- registry.yaml | 3 +- 3 files changed, 19 insertions(+), 35 deletions(-) diff --git a/authors.yaml b/authors.yaml index 819ed864b2..308564bf97 100644 --- a/authors.yaml +++ b/authors.yaml @@ -505,3 +505,7 @@ jhall-openai: avatar: "https://avatars.githubusercontent.com/u/198997750?v=4" +charlie-openai: + name: "Charlie Weems" + website: "https://wee.ms" + avatar: "https://avatars.githubusercontent.com/u/181146176?v=4" \ No newline at end of file diff --git a/examples/codex/Autofix-github-actions.ipynb b/examples/codex/Autofix-github-actions.ipynb index b42f88045f..be1eda33ef 100644 --- a/examples/codex/Autofix-github-actions.ipynb +++ b/examples/codex/Autofix-github-actions.ipynb @@ -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", @@ -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. " ] @@ -80,14 +80,14 @@ " 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", @@ -103,33 +103,12 @@ " 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", "\n", " - name: Verify tests\n", " run: npm test --silent\n", @@ -139,7 +118,7 @@ " uses: peter-evans/create-pull-request@v6\n", " with:\n", " commit-message: \"fix(ci): auto-fix failing tests via Codex\"\n", - " branch: codex/auto-fix-${{ github.event.workflow_run.run_id }}\n", + " branch: codex/auto-fix-${{ github.event.workflow_run.id }}\n", " base: ${{ env.FAILED_HEAD_BRANCH }}\n", " title: \"Auto-fix failing CI via Codex\"\n", " body: |\n", @@ -157,7 +136,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", @@ -181,7 +160,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", "\n", diff --git a/registry.yaml b/registry.yaml index ffc947f8c7..2d67066da1 100644 --- a/registry.yaml +++ b/registry.yaml @@ -2541,12 +2541,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 From 07064734c4e573cc0225bcb4aff0a67d01cd22c7 Mon Sep 17 00:00:00 2001 From: Charlie Weems Date: Fri, 3 Oct 2025 12:07:28 -0700 Subject: [PATCH 2/2] Add workspace write --- examples/codex/Autofix-github-actions.ipynb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/examples/codex/Autofix-github-actions.ipynb b/examples/codex/Autofix-github-actions.ipynb index be1eda33ef..3633560801 100644 --- a/examples/codex/Autofix-github-actions.ipynb +++ b/examples/codex/Autofix-github-actions.ipynb @@ -55,7 +55,6 @@ "metadata": {}, "source": [ "```yaml\n", - "\n", "name: Codex Auto-Fix on Failure\n", "\n", "on:\n", @@ -86,7 +85,6 @@ " echo \"OPENAI_API_KEY secret is not set. Skipping auto-fix.\" >&2\n", " exit 1\n", " fi\n", - "\n", " - name: Checkout Failing Ref\n", " uses: actions/checkout@v4\n", " with:\n", @@ -102,13 +100,13 @@ " - name: Install dependencies\n", " run: |\n", " if [ -f package-lock.json ]; then npm ci; else npm i; fi\n", - "\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", + " 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", @@ -118,15 +116,13 @@ " uses: peter-evans/create-pull-request@v6\n", " with:\n", " commit-message: \"fix(ci): auto-fix failing tests via Codex\"\n", - " branch: codex/auto-fix-${{ github.event.workflow_run.id }}\n", + " branch: codex/auto-fix-${{ github.event.workflow_run.run_id }}\n", " base: ${{ env.FAILED_HEAD_BRANCH }}\n", " 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" ]