PR OSP retry #1
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: PR OSP retry | |
| # No concurrency group: workflow_run reports github.ref as the default branch, so any group self-cancels. | |
| on: | |
| workflow_run: | |
| workflows: ["PR OSP (label-selected)"] | |
| types: [completed] | |
| permissions: | |
| actions: write | |
| jobs: | |
| retry: | |
| name: Rerun failed jobs once | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| # 'failure' skips superseded runs (those land as 'cancelled'); attempt 1 bounds this to one retry. | |
| if: > | |
| github.event.workflow_run.conclusion == 'failure' && | |
| github.event.workflow_run.run_attempt == 1 | |
| steps: | |
| - name: Verify trigger is trusted | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| REPO: ${{ github.repository }} | |
| ACTOR: ${{ github.event.workflow_run.actor.login }} | |
| WF_PATH: ${{ github.event.workflow_run.path }} | |
| run: | | |
| # A fork controls both the workflow name and a new file's path, so pin the path. | |
| if [ "$WF_PATH" != ".github/workflows/pr-osp-select.yml" ]; then | |
| echo "::error::untrusted triggering workflow: $WF_PATH" | |
| exit 1 | |
| fi | |
| # Distinguish "not a collaborator" (404) from an API failure; never conflate them. | |
| if ! body=$(gh api "/repos/$REPO/collaborators/$ACTOR/permission" 2>&1); then | |
| case "$body" in | |
| *"Not Found"*) echo "::error::actor $ACTOR is not a collaborator"; exit 1 ;; | |
| *) echo "::error::could not verify $ACTOR: $body"; exit 1 ;; | |
| esac | |
| fi | |
| perm=$(printf '%s' "$body" | jq -r '.permission') | |
| # triage can add labels, so it can legitimately start a PR OSP run. | |
| case "$perm" in | |
| admin|write|maintain|triage) echo "actor $ACTOR ok ($perm)" ;; | |
| *) echo "::error::actor $ACTOR cannot label ($perm)"; exit 1 ;; | |
| esac | |
| - name: Rerun failed jobs | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| RUN_ID: ${{ github.event.workflow_run.id }} | |
| run: | | |
| gh api -X POST \ | |
| "/repos/${{ github.repository }}/actions/runs/$RUN_ID/rerun-failed-jobs" |