-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
55 lines (42 loc) · 1.36 KB
/
index.js
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
const { Octokit } = require("@octokit/rest");
const core = require("@actions/core");
const settings = ["auth", "owner", "repo", "workflowID"].reduce((obj, key) => {
obj[key] = core.getInput(key);
return obj;
}, {});
const octokit = new Octokit({
"auth": settings.auth
});
(async () => {
let success;
let latestRun = (await octokit.request('GET /repos/{owner}/{repo}/actions/workflows/{workflow_id}/runs', {
"owner": settings.owner,
"repo": settings.repo,
"workflow_id": settings.workflowID
})).data.workflow_runs.sort((a, b) => new Date(b.created_at) - new Date(a.created_at))[0];
console.log(`latestRun.id: ${latestRun.id}`);
console.log(`latestRun.status: ${latestRun.status}`);
if (!latestRun) {
console.error("No runs in this workflow.");
success = false;
} else {
while (latestRun.status !== "completed") {
await timeout(30000);
latestRun = (await octokit.request('GET /repos/{owner}/{repo}/actions/runs/{run_id}', {
"owner": settings.owner,
"repo": settings.repo,
"run_id": latestRun.id
})).data;
console.log(`latestRun.id: ${latestRun.id}`);
console.log(`latestRun.status: ${latestRun.status}`);
}
success = latestRun.conclusion === "success";
}
console.log(`success: ${success}`);
process.exit(success ? 0 : 1);
})();
function timeout (ms) {
return new Promise((resolve) => {
setTimeout(() => resolve(), ms);
});
}