2024-04-14 17:49:41 -04:00
|
|
|
name: Cancel queued workflows on PR merge
|
|
|
|
|
2024-03-29 00:46:38 -04:00
|
|
|
on:
|
|
|
|
pull_request:
|
|
|
|
types:
|
|
|
|
- closed
|
|
|
|
|
|
|
|
jobs:
|
2024-04-14 17:49:41 -04:00
|
|
|
|
2024-03-29 00:46:38 -04:00
|
|
|
cancel_stuff:
|
|
|
|
if: github.event.pull_request.merged == true
|
2024-04-14 17:49:41 -04:00
|
|
|
runs-on: build-set
|
2024-03-29 00:46:38 -04:00
|
|
|
permissions:
|
|
|
|
actions: write
|
2024-04-14 17:49:41 -04:00
|
|
|
|
2024-03-29 00:46:38 -04:00
|
|
|
steps:
|
2024-04-14 17:49:41 -04:00
|
|
|
- name: Cancel queued workflows for ${{ github.event.pull_request.head.ref }}
|
|
|
|
uses: actions/github-script@v7
|
|
|
|
with:
|
|
|
|
result-encoding: string
|
|
|
|
retries: 3
|
|
|
|
script: |
|
|
|
|
let branch_workflows = await github.rest.actions.listWorkflowRuns({
|
|
|
|
owner: context.repo.owner,
|
|
|
|
repo: context.repo.repo,
|
|
|
|
workflow_id: "build-shit.yml",
|
|
|
|
status: "queued",
|
|
|
|
branch: "${{ github.event.pull_request.head.ref }}"
|
|
|
|
});
|
|
|
|
let runs = branch_workflows.data.workflow_runs;
|
|
|
|
runs.forEach((run) => {
|
|
|
|
github.rest.actions.cancelWorkflowRun({
|
2024-03-29 00:46:38 -04:00
|
|
|
owner: context.repo.owner,
|
|
|
|
repo: context.repo.repo,
|
2024-04-14 17:49:41 -04:00
|
|
|
run_id: run.id
|
2024-03-29 00:46:38 -04:00
|
|
|
});
|
2024-04-14 17:49:41 -04:00
|
|
|
});
|
|
|
|
console.log(runs);
|