@@ -35,21 +35,26 @@ jobs:
3535
3636 cancel_if_not_opt_in :
3737 runs-on : self-hosted-docker-tiny
38- if : github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
38+ # Note that we don't auto-cancel on merged commits (e.g. in a post-merge workflow), and on
39+ # pull_request_target events (which indicate that we are running from a fork).
40+ if : github.event_name == 'pull_request'
3941 name : Cancel if not opted in
4042 permissions :
4143 actions : write
4244 contents : read
4345 steps :
4446 - name : Checkout code
4547 uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
48+ - name : Check if static only
49+ uses : ./.github/actions/tests/skip_on_static
50+ id : static_only
4651 - name : Cancel if not opted in
4752 shell : bash
4853 run : |
4954 git fetch origin ${{ github.event.pull_request.head.sha }}
5055 last_commit_msg=$(git log -1 --pretty=%B ${{ github.event.pull_request.head.sha }})
5156 echo "Last commit message: $last_commit_msg"
52- if [[ $last_commit_msg != *"[ci]"* ]] && [[ "$last_commit_msg" != *"[static]"* ]] ; then
57+ if [[ $last_commit_msg != *"[ci]"* ]] && [[ "${{ steps.static_only.outputs.skip }}" == "false" ]] ; then
5358 echo "Cancelling the entire workflow because the current commit does not opt in for CI."
5459 curl -fsSL -X POST -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/vnd.github+json" "${{ github.api_url }}/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/cancel"
5560 else
@@ -301,6 +306,9 @@ jobs:
301306 steps :
302307 - name : Checkout code
303308 uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
309+ - name : Check if static only
310+ uses : ./.github/actions/tests/skip_on_static
311+ id : static_only
304312 - name : Handle [force] and [static] labels
305313 shell : bash
306314 run : |
@@ -310,7 +318,7 @@ jobs:
310318 if [[ $last_commit_msg == *"[force]"* ]]; then
311319 echo "Skipping the check for job success because the current commit opts in for a forced run."
312320 echo "FORCE=true" >> "$GITHUB_ENV"
313- elif [[ "$last_commit_msg " == *"[static]"* ]]; then
321+ elif [[ "${{ steps.static_only.outputs.skip }} " == "true" ]]; then
314322 echo "Only static tests are required"
315323 # shellcheck disable=SC2129
316324 echo "FORCE=false" >> "$GITHUB_ENV"
0 commit comments