diff --git a/.github/workflows/ci-trigger-full-suite.yml b/.github/workflows/ci-trigger-full-suite.yml index 7d184249b..494f24b61 100644 --- a/.github/workflows/ci-trigger-full-suite.yml +++ b/.github/workflows/ci-trigger-full-suite.yml @@ -2,7 +2,7 @@ name: Trigger Full Suite on: pull_request: - types: [labeled] + types: [labeled, synchronize] permissions: contents: read @@ -14,10 +14,43 @@ concurrency: jobs: trigger: - if: github.event.label.name == 'ready' + if: >- + (github.event.action == 'labeled' && github.event.label.name == 'ready') + || github.event.action == 'synchronize' runs-on: ubuntu-latest steps: + - name: Check ready label + id: check + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + with: + script: | + const { data: pr } = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + }); + const hasReady = pr.labels.some(l => l.name === 'ready'); + core.setOutput('has_ready', String(hasReady)); + if (!hasReady) core.info('No ready label — skipping Full Suite trigger.'); + + - name: Cancel previous Buildkite builds + if: steps.check.outputs.has_ready == 'true' + env: + BUILDKITE_API_TOKEN: ${{ secrets.BUILDKITE_API_TOKEN }} + PR_BRANCH: ${{ github.event.pull_request.head.ref }} + run: | + # Find running builds for this branch with FULL_SUITE=true and cancel them + builds=$(curl -sS -H "Authorization: Bearer $BUILDKITE_API_TOKEN" \ + "https://api.buildkite.com/v2/organizations/${{ vars.BUILDKITE_ORG_SLUG }}/pipelines/${{ vars.BUILDKITE_PIPELINE_SLUG }}/builds?branch=${PR_BRANCH}&state=running,scheduled" \ + | jq -r '.[] | select(.env.FULL_SUITE == "true") | .number') + for build_num in $builds; do + echo "Cancelling Buildkite build #$build_num" + curl -sS -X PUT -H "Authorization: Bearer $BUILDKITE_API_TOKEN" \ + "https://api.buildkite.com/v2/organizations/${{ vars.BUILDKITE_ORG_SLUG }}/pipelines/${{ vars.BUILDKITE_PIPELINE_SLUG }}/builds/${build_num}/cancel" + done + - name: Trigger Buildkite Full Suite + if: steps.check.outputs.has_ready == 'true' uses: buildkite/trigger-pipeline-action@v2.4.1 with: buildkite_api_access_token: ${{ secrets.BUILDKITE_API_TOKEN }}