-
Notifications
You must be signed in to change notification settings - Fork 407
67 lines (64 loc) · 2.16 KB
/
rerun-failed-workflows.yaml
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
61
62
63
64
65
66
67
name: Rerun Failed Workflows
on:
issue_comment:
types: [created]
jobs:
rerun_failed_workflows:
runs-on: ubuntu-22.04
steps:
- name: Check for Command and Access Level
id: check
uses: actions/github-script@v5
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issue = context.issue;
const username = context.payload.comment.user.login;
const regex = /\/rerun/g;
const comment = await github.rest.issues.getComment({
owner: issue.owner,
repo: issue.repo,
comment_id: context.payload.comment.id,
});
if (regex.test(comment.data.body)) {
try {
await github.rest.repos.checkUserAccessLevel({
owner: issue.owner,
repo: issue.repo,
username: username,
permission: 'read'
});
return true;
} catch (error) {
console.log(`User ${username} does not have access to rerun failed workflows`);
return false;
}
} else {
return false;
}
result-encoding: string
- name: Fetch and rerun failed workflows
if: steps.check.outputs.result == 'true'
uses: actions/github-script@v5
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const issue = context.issue;
const pull = await github.rest.pulls.get({
owner: issue.owner,
repo: issue.repo,
pull_number: issue.number,
});
const workflows = await github.rest.actions.listWorkflowRunsForRepo({
owner: issue.owner,
repo: issue.repo,
branch: pull.data.head.ref,
status: 'failure',
});
for (const run of workflows.data.workflow_runs) {
await github.rest.actions.reRunWorkflow({
owner: issue.owner,
repo: issue.repo,
run_id: run.id,
});
}