|
| 1 | +name: Post Test Status |
| 2 | + |
| 3 | +# This workflow runs in the base repo context (with write permissions) |
| 4 | +# even for fork PRs, allowing us to post commit statuses. |
| 5 | +# |
| 6 | +# Add any status posting for skipped jobs here to avoid "Resource not |
| 7 | +# accessible by integration" errors when PRs come from forks. |
| 8 | + |
| 9 | +on: |
| 10 | + workflow_run: |
| 11 | + workflows: ["Dash Testing"] |
| 12 | + types: |
| 13 | + - completed |
| 14 | + |
| 15 | +jobs: |
| 16 | + post-skipped-statuses: |
| 17 | + name: Post Statuses for Skipped Jobs |
| 18 | + runs-on: ubuntu-latest |
| 19 | + if: github.event.workflow_run.event == 'pull_request' |
| 20 | + permissions: |
| 21 | + statuses: write |
| 22 | + actions: read |
| 23 | + steps: |
| 24 | + - name: Post statuses for skipped jobs |
| 25 | + uses: actions/github-script@v7 |
| 26 | + with: |
| 27 | + script: | |
| 28 | + const { owner, repo } = context.repo; |
| 29 | + const runId = context.payload.workflow_run.id; |
| 30 | + const headSha = context.payload.workflow_run.head_sha; |
| 31 | +
|
| 32 | + // Define jobs that need a success status posted when skipped |
| 33 | + // Format: { jobName: 'GitHub Job Name', statusContext: 'status/context-name', description: 'Description' } |
| 34 | + const skippedStatusJobs = [ |
| 35 | + { |
| 36 | + jobName: 'Dash Table Visual Tests', |
| 37 | + statusContext: 'percy/dash-table-test', |
| 38 | + description: 'Skipped — no dash-table changes' |
| 39 | + } |
| 40 | + // Add more jobs here as needed: |
| 41 | + // { |
| 42 | + // jobName: 'Job Name', |
| 43 | + // statusContext: 'context/name', |
| 44 | + // description: 'Skipped — reason' |
| 45 | + // } |
| 46 | + ]; |
| 47 | +
|
| 48 | + // Get all jobs for the workflow run |
| 49 | + const { data: { jobs } } = await github.rest.actions.listJobsForWorkflowRun({ |
| 50 | + owner, |
| 51 | + repo, |
| 52 | + run_id: runId, |
| 53 | + }); |
| 54 | +
|
| 55 | + // Post status for each skipped job |
| 56 | + for (const { jobName, statusContext, description } of skippedStatusJobs) { |
| 57 | + const job = jobs.find(j => j.name === jobName); |
| 58 | +
|
| 59 | + if (job && job.conclusion === 'skipped') { |
| 60 | + await github.rest.repos.createCommitStatus({ |
| 61 | + owner, |
| 62 | + repo, |
| 63 | + sha: headSha, |
| 64 | + state: 'success', |
| 65 | + context: statusContext, |
| 66 | + description: description, |
| 67 | + }); |
| 68 | + console.log(`Posted skipped status for ${statusContext}`); |
| 69 | + } else { |
| 70 | + console.log(`Job "${jobName}" status: ${job?.conclusion ?? 'not found'} - no status posted`); |
| 71 | + } |
| 72 | + } |
0 commit comments