Isolate merge_group concurrency to prevent race conditions
Implement a prefix-based concurrency group to ensure GitHub Merge Queue events are not prematurely cancelled by simultaneous push events. - Use 'mq-' prefix in concurrency keys for merge_group events to create isolated groups distinct from standard push events. - Maintain PR number in keys to allow synchronize events to cancel stale runs, preserving CI efficiency. - Simplify job filters to skip redundant push runs on internal merge queue branches.
This commit is contained in:
parent
8d1ead4eef
commit
4f0bb03680
2 changed files with 16 additions and 10 deletions
10
.github/workflows/docker.yml
vendored
10
.github/workflows/docker.yml
vendored
|
|
@ -18,14 +18,18 @@ on:
|
|||
default: true
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.merge_group.head_ref || github.ref }}
|
||||
group: >-
|
||||
${{ github.workflow }}-
|
||||
${{ github.event.pull_request.number ||
|
||||
(github.event_name == 'merge_group' && format('mq-{0}', github.event.merge_group.head_ref)) ||
|
||||
github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build:
|
||||
uses: docker/github-builder/.github/workflows/build.yml@v1
|
||||
# Exclude 'push' events from the Merge Queue to avoid a race condition where
|
||||
# the 'push' event might cancel the 'merge_group' event via the concurrency group.
|
||||
# Exclude 'push' events on Merge Queue branches, as they are already
|
||||
# handled by the 'merge_group' event.
|
||||
if: (!(github.event_name == 'push' && startsWith(github.ref, 'refs/heads/gh-readonly-queue/')))
|
||||
permissions:
|
||||
contents: read
|
||||
|
|
|
|||
16
.github/workflows/oxipng.yml
vendored
16
.github/workflows/oxipng.yml
vendored
|
|
@ -9,7 +9,11 @@ on:
|
|||
workflow_dispatch:
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.event.merge_group.head_ref || github.ref }}
|
||||
group: >-
|
||||
${{ github.workflow }}-
|
||||
${{ github.event.pull_request.number ||
|
||||
(github.event_name == 'merge_group' && format('mq-{0}', github.event.merge_group.head_ref)) ||
|
||||
github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
|
|
@ -20,9 +24,8 @@ jobs:
|
|||
timeout-minutes: 60
|
||||
|
||||
# Prevent tags and in-repo PRs from triggering this workflow more than once for a commit.
|
||||
# We also exclude 'push' events from the Merge Queue (gh-readonly-queue/) because they
|
||||
# trigger alongside the 'merge_group' event. Without this, a race condition in the
|
||||
# concurrency group could cause the 'push' event to cancel the 'merge_group' event.
|
||||
# We also exclude 'push' events on Merge Queue branches, as they are already
|
||||
# handled by the 'merge_group' event.
|
||||
if: >-
|
||||
github.ref_type != 'tag' &&
|
||||
(github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork) &&
|
||||
|
|
@ -161,9 +164,8 @@ jobs:
|
|||
timeout-minutes: 30
|
||||
|
||||
# Prevent tags and in-repo PRs from triggering this workflow more than once for a commit.
|
||||
# We also exclude 'push' events from the Merge Queue (gh-readonly-queue/) because they
|
||||
# trigger alongside the 'merge_group' event. Without this, a race condition in the
|
||||
# concurrency group could cause the 'push' event to cancel the 'merge_group' event.
|
||||
# We also exclude 'push' events on Merge Queue branches, as they are already
|
||||
# handled by the 'merge_group' event.
|
||||
if: >-
|
||||
github.ref_type != 'tag' &&
|
||||
(github.event_name != 'pull_request' || github.event.pull_request.head.repo.fork) &&
|
||||
|
|
|
|||
Loading…
Reference in a new issue