-
Notifications
You must be signed in to change notification settings - Fork 9
60 lines (55 loc) · 1.94 KB
/
re-run.yml
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 重试被取消的workflow run
name: 重试更新计分板
on:
workflow_dispatch:
schedule:
# - cron: '*/12 2-16 * * *'
# - cron: '30 0-1,17-23 * * *'
- cron: '30 * * * *'
permissions:
actions: write
jobs:
rerun:
runs-on: ubuntu-latest
steps:
- name: 重试
uses: actions/github-script@v7
with:
script: |
/*async function list_cancelled_workflow_runs() {
let r = (await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: "add-score.yml",
per_page: 100,
page: 1
})).data;
r.workflow_runs = r.workflow_runs.filter(run => run.conclusion === "cancelled");
r.total_count = r.workflow_runs.length;
return r;
}*/
for (let i = 0; i < 10; i++) {
if (i !== 0)
await new Promise(resolve => setTimeout(resolve, 30000));
const r = (await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: "add-score.yml",
status: "cancelled",
per_page: 100,
page: 1
})).data;
// const r = await list_cancelled_workflow_runs(); // 最近GitHub Actions查询workflow run有问题,所以手动进行处理
console.log(r.total_count);
if (r.total_count === 0)
return;
const count = r.total_count > 100 ? 100 : r.total_count;
const id = r.workflow_runs[count - 1].id;
console.log(id);
console.log(r.workflow_runs[count - 1].run_number);
await github.request("POST /repos/{owner}/{repo}/actions/runs/{run_id}/rerun", {
owner: context.repo.owner,
repo: context.repo.repo,
run_id: id
});
}