Skip to content

Commit 543b791

Browse files
authored
chore: Update workflow to fetch labels using github API (#6721)
* chore: Update workflow to fetch labels using github API * Use github-script
1 parent 483cc24 commit 543b791

File tree

7 files changed

+23
-38
lines changed

7 files changed

+23
-38
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ jobs:
2424
ready-to-merge-gate:
2525
name: Ready-to-merge gate
2626
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) }}
3027

3128
files-changed:
3229
name: Detect File Changes
Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,44 @@
11
name: Ready to Merge Workflow
22
on:
33
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
134

145
jobs:
156
ready-to-merge-gate:
167
name: 'Missing "ready-to-merge" label'
178
runs-on: ubuntu-latest
189
steps:
1910
- name: Check for exact 'ready-to-merge' label
20-
if: ${{ inputs.is-pr }}
11+
if: ${{ github.event_name == 'pull_request' }}
2112
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
13+
uses: actions/github-script@v7
14+
with:
15+
script: |
16+
const expectedLabel = 'ready-to-merge';
17+
18+
// Fetch labels from GitHub API
19+
// GitHub Actions may not contain the labels in the event, so we need to fetch them from the API.
20+
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
21+
owner: context.repo.owner,
22+
repo: context.repo.repo,
23+
issue_number: context.issue.number
24+
});
25+
26+
const labelNames = labels.map(label => label.name);
27+
console.log(`Found labels: ${labelNames.join(', ')}`);
28+
29+
// Check for exact 'ready-to-merge' label match
30+
const labelFound = labelNames.includes(expectedLabel);
31+
core.setOutput('label_found', labelFound.toString());
2932
# Since Github also accepts `skipped` results for Required Workflows, we need
3033
# to fail the job to ensure that the downstream jobs don't just skip.
3134
- name: Fail until the 'ready-to-merge' label is present
32-
if: ${{ inputs.is-pr && steps.check-label.outputs.label_found == 'false' }}
35+
if: ${{ github.event_name == 'pull_request' && steps.check-label.outputs.label_found == 'false' }}
3336
run: |
3437
echo "Add the 'ready-to-merge' label to run CI."
3538
exit 1
3639
- name: Gate passed
37-
if: ${{ inputs.is-pr && steps.check-label.outputs.label_found == 'true' }}
40+
if: ${{ github.event_name == 'pull_request' && steps.check-label.outputs.label_found == 'true' }}
3841
run: echo "Label present. Proceeding with CI."
3942
- name: Gate passed
40-
if: ${{ !inputs.is-pr }}
43+
if: ${{ github.event_name != 'pull_request' }}
4144
run: echo "Not a PR. Proceeding with CI."

.github/workflows/release.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ jobs:
3737
ready-to-merge-gate:
3838
name: Ready-to-merge gate
3939
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) }}
4340

4441
files-changed:
4542
name: Detect File Changes

.github/workflows/test.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ jobs:
2424
ready-to-merge-gate:
2525
name: Ready-to-merge gate
2626
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) }}
3027

3128
# This job detects if the PR contains changes that require running unit tests.
3229
# If yes, the job will output a flag that will be used by the next job to run the unit tests.

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ jobs:
2323
ready-to-merge-gate:
2424
name: Ready-to-merge gate
2525
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) }}
2926

3027
files-changed:
3128
name: Detect File Changes

.github/workflows/ui-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ jobs:
2323
ready-to-merge-gate:
2424
name: Ready-to-merge gate
2525
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) }}
2926

3027
files-changed:
3128
name: Detect File Changes

develop-docs/CI.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ Add this job at the start the workflow and then add `need: ready-to-merge-gate`
1313
ready-to-merge-gate:
1414
name: Ready-to-merge gate
1515
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) }}
1916
```
2017

2118
This job will:

0 commit comments

Comments
 (0)