From eca7a962ff7a02a47ed63af49b2e95142cfd492e Mon Sep 17 00:00:00 2001 From: MuriloZF Date: Wed, 17 Dec 2025 20:01:31 -0300 Subject: [PATCH] Add ready-to-merge-label (#1032) --- .github/workflows/ready-to-merge-workflow.yml | 51 +++++++++++++++++++ .github/workflows/sample-build.yml | 7 +++ 2 files changed, 58 insertions(+) create mode 100644 .github/workflows/ready-to-merge-workflow.yml diff --git a/.github/workflows/ready-to-merge-workflow.yml b/.github/workflows/ready-to-merge-workflow.yml new file mode 100644 index 00000000..ced7530e --- /dev/null +++ b/.github/workflows/ready-to-merge-workflow.yml @@ -0,0 +1,51 @@ +name: Ready to Merge Workflow +on: + workflow_call: + inputs: + is-pr: + required: false + type: boolean + labels: + required: false + type: string + +jobs: + ready-to-merge-gate: + name: 'Missing "ready-to-merge" label' + runs-on: ubuntu-latest + steps: + - name: Check for exact 'ready-to-merge' label + if: ${{ github.event_name == 'pull_request' }} + id: check-label + uses: actions/github-script@v8 + 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 + 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 + 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: ${{ github.event_name == 'pull_request' && steps.check-label.outputs.label_found == 'true' }} + run: echo "Label present. Proceeding with CI." + - name: Gate passed + if: ${{ github.event_name != 'pull_request' }} + run: echo "Not a PR. Proceeding with CI." diff --git a/.github/workflows/sample-build.yml b/.github/workflows/sample-build.yml index f62cc2f6..c3dd6af5 100644 --- a/.github/workflows/sample-build.yml +++ b/.github/workflows/sample-build.yml @@ -18,9 +18,16 @@ env: BUILD_CACHE_KEY: ${{ inputs.build_cache_key }} 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) }} job_sample_build: name: Sample Build (${{ matrix.bump }}) runs-on: macos-latest + needs: ready-to-merge-gate strategy: matrix: include: