-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgh.js
More file actions
68 lines (58 loc) · 1.97 KB
/
gh.js
File metadata and controls
68 lines (58 loc) · 1.97 KB
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
const core = require('@actions/core')
const github = require('@actions/github')
const _ = require('lodash')
const config = require('./config')
const utils = require('./utils')
// Use the unique label to find the runner as we don't have the runner's id,
// it's not possible to get it in any other way.
async function getRunner(label) {
const octokit = github.getOctokit(config.input.githubToken)
let runners = []
try {
runners = await octokit.paginate(
'GET /repos/{owner}/{repo}/actions/runners',
{
owner: config.githubContext.owner,
repo: config.githubContext.repo
}
)
} catch (error) {
core.error(`Failed to fetch runners: ${error.message}`)
return null
}
const foundRunners = _.filter(runners, { name: label })
return foundRunners.length > 0 ? foundRunners[0] : null
}
async function waitForRunnerRegistered(label) {
const timeoutSeconds = 1800
const retryIntervalSeconds = 10
const quietPeriodSeconds = 30
let waitSeconds = 0
core.info(
`Waiting ${quietPeriodSeconds}s for ${config.input.backend} instance to be registered in GitHub as a new self-hosted runner`
)
await utils.sleep(quietPeriodSeconds)
core.info(
`Checking every ${retryIntervalSeconds}s if the GitHub self-hosted runner is registered (runner: ${label})`
)
while (waitSeconds < timeoutSeconds) {
const runner = await getRunner(label)
if (runner && runner.status === 'online') {
core.info(
`GitHub self-hosted runner ${runner.name} is registered and ready to use`
)
return
} else {
waitSeconds += retryIntervalSeconds
core.info('Checking...')
}
await utils.sleep(retryIntervalSeconds)
}
core.error(
`A timeout of ${timeoutSeconds} seconds is exceeded. Your ${config.input.backend} instance was not able to register itself in GitHub as a new self-hosted runner.`
)
throw new Error('GitHub self-hosted runner registration error')
}
module.exports = {
waitForRunnerRegistered
}