-
Notifications
You must be signed in to change notification settings - Fork 12
94 lines (91 loc) · 3.47 KB
/
ready_to_merge.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
name: Ready to Merge
on:
pull_request:
types: [opened, synchronize, reopened]
# branches:
# - main
workflow_dispatch:
jobs:
check_commit_status:
runs-on: ubuntu-latest
steps:
- name: Confirm Check Runs
uses: actions/github-script@v7
with:
script: |
workflows_to_check = (
"analyze",
"format",
"GitGuardian Security Checks",
"check_changes",
"test",
"MegaLinter",
"drive_web",
"pgtap"
);
console.log("Sleeping 10s to give other runs a chance to start");
await sleep(10000);
const { owner, repo } = context.repo;
const commit_sha = context.payload.pull_request.head.sha; // Get the SHA of the head commit of the PR
const maxRetries = 15; // Maximum number of retries
const excludedCheckRunName = "check_commit_status"; // important you don't define name key for the job
let retryCount = 0;
async function fetchCheckRuns() {
const response = await github.rest.checks.listForRef({
owner,
repo,
ref: commit_sha,
// check_name: workflows_to_check,
per_page: 100,
});
return response.data.check_runs;
}
async function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
let checkRuns = await fetchCheckRuns();
let inProgressFound = false;
let failureFound = false;
do {
inProgressFound = false;
failureFound = false;
for (const checkRun of checkRuns) {
console.log("Looking at check run: " + checkRun.name);
// Exclude this job from the evaluation
if (
checkRun.name === excludedCheckRunName ||
!workflows_to_check.includes(checkRun.name)
) {
console.log("Skipping check run: " + checkRun.name);
continue;
}
if (checkRun.status === "completed") {
workflows_to_check.remove(checkRun.name);
console.log("Check run completed: " + checkRun.name);
}
if (checkRun.status === "in_progress") {
inProgressFound = true;
console.log("Check run in progress: " + checkRun.name);
}
if (checkRun.conclusion === "failure") {
failureFound = true;
console.log("Check run failed: " + checkRun.name);
// We could break here, but we want to wait for all checks to complete
}
}
if (inProgressFound) {
if (retryCount >= maxRetries) {
core.setFailed(
"Maximum retries reached with check runs still in progress."
);
break;
}
console.log("Waiting for 1 minute before rechecking...");
await sleep(60000);
checkRuns = await fetchCheckRuns();
retryCount++;
}
} while (inProgressFound);
if (failureFound) {
core.setFailed("There are failed check runs.");
}