Skip to content

Commit 52bdc10

Browse files
authored
chore: Require ready-to-merge label to run all checks (#6686)
* chore: Require `ready-to-merge` label to run all checks * Always run `Ready-to-merge gate` job to avoid unintended skips * Rename `ready` to `ready-to-merge-gate` * Add documentation for ready to merge label * Add comment to gate workflow * Improve label logic * Add debug step (will remove later) * More debugging * Improve condition * Fix check * Fix check
1 parent 6ad363f commit 52bdc10

File tree

7 files changed

+111
-0
lines changed

7 files changed

+111
-0
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
- release/**
88

99
pull_request:
10+
types: [opened, synchronize, reopened, labeled]
1011

1112
# Concurrency configuration:
1213
# - We use workflow-specific concurrency groups to prevent multiple build runs of the same code,
@@ -20,9 +21,17 @@ concurrency:
2021
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
2122

2223
jobs:
24+
ready-to-merge-gate:
25+
name: Ready-to-merge gate
26+
uses: ./.github/workflows/ready-to-merge-workflow.yml
27+
with:
28+
is-pr: ${{ github.event_name == 'pull_request' }}
29+
labels: ${{ toJson(github.event.pull_request.labels) }}
30+
2331
files-changed:
2432
name: Detect File Changes
2533
runs-on: ubuntu-latest
34+
needs: ready-to-merge-gate
2635
outputs:
2736
run_build_for_prs: ${{ steps.changes.outputs.run_build_for_prs }}
2837
steps:
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Ready to Merge Workflow
2+
on:
3+
workflow_call:
4+
inputs:
5+
labels:
6+
description: The GitHub event's labels
7+
required: true
8+
type: string
9+
is-pr:
10+
description: Whether the workflow is running on a PR
11+
required: true
12+
type: boolean
13+
14+
jobs:
15+
ready-to-merge-gate:
16+
name: 'Missing "ready-to-merge" label'
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Check for exact 'ready-to-merge' label
20+
if: ${{ inputs.is-pr }}
21+
id: check-label
22+
run: |
23+
# Use jq to check for exact label match (avoids substring matching issues with contains())
24+
if echo '${{ inputs.labels }}' | jq -e '.[] | select(.name == "ready-to-merge")' > /dev/null; then
25+
echo "label_found=true" >> $GITHUB_OUTPUT
26+
else
27+
echo "label_found=false" >> $GITHUB_OUTPUT
28+
fi
29+
# Since Github also accepts `skipped` results for Required Workflows, we need
30+
# to fail the job to ensure that the downstream jobs don't just skip.
31+
- name: Fail until the 'ready-to-merge' label is present
32+
if: ${{ inputs.is-pr && steps.check-label.outputs.label_found == 'false' }}
33+
run: |
34+
echo "Add the 'ready-to-merge' label to run CI."
35+
exit 1
36+
- name: Gate passed
37+
if: ${{ inputs.is-pr && steps.check-label.outputs.label_found == 'true' }}
38+
run: echo "Label present. Proceeding with CI."
39+
- name: Gate passed
40+
if: ${{ !inputs.is-pr }}
41+
run: echo "Not a PR. Proceeding with CI."

.github/workflows/release.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
- v8.x
99

1010
pull_request:
11+
types: [opened, synchronize, reopened, labeled]
1112

1213
workflow_dispatch:
1314
inputs:
@@ -33,9 +34,17 @@ concurrency:
3334
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
3435

3536
jobs:
37+
ready-to-merge-gate:
38+
name: Ready-to-merge gate
39+
uses: ./.github/workflows/ready-to-merge-workflow.yml
40+
with:
41+
is-pr: ${{ github.event_name == 'pull_request' }}
42+
labels: ${{ toJson(github.event.pull_request.labels) }}
43+
3644
files-changed:
3745
name: Detect File Changes
3846
runs-on: ubuntu-latest
47+
needs: ready-to-merge-gate
3948
outputs:
4049
run_release_for_prs: ${{ steps.changes.outputs.run_release_for_prs }}
4150
steps:

.github/workflows/test.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ on:
77
- release/**
88

99
pull_request:
10+
types: [opened, synchronize, reopened, labeled]
1011

1112
# Concurrency configuration:
1213
# - We use workflow-specific concurrency groups to allow independent test runs across different workflows
@@ -20,6 +21,13 @@ concurrency:
2021
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
2122

2223
jobs:
24+
ready-to-merge-gate:
25+
name: Ready-to-merge gate
26+
uses: ./.github/workflows/ready-to-merge-workflow.yml
27+
with:
28+
is-pr: ${{ github.event_name == 'pull_request' }}
29+
labels: ${{ toJson(github.event.pull_request.labels) }}
30+
2331
# This job detects if the PR contains changes that require running unit tests.
2432
# If yes, the job will output a flag that will be used by the next job to run the unit tests.
2533
# If no, the job will output a flag that will be used by the next job to skip running the unit tests.
@@ -28,6 +36,7 @@ jobs:
2836
files-changed:
2937
name: Detect File Changes
3038
runs-on: ubuntu-latest
39+
needs: ready-to-merge-gate
3140
# Map a step output to a job output
3241
outputs:
3342
run_unit_tests_for_prs: ${{ steps.changes.outputs.run_unit_tests_for_prs }}

.github/workflows/ui-tests-critical.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- v8.x
77

88
pull_request:
9+
types: [opened, synchronize, reopened, labeled]
910

1011
# Concurrency configuration:
1112
# - We use workflow-specific concurrency groups to prevent multiple critical UI test runs,
@@ -19,9 +20,17 @@ concurrency:
1920
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
2021

2122
jobs:
23+
ready-to-merge-gate:
24+
name: Ready-to-merge gate
25+
uses: ./.github/workflows/ready-to-merge-workflow.yml
26+
with:
27+
is-pr: ${{ github.event_name == 'pull_request' }}
28+
labels: ${{ toJson(github.event.pull_request.labels) }}
29+
2230
files-changed:
2331
name: Detect File Changes
2432
runs-on: ubuntu-latest
33+
needs: ready-to-merge-gate
2534
outputs:
2635
run_ui_tests_critical_for_prs: ${{ steps.changes.outputs.run_ui_tests_critical_for_prs }}
2736
steps:

.github/workflows/ui-tests.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
- v8.x
77

88
pull_request:
9+
types: [opened, synchronize, reopened, labeled]
910

1011
# Concurrency configuration:
1112
# - We use workflow-specific concurrency groups to prevent multiple UI test runs on the same code,
@@ -19,9 +20,17 @@ concurrency:
1920
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
2021

2122
jobs:
23+
ready-to-merge-gate:
24+
name: Ready-to-merge gate
25+
uses: ./.github/workflows/ready-to-merge-workflow.yml
26+
with:
27+
is-pr: ${{ github.event_name == 'pull_request' }}
28+
labels: ${{ toJson(github.event.pull_request.labels) }}
29+
2230
files-changed:
2331
name: Detect File Changes
2432
runs-on: ubuntu-latest
33+
needs: ready-to-merge-gate
2534
outputs:
2635
run_ui_tests_for_prs: ${{ steps.changes.outputs.run_ui_tests_for_prs }}
2736
steps:

develop-docs/CI.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# CI inner working
2+
3+
## `ready-to-merge` label
4+
5+
CI checks are great, but macOS runners are limited on every provider, because of this, we need to be smarter on how we run jobs.
6+
To avoid running many jobs on every PR's commit, we have decided to only run a subset of tests regularily and run the full suite only when the PR has the label `ready-to-merge`.
7+
8+
### How to use the gate
9+
10+
Add this job at the start the workflow and then add `need: ready-to-merge-gate` to jobs that you want to be skipped.
11+
12+
```
13+
ready-to-merge-gate:
14+
name: Ready-to-merge gate
15+
uses: ./.github/workflows/ready-to-merge-workflow.yml
16+
with:
17+
is-pr: ${{ github.event_name == 'pull_request' }}
18+
labels: ${{ toJson(github.event.pull_request.labels) }}
19+
```
20+
21+
This job will:
22+
23+
- Pass if the event is not a PR
24+
- Fail if the event is a PR and is missing the `ready-to-merge` label
25+
- Pass if the event is a PR and is has the `ready-to-merge` label

0 commit comments

Comments
 (0)