|
5 | 5 | "id": "e2884696",
|
6 | 6 | "metadata": {},
|
7 | 7 | "source": [
|
8 |
| - "# Autofix CI failures on GitHub with Codex-cli\n", |
| 8 | + "# Autofix CI failures on GitHub with Codex CLI\n", |
9 | 9 | "\n",
|
10 | 10 | "## Purpose of this cookbook\n",
|
11 | 11 | "\n",
|
|
44 | 44 | "metadata": {},
|
45 | 45 | "source": [
|
46 | 46 | "\n",
|
47 |
| - "## Step 3: Insert Codex in your CI pipeline\n", |
| 47 | + "## Step 1: Add the Github Action to your CI Pipeline\n", |
48 | 48 | "\n",
|
49 | 49 | "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. "
|
50 | 50 | ]
|
|
55 | 55 | "metadata": {},
|
56 | 56 | "source": [
|
57 | 57 | "```yaml\n",
|
58 |
| - "\n", |
59 | 58 | "name: Codex Auto-Fix on Failure\n",
|
60 | 59 | "\n",
|
61 | 60 | "on:\n",
|
|
80 | 79 | " FAILED_HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}\n",
|
81 | 80 | " FAILED_HEAD_SHA: ${{ github.event.workflow_run.head_sha }}\n",
|
82 | 81 | " steps:\n",
|
83 |
| - " - name: Check prerequisites\n", |
| 82 | + " - name: Check OpenAI API Key Set\n", |
84 | 83 | " run: |\n",
|
85 | 84 | " if [ -z \"$OPENAI_API_KEY\" ]; then\n",
|
86 | 85 | " echo \"OPENAI_API_KEY secret is not set. Skipping auto-fix.\" >&2\n",
|
87 | 86 | " exit 1\n",
|
88 | 87 | " fi\n",
|
89 |
| - "\n", |
90 |
| - " - name: Checkout failing ref\n", |
| 88 | + " - name: Checkout Failing Ref\n", |
91 | 89 | " uses: actions/checkout@v4\n",
|
92 | 90 | " with:\n",
|
93 | 91 | " ref: ${{ env.FAILED_HEAD_SHA }}\n",
|
|
102 | 100 | " - name: Install dependencies\n",
|
103 | 101 | " run: |\n",
|
104 | 102 | " if [ -f package-lock.json ]; then npm ci; else npm i; fi\n",
|
105 |
| - "\n", |
106 |
| - " - name: Prepare Codex prerequisites\n", |
107 |
| - " shell: bash\n", |
108 |
| - " run: |\n", |
109 |
| - " # Ensure python3 exists for Codex' login helper\n", |
110 |
| - " if ! command -v python3 >/dev/null 2>&1; then\n", |
111 |
| - " sudo apt-get update\n", |
112 |
| - " sudo apt-get install -y python3\n", |
113 |
| - " fi\n", |
114 |
| - "\n", |
115 |
| - " # Ensure Codex config dir exists and is writable\n", |
116 |
| - " mkdir -p \"$HOME/.codex\"\n", |
117 |
| - " # (Optional) pin an explicit home for Codex config/logs\n", |
118 |
| - " echo \"CODEX_HOME=$HOME/.codex\" >> $GITHUB_ENV\n", |
119 |
| - "\n", |
120 |
| - " - name: Install Codex CLI\n", |
121 |
| - " run: npm i -g @openai/codex\n", |
122 |
| - "\n", |
123 |
| - " - name: Authenticate Codex (non-interactive)\n", |
124 |
| - " env:\n", |
125 |
| - " # if you set CODEX_HOME above, export it here too\n", |
126 |
| - " CODEX_HOME: ${{ env.CODEX_HOME }}\n", |
127 |
| - " OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}\n", |
128 |
| - " run: codex login --api-key \"$OPENAI_API_KEY\"\n", |
129 |
| - "\n", |
130 |
| - " - name: Run Codex to fix CI failure\n", |
131 |
| - " run: |\n", |
132 |
| - " 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", |
| 103 | + " - name: Run Codex\n", |
| 104 | + " uses: openai/codex-action@main\n", |
| 105 | + " id: codex\n", |
| 106 | + " with:\n", |
| 107 | + " openai_api_key: ${{ secrets.OPENAI_API_KEY }}\n", |
| 108 | + " 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", |
| 109 | + " codex_args: '[\"--config\",\"sandbox_mode=\\\"workspace-write\\\"\"]'\n", |
133 | 110 | "\n",
|
134 | 111 | " - name: Verify tests\n",
|
135 | 112 | " run: npm test --silent\n",
|
|
144 | 121 | " title: \"Auto-fix failing CI via Codex\"\n",
|
145 | 122 | " body: |\n",
|
146 | 123 | " Codex automatically generated this PR in response to a CI failure on workflow `${{ env.FAILED_WORKFLOW_NAME }}`.\n",
|
147 |
| - "\n", |
148 | 124 | " Failed run: ${{ env.FAILED_RUN_URL }}\n",
|
149 | 125 | " Head branch: `${{ env.FAILED_HEAD_BRANCH }}`\n",
|
150 |
| - "\n", |
151 | 126 | " This PR contains minimal changes intended solely to make the CI pass.\n",
|
152 | 127 | "```\n"
|
153 | 128 | ]
|
|
157 | 132 | "id": "8148024b",
|
158 | 133 | "metadata": {},
|
159 | 134 | "source": [
|
160 |
| - "## Step 4: Actions Workflow kicked off\n", |
| 135 | + "## Step 2: Actions Workflow kicked off\n", |
161 | 136 | "\n",
|
162 | 137 | "You can navigate to the Actions tab under Repo to view the failing jobs in your Actions workflow. \n",
|
163 | 138 | "\n",
|
|
181 | 156 | "id": "d08a3ecc",
|
182 | 157 | "metadata": {},
|
183 | 158 | "source": [
|
184 |
| - "## Step 5: Codex generated PR for review\n", |
| 159 | + "## Step 3: Verify that Codex Created a PR for Review\n", |
185 | 160 | "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",
|
186 | 161 | "\n",
|
187 | 162 | "<img src=\"../../images/codex-pr.png\" width=\"700\"/>\n",
|
|
0 commit comments