File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11name : Cancel runs of closed PRs
22
33# A merged or closed PR gates nothing, so its queued and running runs only hold runners.
4- # `pull_request_target` runs the base branch's workflow with a token that can cancel runs of
5- # fork PRs too; it never checks out the PR's code.
64on :
7- pull_request_target :
5+ pull_request :
86 types :
97 - closed
108
@@ -13,6 +11,8 @@ permissions:
1311
1412jobs :
1513 cancel :
14+ # A fork PR's token is read-only, so it cannot cancel runs.
15+ if : github.event.pull_request.head.repo.full_name == github.repository
1616 runs-on : ubuntu-latest
1717 timeout-minutes : 5
1818 steps :
@@ -21,13 +21,14 @@ jobs:
2121 env :
2222 GH_TOKEN : ${{ github.token }}
2323 HEAD_REF : ${{ github.event.pull_request.head.ref }}
24- HEAD_REPO : ${{ github.event.pull_request.head.repo.full_name }}
24+ RUN_ID : ${{ github.run_id }}
2525 run : |
2626 gh api --paginate -X GET "repos/$GITHUB_REPOSITORY/actions/runs" \
2727 -f branch="$HEAD_REF" -f event=pull_request -f per_page=100 \
2828 --jq ".workflow_runs[]
2929 | select(.status != \"completed\")
30- | select(.head_repository.full_name == \"$HEAD_REPO\")
30+ | select(.head_repository.full_name == \"$GITHUB_REPOSITORY\")
31+ | select(.id != $RUN_ID)
3132 | select(.path != \".github/workflows/pr-preview-cleanup.yml\")
3233 | .id" |
3334 while read -r id; do
You can’t perform that action at this time.
0 commit comments