@@ -5,13 +5,13 @@ const config = require('./config');
5
5
6
6
// use the unique label to find the runner
7
7
// as we don't have the runner's id, it's not possible to get it in any other way
8
- async function getRunner ( label ) {
8
+ async function getRunners ( label ) {
9
9
const octokit = github . getOctokit ( config . input . githubToken ) ;
10
10
11
11
try {
12
12
const runners = await octokit . paginate ( 'GET /repos/{owner}/{repo}/actions/runners' , config . githubContext ) ;
13
13
const foundRunners = _ . filter ( runners , { labels : [ { name : label } ] } ) ;
14
- return foundRunners . length > 0 ? foundRunners [ 0 ] : null ;
14
+ return foundRunners . length > 0 ? foundRunners : null ;
15
15
} catch ( error ) {
16
16
return null ;
17
17
}
@@ -32,22 +32,27 @@ async function getRegistrationToken() {
32
32
}
33
33
34
34
async function removeRunner ( ) {
35
- const runner = await getRunner ( config . input . label ) ;
35
+ const runners = await getRunners ( config . input . label ) ;
36
36
const octokit = github . getOctokit ( config . input . githubToken ) ;
37
37
38
38
// skip the runner removal process if the runner is not found
39
- if ( ! runner ) {
40
- core . info ( `GitHub self-hosted runner with label ${ config . input . label } is not found, so the removal is skipped` ) ;
39
+ if ( ! runners ) {
40
+ core . info ( `GitHub self-hosted runners with label ${ config . input . label } not found, so the removal is skipped` ) ;
41
41
return ;
42
42
}
43
43
44
- try {
45
- await octokit . request ( 'DELETE /repos/{owner}/{repo}/actions/runners/{runner_id}' , _ . merge ( config . githubContext , { runner_id : runner . id } ) ) ;
46
- core . info ( `GitHub self-hosted runner ${ runner . name } is removed` ) ;
47
- return ;
48
- } catch ( error ) {
49
- core . error ( 'GitHub self-hosted runner removal error' ) ;
50
- throw error ;
44
+ const errors = runners . reduce ( async ( errors , runner ) => {
45
+ try {
46
+ await octokit . request ( 'DELETE /repos/{owner}/{repo}/actions/runners/{runner_id}' , _ . merge ( config . githubContext , { runner_id : runner . id } ) ) ;
47
+ core . info ( `GitHub self-hosted runner ${ runner . name } is removed` ) ;
48
+ } catch ( error ) {
49
+ core . error ( `GitHub self-hosted runner ${ runner } removal error: ${ error } ` ) ;
50
+ errors . push ( error ) ;
51
+ }
52
+ return errors ;
53
+ } ) ;
54
+ if ( errors . length > 0 ) {
55
+ core . setFailure ( 'Encountered error(s) removing self-hosted runner(s)' ) ;
51
56
}
52
57
}
53
58
@@ -58,21 +63,23 @@ async function waitForRunnerRegistered(label) {
58
63
let waitSeconds = 0 ;
59
64
60
65
core . info ( `Waiting ${ quietPeriodSeconds } s for the AWS EC2 instance to be registered in GitHub as a new self-hosted runner` ) ;
61
- await new Promise ( r => setTimeout ( r , quietPeriodSeconds * 1000 ) ) ;
66
+ await new Promise ( ( r ) => setTimeout ( r , quietPeriodSeconds * 1000 ) ) ;
62
67
core . info ( `Checking every ${ retryIntervalSeconds } s if the GitHub self-hosted runner is registered` ) ;
63
68
64
69
return new Promise ( ( resolve , reject ) => {
65
70
const interval = setInterval ( async ( ) => {
66
- const runner = await getRunner ( label ) ;
71
+ const runners = await getRunners ( label ) ;
67
72
68
73
if ( waitSeconds > timeoutMinutes * 60 ) {
69
74
core . error ( 'GitHub self-hosted runner registration error' ) ;
70
75
clearInterval ( interval ) ;
71
- reject ( `A timeout of ${ timeoutMinutes } minutes is exceeded. Your AWS EC2 instance was not able to register itself in GitHub as a new self-hosted runner.` ) ;
76
+ reject (
77
+ `A timeout of ${ timeoutMinutes } minutes is exceeded. Your AWS EC2 instance was not able to register itself in GitHub as a new self-hosted runner.`
78
+ ) ;
72
79
}
73
80
74
- if ( runner && runner . status === 'online' ) {
75
- core . info ( `GitHub self-hosted runner ${ runner . name } is registered and ready to use` ) ;
81
+ if ( runners && runners . every ( ( runner ) => runner . status === 'online' ) ) {
82
+ core . info ( `GitHub self-hosted runners ${ runners } are registered and ready to use` ) ;
76
83
clearInterval ( interval ) ;
77
84
resolve ( ) ;
78
85
} else {
0 commit comments