forked from vllm-project/vllm-ascend
-
Notifications
You must be signed in to change notification settings - Fork 1
46 lines (40 loc) · 1.51 KB
/
Copy pathpr_close_cancel_job.yaml
File metadata and controls
46 lines (40 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
name: Cancel runs on PR close
on:
pull_request:
types: [closed]
permissions:
actions: write
contents: read
jobs:
cancel:
runs-on: linux-amd64-cpu-2-hk
steps:
- uses: actions/github-script@v9
with:
github-token: ${{ github.token }}
script: |
const { owner, repo } = context.repo;
const branch = context.payload.pull_request.head.ref;
const statuses = ["in_progress", "queued", "waiting", "pending", "requested"];
for (const status of statuses) {
let page = 1;
while (true) {
const resp = await github.rest.actions.listWorkflowRunsForRepo({
owner, repo, branch, status, per_page: 100, page
});
const runs = resp.data.workflow_runs;
if (!runs.length) break;
for (const run of runs) {
if (run.id === context.runId) continue; // don't cancel this workflow
try {
await github.rest.actions.cancelWorkflowRun({ owner, repo, run_id: run.id });
core.info(`Cancel requested: ${run.html_url}`);
} catch (e) {
// common reasons: already completed (409) or insufficient permissions (403)
core.warning(`Failed to cancel ${run.html_url}: ${e.message}`);
}
}
if (runs.length < 100) break;
page++;
}
}