Post CI Dashboard Link #2222
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: Post CI Dashboard Link | |
| on: | |
| workflow_run: | |
| workflows: ["PR CI"] | |
| types: [completed] | |
| permissions: | |
| pull-requests: write | |
| jobs: | |
| post-link: | |
| if: github.event.workflow_run.event == 'pull_request' | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - uses: actions/github-script@v9.0.0 | |
| with: | |
| script: | | |
| const wr = context.payload.workflow_run; | |
| console.log('=== Triggering PR CI workflow_run info ==='); | |
| console.log(` Run ID: ${wr.id}`); | |
| console.log(` Run number: ${wr.run_number}`); | |
| console.log(` Run URL: ${wr.html_url}`); | |
| console.log(` Triggering event: ${wr.event}`); | |
| console.log(` Conclusion: ${wr.conclusion}`); | |
| console.log(` Head branch: ${wr.head_branch}`); | |
| console.log(` Head SHA: ${wr.head_sha}`); | |
| console.log(` Actor: ${wr.actor?.login}`); | |
| console.log(` Triggering actor: ${wr.triggering_actor?.login}`); | |
| console.log(` Created at: ${wr.created_at}`); | |
| console.log(` Run started at: ${wr.run_started_at}`); | |
| console.log(` Updated at: ${wr.updated_at}`); | |
| console.log('=========================================='); | |
| const headSha = context.payload.workflow_run.head_sha; | |
| const runId = context.payload.workflow_run.id; | |
| const { data: prs } = await github.rest.pulls.list({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| }); | |
| const pr = prs.find(pr => pr.head.sha === headSha); | |
| if (!pr) { | |
| console.log(`No open PR found for SHA ${headSha}, skipping`); | |
| return; | |
| } | |
| console.log(`Matched PR #${pr.number}: ${pr.html_url}`); | |
| // Check if the code quality job failed (causes all test jobs to be skipped) | |
| const { data: jobsData } = await github.rest.actions.listJobsForWorkflowRun({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| run_id: runId, | |
| per_page: 100, | |
| }); | |
| const qualityJob = jobsData.jobs.find(j => j.name.includes('Check code quality')); | |
| const qualityFailed = qualityJob && qualityJob.conclusion === 'failure'; | |
| // Delete any existing dashboard comment before posting a fresh one | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: pr.number, | |
| }); | |
| for (const comment of comments) { | |
| if (comment.body.includes('**CI Observability Dashboard:** [View test results in Grafana]') || | |
| comment.body.includes('**CI Dashboard:** [View test results in Grafana]')) { | |
| await github.rest.issues.deleteComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| comment_id: comment.id, | |
| }); | |
| } | |
| } | |
| const url = `https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=${pr.number}`; | |
| let body = `**CI Dashboard:** [View test results in Grafana](${url})`; | |
| if (qualityFailed) { | |
| body += `\n\n> ⚠️ **Code quality check failed** — all test jobs were skipped. Fix the code quality issues and push again to run tests.`; | |
| } | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: pr.number, | |
| body, | |
| }); |