-
Notifications
You must be signed in to change notification settings - Fork 12
/
workflow-runs.js
30 lines (27 loc) · 963 Bytes
/
workflow-runs.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
const sleep = async (milliseconds) => {
return new Promise((resolve) => {
setTimeout(resolve, milliseconds)
})
}
const waitForWorkflowRunToFinish = async (context, token, owner, repo, workflowRunId) => {
const githubApiRequest = require('./github-api-request')
let counter = 0
for (;;) {
const res = await githubApiRequest(
context,
token,
'GET',
`/repos/${owner}/${repo}/actions/runs/${workflowRunId}`
)
if (res.status === 'completed') {
if (res.conclusion !== 'success') throw new Error(`Workflow run ${workflowRunId} completed with ${res.conclusion}!`)
return res
}
if (context.log) context.log(`Waiting for workflow run ${workflowRunId} (current status: ${res.status})`)
if (counter++ > 60) throw new Error(`Timed out waiting for workflow run ${workflowRunId}?`)
await sleep(10000)
}
}
module.exports = {
waitForWorkflowRunToFinish
}