|
| 1 | +name: Leaderboard Validation Comment |
| 2 | + |
| 3 | +# Post validation results as a PR comment after the leaderboard workflow completes. |
| 4 | +# Uses workflow_run to run in the upstream repo context with write permissions, |
| 5 | +# enabling comments on fork PRs (same pattern as coverage-comment.yml). |
| 6 | + |
| 7 | +on: |
| 8 | + workflow_run: |
| 9 | + workflows: ["Leaderboard Management"] |
| 10 | + types: [completed] |
| 11 | + |
| 12 | +jobs: |
| 13 | + post-comment: |
| 14 | + name: Post Validation Comment |
| 15 | + runs-on: ubuntu-latest |
| 16 | + if: github.event.workflow_run.event == 'pull_request' |
| 17 | + permissions: |
| 18 | + pull-requests: write |
| 19 | + actions: read |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Get PR number from workflow run |
| 23 | + id: pr_info |
| 24 | + env: |
| 25 | + GH_TOKEN: ${{ github.token }} |
| 26 | + run: | |
| 27 | + HEAD_REPO="${{ github.event.workflow_run.head_repository.full_name }}" |
| 28 | + HEAD_BRANCH="${{ github.event.workflow_run.head_branch }}" |
| 29 | + TARGET_REPO="${{ github.repository }}" |
| 30 | +
|
| 31 | + if [ "$HEAD_REPO" = "$TARGET_REPO" ]; then |
| 32 | + BRANCH_QUERY="${HEAD_BRANCH}" |
| 33 | + else |
| 34 | + BRANCH_QUERY="${HEAD_REPO%%/*}:${HEAD_BRANCH}" |
| 35 | + fi |
| 36 | +
|
| 37 | + PR_NUMBER=$(gh pr view \ |
| 38 | + --repo "$TARGET_REPO" \ |
| 39 | + "$BRANCH_QUERY" \ |
| 40 | + --json number --jq .number 2>/dev/null || echo "") |
| 41 | +
|
| 42 | + if [ -z "$PR_NUMBER" ]; then |
| 43 | + echo "::warning::Could not find PR for ${BRANCH_QUERY} in ${TARGET_REPO}" |
| 44 | + exit 0 |
| 45 | + fi |
| 46 | +
|
| 47 | + echo "pr_number=${PR_NUMBER}" >> "$GITHUB_OUTPUT" |
| 48 | +
|
| 49 | + - name: Download validation data |
| 50 | + if: steps.pr_info.outputs.pr_number |
| 51 | + uses: actions/download-artifact@v4 |
| 52 | + with: |
| 53 | + name: leaderboard-validation |
| 54 | + path: validation-data |
| 55 | + run-id: ${{ github.event.workflow_run.id }} |
| 56 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 57 | + |
| 58 | + - name: Post validation comment |
| 59 | + if: steps.pr_info.outputs.pr_number |
| 60 | + uses: actions/github-script@v9 |
| 61 | + env: |
| 62 | + TRUSTED_PR_NUMBER: ${{ steps.pr_info.outputs.pr_number }} |
| 63 | + with: |
| 64 | + script: | |
| 65 | + const fs = require('fs'); |
| 66 | + const data = JSON.parse(fs.readFileSync('validation-data/validation.json', 'utf8')); |
| 67 | +
|
| 68 | + const artifactPR = data.pr_number; |
| 69 | + const trustedPR = parseInt(process.env.TRUSTED_PR_NUMBER); |
| 70 | + if (parseInt(artifactPR) !== trustedPR) { |
| 71 | + core.setFailed(`PR number mismatch: artifact=${artifactPR}, expected=${trustedPR}`); |
| 72 | + return; |
| 73 | + } |
| 74 | +
|
| 75 | + const claimed = data.claimed_score || 'N/A'; |
| 76 | + const actual = data.actual_score || 'N/A'; |
| 77 | + const diff = actual !== 'N/A' && actual !== '' |
| 78 | + ? Math.abs(parseFloat(actual) - parseFloat(claimed)).toFixed(1) |
| 79 | + : 'N/A'; |
| 80 | +
|
| 81 | + const status = parseFloat(diff) <= 2.0 ? '✅ **PASSED**' : '❌ **FAILED**'; |
| 82 | + const body = `## Leaderboard Validation\n\n${status}\n\n` + |
| 83 | + `**Claimed**: ${claimed}/100\n` + |
| 84 | + `**Verified**: ${actual}/100\n` + |
| 85 | + `**Diff**: ${diff} points (±2 tolerance)`; |
| 86 | +
|
| 87 | + const comments = await github.rest.issues.listComments({ |
| 88 | + owner: context.repo.owner, |
| 89 | + repo: context.repo.repo, |
| 90 | + issue_number: trustedPR, |
| 91 | + }); |
| 92 | +
|
| 93 | + const existing = comments.data.find(c => |
| 94 | + c.user.login === 'github-actions[bot]' && |
| 95 | + c.body.includes('Leaderboard Validation') |
| 96 | + ); |
| 97 | +
|
| 98 | + if (existing) { |
| 99 | + await github.rest.issues.updateComment({ |
| 100 | + owner: context.repo.owner, |
| 101 | + repo: context.repo.repo, |
| 102 | + comment_id: existing.id, |
| 103 | + body: body, |
| 104 | + }); |
| 105 | + } else { |
| 106 | + await github.rest.issues.createComment({ |
| 107 | + owner: context.repo.owner, |
| 108 | + repo: context.repo.repo, |
| 109 | + issue_number: trustedPR, |
| 110 | + body: body, |
| 111 | + }); |
| 112 | + } |
0 commit comments