|
| 1 | +# Turn the outcome of the expected-failures strict array-API jobs into |
| 2 | +# check runs on the PR. This runs as a separate workflow_run workflow because |
| 3 | +# pull_request runs for fork PRs get a read-only GITHUB_TOKEN and cannot |
| 4 | +# create check runs themselves. Each check uses a stable name (the matrix |
| 5 | +# entry name); the outcome is carried by the conclusion and output instead. |
| 6 | +# These checks are informational only (an expected test failure is reported |
| 7 | +# as neutral, so the PR rollup stays green) and are not intended to be |
| 8 | +# required checks while the failures are expected. |
| 9 | +# |
| 10 | +# Note: workflow_run workflows execute from the default branch, so changes to |
| 11 | +# this file only take effect once merged. |
| 12 | +name: Strict array API status |
| 13 | + |
| 14 | +on: |
| 15 | + workflow_run: |
| 16 | + workflows: ["CI"] |
| 17 | + types: [completed] |
| 18 | + |
| 19 | +permissions: |
| 20 | + checks: write |
| 21 | + actions: read |
| 22 | + |
| 23 | +jobs: |
| 24 | + report: |
| 25 | + # Only report on pull_request runs. CI also triggers on push (all |
| 26 | + # branches) and schedule, so without this gate a same-repo PR branch gets |
| 27 | + # two completed CI runs per push and this workflow would post duplicate |
| 28 | + # (possibly contradictory) checks on the same head SHA. |
| 29 | + if: github.event.workflow_run.event == 'pull_request' |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - name: Download strict job outcomes |
| 33 | + id: download |
| 34 | + # The artifacts are missing for CI runs from before the record/upload |
| 35 | + # steps became `if: always()` (or when the whole CI run was skipped); |
| 36 | + # tolerate that and skip the check runs below. Runs after that change |
| 37 | + # should always upload an outcome artifact per matrix entry. |
| 38 | + continue-on-error: true |
| 39 | + uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # 7.0.0 |
| 40 | + with: |
| 41 | + pattern: strict-job-outcome-* |
| 42 | + merge-multiple: false |
| 43 | + path: strict-outcomes |
| 44 | + run-id: ${{ github.event.workflow_run.id }} |
| 45 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 46 | + - name: Create check runs |
| 47 | + if: steps.download.outcome == 'success' |
| 48 | + uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 |
| 49 | + with: |
| 50 | + script: | |
| 51 | + const fs = require('fs'); |
| 52 | + const path = require('path'); |
| 53 | + const run = context.payload.workflow_run; |
| 54 | + const root = 'strict-outcomes'; |
| 55 | + // One directory per artifact, i.e. per expected-failures matrix |
| 56 | + // entry. Each contains a strict-outcome.json written by ci_tests.yml |
| 57 | + // with the schema {"name": "<matrix name>", |
| 58 | + // "state": "success" | "failure" | "error"}. |
| 59 | + let dirs = []; |
| 60 | + try { |
| 61 | + dirs = fs.readdirSync(root).filter((d) => d.startsWith('strict-job-outcome-')); |
| 62 | + } catch (err) { |
| 63 | + core.info(`No outcome artifacts downloaded (${err.message}); nothing to report.`); |
| 64 | + return; |
| 65 | + } |
| 66 | + if (dirs.length === 0) { |
| 67 | + core.info('No strict-job-outcome-* artifacts found; nothing to report.'); |
| 68 | + return; |
| 69 | + } |
| 70 | + for (const dir of dirs) { |
| 71 | + // Fall back to the artifact name and an error state if the JSON |
| 72 | + // is missing or malformed, so a broken upload still surfaces. |
| 73 | + let name = dir.replace('strict-job-outcome-', ''); |
| 74 | + let state = 'error'; |
| 75 | + try { |
| 76 | + const data = JSON.parse(fs.readFileSync(path.join(root, dir, 'strict-outcome.json'), 'utf8')); |
| 77 | + if (typeof data.name === 'string' && data.name) { |
| 78 | + name = data.name; |
| 79 | + } |
| 80 | + if (['success', 'failure', 'error'].includes(data.state)) { |
| 81 | + state = data.state; |
| 82 | + } else { |
| 83 | + core.warning(`Unrecognized state ${JSON.stringify(data.state)} in ${dir}; reporting an error state.`); |
| 84 | + } |
| 85 | + } catch (err) { |
| 86 | + core.warning(`Could not read outcome JSON in ${dir} (${err.message}); reporting an error state.`); |
| 87 | + } |
| 88 | + let conclusion; |
| 89 | + let title; |
| 90 | + let summary; |
| 91 | + if (state === 'success') { |
| 92 | + conclusion = 'success'; |
| 93 | + title = 'Strict array-API tests passed'; |
| 94 | + summary = `The ${name} job in [this CI run](${run.html_url}) passed. ` + |
| 95 | + 'The expected-failures carve-out for it can be retired.'; |
| 96 | + } else if (state === 'failure') { |
| 97 | + conclusion = 'neutral'; |
| 98 | + title = 'Strict array-API tests failed (expected)'; |
| 99 | + summary = `The ${name} job in [this CI run](${run.html_url}) failed. ` + |
| 100 | + 'This is expected until the remaining array-API bugs are fixed; ' + |
| 101 | + 'see the run log for details.'; |
| 102 | + } else { |
| 103 | + conclusion = 'failure'; |
| 104 | + title = 'Strict array-API job broke (infra error)'; |
| 105 | + summary = `The ${name} job in [this CI run](${run.html_url}) did not ` + |
| 106 | + 'complete its tests step. This is an infrastructure error in the ' + |
| 107 | + 'job itself, not a test failure; see the run log for details.'; |
| 108 | + } |
| 109 | + // Stable check name (just the matrix entry name); the outcome |
| 110 | + // lives in the conclusion and output so the checks UI does not |
| 111 | + // accumulate differently-named checks per outcome. |
| 112 | + await github.rest.checks.create({ |
| 113 | + owner: context.repo.owner, |
| 114 | + repo: context.repo.repo, |
| 115 | + name, |
| 116 | + head_sha: run.head_sha, |
| 117 | + status: 'completed', |
| 118 | + conclusion, |
| 119 | + output: { title, summary }, |
| 120 | + }); |
| 121 | + } |
0 commit comments