E2E Failure Comment #411753
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: E2E Failure Comment | |
| on: | |
| status: | |
| jobs: | |
| comment-on-failure: | |
| name: Comment on PR when an e2e test fails | |
| runs-on: ubuntu-latest | |
| # TeamCity (.teamcity/_self/CalypsoE2ETestsBuildTemplate.kt) posts a commit | |
| # status for each e2e build. Only react to failed terminal states. | |
| if: >- | |
| contains(github.event.context, 'E2E') && | |
| (github.event.state == 'failure' || github.event.state == 'error') | |
| permissions: | |
| pull-requests: write | |
| issues: write | |
| timeout-minutes: 5 | |
| steps: | |
| - name: Post comment on PR | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const watermark = '<!--e2e-failure-watermark:v1-->'; | |
| const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| commit_sha: context.payload.sha, | |
| }); | |
| const openPrs = prs.filter((pr) => pr.state === 'open'); | |
| if (openPrs.length === 0) return; | |
| const buildBody = (prNumber) => [ | |
| watermark, | |
| `Looks like one of the E2E tests has failed.`, | |
| ``, | |
| `You can fix them following these steps:`, | |
| ``, | |
| `1. Check out this branch locally:`, | |
| ` \`\`\`bash`, | |
| ` gh pr checkout ${prNumber}`, | |
| ` \`\`\``, | |
| `2. Start Claude Code in the repo:`, | |
| ` \`\`\`bash`, | |
| ` claude`, | |
| ` \`\`\``, | |
| `3. Run the \`/fix-e2e-tests\` skill, passing this PR number:`, | |
| ` \`\`\``, | |
| ` /fix-e2e-tests ${prNumber}`, | |
| ` \`\`\``, | |
| ].join('\n'); | |
| for (const pr of openPrs) { | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: pr.number, | |
| }); | |
| // Skip if we've already commented on this PR. | |
| if (comments.some((c) => c.body && c.body.includes(watermark))) continue; | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: pr.number, | |
| body: buildBody(pr.number), | |
| }); | |
| } |