|
| 1 | +name: Pin Bump CI Handler |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["trunk"] |
| 6 | + types: [completed] |
| 7 | + |
| 8 | +jobs: |
| 9 | + handle-ci-result: |
| 10 | + if: github.repository_owner == 'pytorch' |
| 11 | + runs-on: ubuntu-latest |
| 12 | + environment: update-commit-hash |
| 13 | + permissions: |
| 14 | + pull-requests: write |
| 15 | + issues: write |
| 16 | + steps: |
| 17 | + - uses: actions/github-script@v7 |
| 18 | + with: |
| 19 | + github-token: ${{ secrets.UPDATEBOT_TOKEN }} |
| 20 | + script: | |
| 21 | + const { owner, repo } = context.repo; |
| 22 | + const workflowRun = context.payload.workflow_run; |
| 23 | + const conclusion = workflowRun.conclusion; |
| 24 | + const runUrl = workflowRun.html_url; |
| 25 | +
|
| 26 | + const prs = workflowRun.pull_requests; |
| 27 | + if (!prs || prs.length === 0) { |
| 28 | + console.log('No PRs associated with this workflow run. Skipping.'); |
| 29 | + return; |
| 30 | + } |
| 31 | +
|
| 32 | + const prNumber = prs[0].number; |
| 33 | + const pr = await github.rest.pulls.get({ owner, repo, pull_number: prNumber }); |
| 34 | +
|
| 35 | + const isPinBump = pr.data.labels.some(l => l.name === 'ci/pytorch-pin-bump'); |
| 36 | + if (!isPinBump) { |
| 37 | + console.log(`PR #${prNumber} is not a pin bump PR. Skipping.`); |
| 38 | + return; |
| 39 | + } |
| 40 | +
|
| 41 | + const allowedAuthors = new Set(['pytorchbot', 'pytorchupdatebot', 'facebook-github-bot']); |
| 42 | + if (!allowedAuthors.has(pr.data.user.login)) { |
| 43 | + console.log(`PR #${prNumber} was created by ${pr.data.user.login}, not an allowed automation account. Skipping.`); |
| 44 | + return; |
| 45 | + } |
| 46 | +
|
| 47 | + console.log(`Pin bump PR #${prNumber}, trunk concluded: ${conclusion}`); |
| 48 | +
|
| 49 | + const comments = await github.rest.issues.listComments({ |
| 50 | + owner, repo, issue_number: prNumber, per_page: 100 |
| 51 | + }); |
| 52 | + const fixAttempts = comments.data.filter( |
| 53 | + c => c.body && c.body.startsWith('@claude [ci-fix-attempt') |
| 54 | + ).length; |
| 55 | +
|
| 56 | + if (conclusion === 'success') { |
| 57 | + const note = fixAttempts > 0 |
| 58 | + ? `Claude fixed CI failures in ${fixAttempts} attempt(s).` |
| 59 | + : 'CI passed on the first try.'; |
| 60 | +
|
| 61 | + await github.rest.issues.createComment({ |
| 62 | + owner, repo, issue_number: prNumber, |
| 63 | + body: `## CI Passed\n\nAll trunk CI checks have passed on this pin bump PR. ${note}\n\n**This PR is ready for human review and merge.**\n\ncc @jakeszwe` |
| 64 | + }); |
| 65 | + return; |
| 66 | + } |
| 67 | +
|
| 68 | + if (conclusion !== 'failure') { |
| 69 | + console.log(`Trunk concluded with "${conclusion}" (not failure). Skipping.`); |
| 70 | + return; |
| 71 | + } |
| 72 | +
|
| 73 | + if (fixAttempts >= 3) { |
| 74 | + await github.rest.issues.createComment({ |
| 75 | + owner, repo, issue_number: prNumber, |
| 76 | + body: [ |
| 77 | + '## Automated Fix Attempts Exhausted', |
| 78 | + '', |
| 79 | + `CI is still failing after ${fixAttempts} automated fix attempt(s).`, |
| 80 | + `Failed trunk run: ${runUrl}`, |
| 81 | + '', |
| 82 | + 'This pin bump likely requires human intervention. Common causes:', |
| 83 | + '- BC-breaking API changes in PyTorch that need design discussion', |
| 84 | + '- New dependencies or build system changes', |
| 85 | + '- Test infrastructure issues unrelated to the pin bump', |
| 86 | + '', |
| 87 | + 'cc @jakeszwe' |
| 88 | + ].join('\n') |
| 89 | + }); |
| 90 | + return; |
| 91 | + } |
| 92 | +
|
| 93 | + const attemptNum = fixAttempts + 1; |
| 94 | + await github.rest.issues.createComment({ |
| 95 | + owner, repo, issue_number: prNumber, |
| 96 | + body: [ |
| 97 | + `@claude [ci-fix-attempt ${attemptNum}/3]`, |
| 98 | + '', |
| 99 | + `The \`trunk\` CI workflow has failed on this automated PyTorch pin bump PR.`, |
| 100 | + `Failed run: ${runUrl}`, |
| 101 | + '', |
| 102 | + 'Please:', |
| 103 | + '1. Read the Dr. CI comment on this PR for a summary of which jobs failed and whether they are flaky. Ignore failures marked as FLAKY.', |
| 104 | + '2. Use your CI tools to download the failure logs for the non-flaky failing jobs', |
| 105 | + '3. Identify the root cause of the failure', |
| 106 | + '4. If this is a build or test failure caused by PyTorch API changes, fix the ExecuTorch code to be compatible with the new PyTorch version', |
| 107 | + '5. If this is a c10 header sync issue, the headers have already been synced by the pin bump script — the issue is likely in ExecuTorch code that uses those headers', |
| 108 | + '6. Run `lintrunner -a` on any files you change', |
| 109 | + '7. Push your fix as a new commit to this PR branch', |
| 110 | + '', |
| 111 | + 'Important constraints:', |
| 112 | + '- Do NOT modify torch_pin.py or .ci/docker/ci_commit_pins/pytorch.txt — the pin itself is correct', |
| 113 | + '- Do NOT modify files under runtime/core/portable_type/c10/ unless the sync introduced a new API that ExecuTorch code needs to adapt to', |
| 114 | + '- Focus on fixing ExecuTorch code to be compatible with the new PyTorch APIs', |
| 115 | + '- If this is a major BC-breaking change that requires architectural discussion, say so clearly and stop — do not attempt a fix' |
| 116 | + ].join('\n') |
| 117 | + }); |
0 commit comments