|
9 | 9 | # that automation opens (Version Packages, Prepare Python Release) get no |
10 | 10 | # push run. Their workflows dispatch this one on the PR's branch instead |
11 | 11 | # (#5110): `workflow_dispatch` is the one event that token can start, and its |
12 | | - # run reports its checks on the branch's head commit, which the PR shows. |
| 12 | + # run's checks attach to the branch's head commit. The rollup a PR reads |
| 13 | + # leaves dispatched checks out, so the `dispatch-status` jobs below report |
| 14 | + # the run as a commit status instead. |
13 | 15 | workflow_dispatch: |
14 | 16 |
|
15 | 17 | # Superseded runs on the same ref are cancelled (e.g. rapid amend-pushes), |
@@ -180,3 +182,62 @@ jobs: |
180 | 182 | with: |
181 | 183 | name: dist-${{ matrix.package }} |
182 | 184 | path: src/${{ matrix.package }}/dist/ |
| 185 | + |
| 186 | + # A dispatched run's checks attach to the branch's head commit but are left |
| 187 | + # out of its status rollup, which is what a pull request reads (verified on |
| 188 | + # #5110: 29 successful dispatched check runs, a rollup of null). So on a |
| 189 | + # dispatch, which is how a version PR opened by automation gets CI, these two |
| 190 | + # jobs mirror the run onto the commit as a status, which the rollup does |
| 191 | + # include: pending at the start, then the result of every job above. A push |
| 192 | + # run reports through its own checks and skips both. |
| 193 | + dispatch-status-pending: |
| 194 | + name: Report the dispatched run as pending |
| 195 | + if: github.event_name == 'workflow_dispatch' |
| 196 | + timeout-minutes: 5 |
| 197 | + runs-on: ubuntu-latest |
| 198 | + permissions: |
| 199 | + statuses: write |
| 200 | + steps: |
| 201 | + - name: Set the commit status to pending |
| 202 | + env: |
| 203 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 204 | + run: | |
| 205 | + gh api "repos/$GITHUB_REPOSITORY/statuses/$GITHUB_SHA" \ |
| 206 | + -f state=pending -f context="Python (dispatched)" \ |
| 207 | + -f description="Dispatched run in progress" \ |
| 208 | + -f target_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" |
| 209 | +
|
| 210 | + # `!cancelled()`: a run superseded by a newer dispatch posts nothing, and the |
| 211 | + # newer run reports instead. A job skipped by its own `if:` counts as passed. |
| 212 | + dispatch-status: |
| 213 | + name: Report the dispatched run's result |
| 214 | + if: github.event_name == 'workflow_dispatch' && !cancelled() |
| 215 | + needs: |
| 216 | + [ |
| 217 | + dispatch-status-pending, |
| 218 | + detect-packages, |
| 219 | + script-tests, |
| 220 | + test, |
| 221 | + coverage, |
| 222 | + test-windows, |
| 223 | + build, |
| 224 | + ] |
| 225 | + timeout-minutes: 5 |
| 226 | + runs-on: ubuntu-latest |
| 227 | + permissions: |
| 228 | + statuses: write |
| 229 | + steps: |
| 230 | + - name: Set the commit status to the run's result |
| 231 | + env: |
| 232 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 233 | + NEEDS: ${{ toJSON(needs) }} |
| 234 | + run: | |
| 235 | + if jq -e 'all(.[]; .result == "success" or .result == "skipped")' <<<"$NEEDS" >/dev/null; then |
| 236 | + STATE=success DESCRIPTION="Every job passed" |
| 237 | + else |
| 238 | + STATE=failure DESCRIPTION="A job failed; open the run for details" |
| 239 | + fi |
| 240 | + gh api "repos/$GITHUB_REPOSITORY/statuses/$GITHUB_SHA" \ |
| 241 | + -f state="$STATE" -f context="Python (dispatched)" \ |
| 242 | + -f description="$DESCRIPTION" \ |
| 243 | + -f target_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" |
0 commit comments