@@ -5,13 +5,13 @@ const config = require('./config');
55
66// use the unique label to find the runner
77// 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 ) {
99 const octokit = github . getOctokit ( config . input . githubToken ) ;
1010
1111 try {
1212 const runners = await octokit . paginate ( 'GET /repos/{owner}/{repo}/actions/runners' , config . githubContext ) ;
1313 const foundRunners = _ . filter ( runners , { labels : [ { name : label } ] } ) ;
14- return foundRunners . length > 0 ? foundRunners [ 0 ] : null ;
14+ return foundRunners . length > 0 ? foundRunners : null ;
1515 } catch ( error ) {
1616 return null ;
1717 }
@@ -32,22 +32,27 @@ async function getRegistrationToken() {
3232}
3333
3434async function removeRunner ( ) {
35- const runner = await getRunner ( config . input . label ) ;
35+ const runners = await getRunners ( config . input . label ) ;
3636 const octokit = github . getOctokit ( config . input . githubToken ) ;
3737
3838 // 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` ) ;
4141 return ;
4242 }
4343
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)' ) ;
5156 }
5257}
5358
@@ -58,21 +63,23 @@ async function waitForRunnerRegistered(label) {
5863 let waitSeconds = 0 ;
5964
6065 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 ) ) ;
6267 core . info ( `Checking every ${ retryIntervalSeconds } s if the GitHub self-hosted runner is registered` ) ;
6368
6469 return new Promise ( ( resolve , reject ) => {
6570 const interval = setInterval ( async ( ) => {
66- const runner = await getRunner ( label ) ;
71+ const runners = await getRunners ( label ) ;
6772
6873 if ( waitSeconds > timeoutMinutes * 60 ) {
6974 core . error ( 'GitHub self-hosted runner registration error' ) ;
7075 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+ ) ;
7279 }
7380
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` ) ;
7683 clearInterval ( interval ) ;
7784 resolve ( ) ;
7885 } else {
0 commit comments