@@ -7,7 +7,6 @@ function setOutput(label) {
77 core . setOutput ( 'label' , label )
88}
99
10- // This variable should only be defined for cleanup purpose.
1110let runnerName
1211
1312async function cleanup ( ) {
@@ -30,28 +29,31 @@ async function start() {
3029 for ( let i = 1 ; i <= 3 ; i ++ ) {
3130 try {
3231 startInstanceResponse = await slab . startInstanceRequest ( )
33- runnerName = startInstanceResponse . runner_name
3432 break
3533 } catch ( error ) {
3634 core . info ( 'Retrying request now...' )
3735 }
3836
3937 if ( i === 3 ) {
4038 core . setFailed (
41- `${ provider } instance start request has failed after 3 attempts`
39+ `${ provider } instance start request has failed after 3 attempts (reason: configuration fetching has failed) `
4240 )
4341 }
4442 }
4543
46- setOutput ( startInstanceResponse . runner_name )
44+ try {
45+ const waitGithubResponse = await slab . waitForGithub (
46+ startInstanceResponse . task_id ,
47+ 'configuration_fetching'
48+ )
4749
48- core . info (
49- `${ provider } instance details: ${ JSON . stringify (
50- startInstanceResponse . details
51- ) } `
52- )
50+ runnerName = waitGithubResponse . configuration_fetching . runner_name
51+ setOutput ( runnerName )
52+
53+ core . info (
54+ `${ provider } instance details: ${ waitGithubResponse . configuration_fetching . details } `
55+ )
5356
54- try {
5557 const waitInstanceResponse = await slab . waitForInstance (
5658 startInstanceResponse . task_id ,
5759 'start'
@@ -60,10 +62,10 @@ async function start() {
6062 const instanceId = waitInstanceResponse . start . instance_id
6163 core . info ( `${ provider } instance started with ID: ${ instanceId } ` )
6264
63- await waitForRunnerRegistered ( startInstanceResponse . runner_name )
65+ await waitForRunnerRegistered ( runnerName )
6466 } catch ( error ) {
6567 core . info ( `Clean up after error, stop ${ provider } instance` )
66- await slab . stopInstanceRequest ( startInstanceResponse . runner_name )
68+ await slab . stopInstanceRequest ( runnerName )
6769 core . setFailed ( `${ provider } instance start has failed` )
6870 }
6971}
@@ -84,6 +86,22 @@ async function stop() {
8486 }
8587 }
8688
89+ try {
90+ const waitGithubResponse = await slab . waitForGithub (
91+ stopInstanceResponse . task_id ,
92+ 'runner_unregister'
93+ )
94+ const taskStatus = waitGithubResponse . runner_unregister . status . toLowerCase ( )
95+ if ( taskStatus === 'done' ) {
96+ core . info (
97+ `Runner ${ config . input . label } unregistered from GitHub successfully`
98+ )
99+ }
100+ } catch ( error ) {
101+ // Unregistration failure is not critical, so we just log it and continue.
102+ core . warning ( 'An error occurred while unregistering runner, check job logs' )
103+ }
104+
87105 await slab . waitForInstance ( stopInstanceResponse . task_id , 'stop' )
88106
89107 core . info ( 'Instance successfully stopped' )
0 commit comments