From 620ea40cb64a4998fb44ae48ad847f281127c4b4 Mon Sep 17 00:00:00 2001 From: Itay Brenner Date: Fri, 7 Nov 2025 12:31:32 -0300 Subject: [PATCH 1/2] chore: Update workflow to fetch labels using github API --- .github/workflows/build.yml | 3 -- .github/workflows/ready-to-merge-workflow.yml | 29 +++++++++---------- .github/workflows/release.yml | 3 -- .github/workflows/test.yml | 3 -- .github/workflows/ui-tests-critical.yml | 3 -- .github/workflows/ui-tests.yml | 3 -- develop-docs/CI.md | 3 -- 7 files changed, 14 insertions(+), 33 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 83191bd1df4..788a09cffac 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,9 +24,6 @@ jobs: ready-to-merge-gate: name: Ready-to-merge gate uses: ./.github/workflows/ready-to-merge-workflow.yml - with: - is-pr: ${{ github.event_name == 'pull_request' }} - labels: ${{ toJson(github.event.pull_request.labels) }} files-changed: name: Detect File Changes diff --git a/.github/workflows/ready-to-merge-workflow.yml b/.github/workflows/ready-to-merge-workflow.yml index 402593eb85f..ef3caa00921 100644 --- a/.github/workflows/ready-to-merge-workflow.yml +++ b/.github/workflows/ready-to-merge-workflow.yml @@ -1,15 +1,6 @@ name: Ready to Merge Workflow on: workflow_call: - inputs: - labels: - description: The GitHub event's labels - required: true - type: string - is-pr: - description: Whether the workflow is running on a PR - required: true - type: boolean jobs: ready-to-merge-gate: @@ -17,11 +8,19 @@ jobs: runs-on: ubuntu-latest steps: - name: Check for exact 'ready-to-merge' label - if: ${{ inputs.is-pr }} + if: ${{ github.event_name == 'pull_request' }} id: check-label + env: + GH_TOKEN: ${{ github.token }} + EXPECTED_LABEL: "ready-to-merge" run: | - # Use jq to check for exact label match (avoids substring matching issues with contains()) - if echo '${{ inputs.labels }}' | jq -e '.[] | select(.name == "ready-to-merge")' > /dev/null; then + # Fetch labels from GitHub API + # Looks like GH actions may not contain the labels in the event, so we need to fetch them from the API. + labels=$(gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels --jq '.[].name') + echo "Found labels: $labels" + + # Check for exact 'ready-to-merge' label match + if echo "$labels" | grep -q "^${{ env.EXPECTED_LABEL }}$"; then echo "label_found=true" >> $GITHUB_OUTPUT else echo "label_found=false" >> $GITHUB_OUTPUT @@ -29,13 +28,13 @@ jobs: # Since Github also accepts `skipped` results for Required Workflows, we need # to fail the job to ensure that the downstream jobs don't just skip. - name: Fail until the 'ready-to-merge' label is present - if: ${{ inputs.is-pr && steps.check-label.outputs.label_found == 'false' }} + if: ${{ github.event_name == 'pull_request' && steps.check-label.outputs.label_found == 'false' }} run: | echo "Add the 'ready-to-merge' label to run CI." exit 1 - name: Gate passed - if: ${{ inputs.is-pr && steps.check-label.outputs.label_found == 'true' }} + if: ${{ github.event_name == 'pull_request' && steps.check-label.outputs.label_found == 'true' }} run: echo "Label present. Proceeding with CI." - name: Gate passed - if: ${{ !inputs.is-pr }} + if: ${{ github.event_name != 'pull_request' }} run: echo "Not a PR. Proceeding with CI." diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0cee5875a6a..a49971f5048 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -37,9 +37,6 @@ jobs: ready-to-merge-gate: name: Ready-to-merge gate uses: ./.github/workflows/ready-to-merge-workflow.yml - with: - is-pr: ${{ github.event_name == 'pull_request' }} - labels: ${{ toJson(github.event.pull_request.labels) }} files-changed: name: Detect File Changes diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a4bd63eea9d..caf83832e93 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,9 +24,6 @@ jobs: ready-to-merge-gate: name: Ready-to-merge gate uses: ./.github/workflows/ready-to-merge-workflow.yml - with: - is-pr: ${{ github.event_name == 'pull_request' }} - labels: ${{ toJson(github.event.pull_request.labels) }} # This job detects if the PR contains changes that require running unit tests. # If yes, the job will output a flag that will be used by the next job to run the unit tests. diff --git a/.github/workflows/ui-tests-critical.yml b/.github/workflows/ui-tests-critical.yml index 4a55157f271..e5ec4357b25 100644 --- a/.github/workflows/ui-tests-critical.yml +++ b/.github/workflows/ui-tests-critical.yml @@ -23,9 +23,6 @@ jobs: ready-to-merge-gate: name: Ready-to-merge gate uses: ./.github/workflows/ready-to-merge-workflow.yml - with: - is-pr: ${{ github.event_name == 'pull_request' }} - labels: ${{ toJson(github.event.pull_request.labels) }} files-changed: name: Detect File Changes diff --git a/.github/workflows/ui-tests.yml b/.github/workflows/ui-tests.yml index e2fdced3c29..db2bc424ee6 100644 --- a/.github/workflows/ui-tests.yml +++ b/.github/workflows/ui-tests.yml @@ -23,9 +23,6 @@ jobs: ready-to-merge-gate: name: Ready-to-merge gate uses: ./.github/workflows/ready-to-merge-workflow.yml - with: - is-pr: ${{ github.event_name == 'pull_request' }} - labels: ${{ toJson(github.event.pull_request.labels) }} files-changed: name: Detect File Changes diff --git a/develop-docs/CI.md b/develop-docs/CI.md index 09ee96b7c8e..7e89b81163c 100644 --- a/develop-docs/CI.md +++ b/develop-docs/CI.md @@ -13,9 +13,6 @@ Add this job at the start the workflow and then add `need: ready-to-merge-gate` ready-to-merge-gate: name: Ready-to-merge gate uses: ./.github/workflows/ready-to-merge-workflow.yml - with: - is-pr: ${{ github.event_name == 'pull_request' }} - labels: ${{ toJson(github.event.pull_request.labels) }} ``` This job will: From 313832cdf41b93cfc93cc98e3de2e69c1d4a8435 Mon Sep 17 00:00:00 2001 From: Itay Brenner Date: Tue, 11 Nov 2025 15:10:05 -0300 Subject: [PATCH 2/2] Use github-script --- .github/workflows/ready-to-merge-workflow.yml | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ready-to-merge-workflow.yml b/.github/workflows/ready-to-merge-workflow.yml index ef3caa00921..8d5227c82ce 100644 --- a/.github/workflows/ready-to-merge-workflow.yml +++ b/.github/workflows/ready-to-merge-workflow.yml @@ -10,21 +10,25 @@ jobs: - name: Check for exact 'ready-to-merge' label if: ${{ github.event_name == 'pull_request' }} id: check-label - env: - GH_TOKEN: ${{ github.token }} - EXPECTED_LABEL: "ready-to-merge" - run: | - # Fetch labels from GitHub API - # Looks like GH actions may not contain the labels in the event, so we need to fetch them from the API. - labels=$(gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels --jq '.[].name') - echo "Found labels: $labels" + uses: actions/github-script@v7 + with: + script: | + const expectedLabel = 'ready-to-merge'; + + // Fetch labels from GitHub API + // GitHub Actions may not contain the labels in the event, so we need to fetch them from the API. + const { data: labels } = await github.rest.issues.listLabelsOnIssue({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number + }); + + const labelNames = labels.map(label => label.name); + console.log(`Found labels: ${labelNames.join(', ')}`); - # Check for exact 'ready-to-merge' label match - if echo "$labels" | grep -q "^${{ env.EXPECTED_LABEL }}$"; then - echo "label_found=true" >> $GITHUB_OUTPUT - else - echo "label_found=false" >> $GITHUB_OUTPUT - fi + // Check for exact 'ready-to-merge' label match + const labelFound = labelNames.includes(expectedLabel); + core.setOutput('label_found', labelFound.toString()); # Since Github also accepts `skipped` results for Required Workflows, we need # to fail the job to ensure that the downstream jobs don't just skip. - name: Fail until the 'ready-to-merge' label is present