GeezerVison is showing github.com — Auto-port 4.1: Add workflow that will cancel running workflows for me… · lltopk/netty@9568693
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboard +37Lines changed: 37 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +# Fork of https://github.com/AgentWorkforce/relay/blob/v12.2.2/.github/workflows/cancel-on-merge.yml |
| 2 | +name: Cancel PR Jobs on Merge |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [closed] |
| 6 | + |
| 7 | +jobs: |
| 8 | + cancel: |
| 9 | + if: github.event.pull_request.merged == true |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Cancel running workflows for this PR |
| 13 | + uses: actions/github-script@v7 |
| 14 | + with: |
| 15 | + script: | |
| 16 | + const { owner, repo } = context.repo; |
| 17 | + const headSha = context.payload.pull_request.head.sha; |
| 18 | +
|
| 19 | + // Get all running workflow runs for this commit |
| 20 | + const runs = await github.rest.actions.listWorkflowRunsForRepo({ |
| 21 | + owner, |
| 22 | + repo, |
| 23 | + status: 'in_progress', |
| 24 | + head_sha: headSha, |
| 25 | + }); |
| 26 | +
|
| 27 | + // Cancel each running workflow |
| 28 | + for (const run of runs.data.workflow_runs) { |
| 29 | + console.log(`Cancelling workflow run ${run.id} (${run.name})`); |
| 30 | + await github.rest.actions.cancelWorkflowRun({ |
| 31 | + owner, |
| 32 | + repo, |
| 33 | + run_id: run.id, |
| 34 | + }); |
| 35 | + } |
| 36 | +
|
| 37 | + console.log(`Cancelled ${runs.data.workflow_runs.length} workflow runs`); |