|
| 1 | +--- |
| 2 | +mode: agent |
| 3 | +--- |
| 4 | + |
| 5 | +# Fix PR CI failures |
| 6 | + |
| 7 | +Analyze the CI failures in the PR for the current branch and fix them, following the structured plan below. |
| 8 | + |
| 9 | +Each time this prompt is triggered, assume you are starting fresh from the beginning of the process. |
| 10 | + |
| 11 | +Do not stop a given execution until you have worked through all phases below. |
| 12 | + |
| 13 | +## Phase 0: Validate |
| 14 | + |
| 15 | +1. Verify we're not on a protected branch: `git branch --show-current` should not be `main` |
| 16 | +2. Check that the branch is up-to-date with remote: `git fetch && git status` - exit and warn if behind |
| 17 | +3. Get the current branch name using `git branch --show-current` |
| 18 | +4. Find the PR for this branch using `gh pr list --head <branch-name> --json number,title` and extract the PR number |
| 19 | +5. Use `gh pr view <pr-number> --json statusCheckRollup` to get the list of all failed CI jobs |
| 20 | +6. Check if there are actually CI failures to fix - if all jobs passed, exit early |
| 21 | + |
| 22 | +## Phase 1: Gather Information |
| 23 | + |
| 24 | +**Phase 1 is for gathering information ONLY. Do NOT analyze failures or look at any code during this phase.** |
| 25 | +**Your only goal in Phase 1 is to collect: job names, job IDs, log files, and failed task names.** |
| 26 | + |
| 27 | +1. Get repository info: `gh repo view --json owner,name` |
| 28 | +2. For unique job type that failed |
| 29 | + - **Important**: Ignore duplicate jobs that only differ by parameters inside of parenthesis. For example: |
| 30 | + - In `abc / def (x, y, z)`, the job is `abc / def` while x, y, and z are parameters |
| 31 | + - **Strategy**: Download logs for 1-2 representative jobs first to identify patterns (e.g., one "build" job, one "test0" job) |
| 32 | + - Compilation failures typically repeat across all jobs, so you don't need every log file |
| 33 | + - Retrieve logs for selected representative jobs: |
| 34 | + - Get the job ID from the failed run by examining the PR status checks JSON |
| 35 | + - Download logs using: `cd /tmp && gh auth token | xargs -I {} curl -sSfL -H "Authorization: token {}" -o <job-name>.log "https://api.github.com/repos/<owner>/<repo>/actions/jobs/<job-id>/logs"` |
| 36 | + - Example: `cd /tmp && gh auth token | xargs -I {} curl -sSfL -H "Authorization: token {}" -o test0-java8-indy-false.log "https://api.github.com/repos/open-telemetry/opentelemetry-java-instrumentation/actions/jobs/53713949850/logs"` |
| 37 | + - The GitHub API responds with an HTTP 302 redirect to blob storage; `-L` (already included) ensures the download follows the redirect and saves the final log contents. |
| 38 | + - Find all gradle tasks that failed: |
| 39 | + - Search for failed tasks: `grep "Task.*FAILED" /tmp/<job-name>.log` |
| 40 | + - Look for test failures: `grep "FAILED" /tmp/<job-name>.log | grep -E "(Test|test)"` |
| 41 | + - Example output: `> Task :instrumentation:cassandra:cassandra-4.0:javaagent:test FAILED` |
| 42 | + - Extract error context: |
| 43 | + - For compilation errors: `grep -B 5 -A 20 "error:" /tmp/<job-name>.log` |
| 44 | + - For task failures: `grep -B 2 -A 15 "Task.*FAILED" /tmp/<job-name>.log` |
| 45 | + |
| 46 | +## Phase 2: Create CI-PLAN.md |
| 47 | + |
| 48 | +**ONLY:** Create the CI-PLAN.md file in the repository root with the following structure: |
| 49 | + |
| 50 | +```markdown |
| 51 | +# CI Failure Analysis Plan |
| 52 | + |
| 53 | +## Failed Jobs Summary |
| 54 | +- Job 1: <job-name> (job ID: <id>) |
| 55 | +- Job 2: <job-name> (job ID: <id>) |
| 56 | +... |
| 57 | + |
| 58 | +## Unique Failed Gradle Tasks |
| 59 | + |
| 60 | +- [ ] Task: <gradle-task-path> |
| 61 | + - Seen in: <job-name-1>, <job-name-2>, ... |
| 62 | + - Log files: /tmp/<file1>.log, /tmp/<file2>.log |
| 63 | + |
| 64 | +- [ ] Task: <gradle-task-path> |
| 65 | + - Seen in: <job-name-1>, <job-name-2>, ... |
| 66 | + - Log files: /tmp/<file1>.log, /tmp/<file2>.log |
| 67 | + |
| 68 | +## Notes |
| 69 | +[Any patterns or observations about the failures] |
| 70 | +``` |
| 71 | + |
| 72 | +## Phase 3: Fix Issues |
| 73 | + |
| 74 | +**Important**: Do not commit CI-PLAN.md - it's only for tracking work during the session |
| 75 | + |
| 76 | +- Work through the CI-PLAN.md, checking items off as you complete them |
| 77 | +- For each failed task: |
| 78 | + - Analyze the failure |
| 79 | + - Implement the fix |
| 80 | + - **Test locally before committing**: |
| 81 | + - For compilation errors: `./gradlew <failed-task-path>` |
| 82 | + - For test failures: `./gradlew <failed-test-task>` |
| 83 | + - Verify the fix resolves the issue |
| 84 | + - Update the checkbox in CI-PLAN.md |
| 85 | + - Commit each logical fix as a separate commit |
| 86 | + - Reminder: do not commit CI-PLAN.md |
| 87 | +- Do not git push in this phase |
| 88 | + |
| 89 | +## Phase 4: Validate and Push |
| 90 | + |
| 91 | +- Once all fixes are committed, push the changes: `git push` (or `git push -f` if needed) |
| 92 | +- Provide a summary of: |
| 93 | + - What failures were found |
| 94 | + - What fixes were applied |
| 95 | + - Which commits were created |
0 commit comments