Skip to content

Commit 7cbc820

Browse files
GH runner auto update (#679)
Co-authored-by: Casper da Costa-Luis <[email protected]>
1 parent 83d44c9 commit 7cbc820

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

bin/cml-runner.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const shutdown = async (opts) => {
4141
RUNNER_SHUTTING_DOWN = true;
4242

4343
const { error, cloud } = opts;
44-
const { name, workdir = '', tfResource, noRetry } = opts;
44+
const { name, workdir = '', tfResource, noRetry, reason } = opts;
4545
const tfPath = workdir;
4646

4747
const unregisterRunner = async () => {
@@ -95,10 +95,14 @@ const shutdown = async (opts) => {
9595
}
9696
};
9797

98+
if (error) console.log(error);
9899
console.log(
99-
JSON.stringify({ level: error ? 'error' : 'info', status: 'terminated' })
100+
JSON.stringify({
101+
level: error ? 'error' : 'info',
102+
status: 'terminated',
103+
reason
104+
})
100105
);
101-
if (error) console.error(error);
102106
await sleep(RUNNER_DESTROY_DELAY);
103107

104108
if (cloud) {
@@ -273,14 +277,18 @@ const runLocal = async (opts) => {
273277

274278
proc.stderr.on('data', dataHandler);
275279
proc.stdout.on('data', dataHandler);
276-
proc.on('uncaughtException', () => shutdown(opts));
277-
proc.on('disconnect', () => shutdown(opts));
278-
proc.on('exit', () => shutdown(opts));
280+
proc.on('uncaughtException', () =>
281+
shutdown({ ...opts, reason: 'proc_uncaughtException' })
282+
);
283+
proc.on('disconnect', () => shutdown({ ...opts, reason: 'proc_disconnect' }));
284+
proc.on('exit', () => shutdown({ ...opts, reason: 'proc_exit' }));
279285

280286
if (!noRetry) {
281287
try {
282288
console.log(`EC2 id ${await SpotNotifier.instanceId()}`);
283-
SpotNotifier.on('termination', () => shutdown(opts));
289+
SpotNotifier.on('termination', () =>
290+
shutdown({ ...opts, reason: 'spot_termination' })
291+
);
284292
SpotNotifier.start();
285293
} catch (err) {
286294
console.log('SpotNotifier can not be started.');
@@ -290,7 +298,7 @@ const runLocal = async (opts) => {
290298
if (parseInt(idleTimeout) !== 0) {
291299
const watcher = setInterval(() => {
292300
RUNNER_TIMEOUT_TIMER > idleTimeout &&
293-
shutdown(opts) &&
301+
shutdown({ ...opts, reason: `timeout:${idleTimeout}` }) &&
294302
clearInterval(watcher);
295303

296304
if (!RUNNER_JOBS_RUNNING.length) RUNNER_TIMEOUT_TIMER++;
@@ -304,7 +312,8 @@ const runLocal = async (opts) => {
304312
new Date().getTime() - new Date(job.date).getTime() >
305313
GH_5_MIN_TIMEOUT
306314
)
307-
shutdown(opts) && clearInterval(watcher);
315+
shutdown({ ...opts, reason: 'timeout:72h' }) &&
316+
clearInterval(watcher);
308317
});
309318
}, 60 * 1000);
310319
}
@@ -313,9 +322,9 @@ const runLocal = async (opts) => {
313322
};
314323

315324
const run = async (opts) => {
316-
process.on('SIGTERM', () => shutdown(opts));
317-
process.on('SIGINT', () => shutdown(opts));
318-
process.on('SIGQUIT', () => shutdown(opts));
325+
process.on('SIGTERM', () => shutdown({ ...opts, reason: 'SIGTERM' }));
326+
process.on('SIGINT', () => shutdown({ ...opts, reason: 'SIGINT' }));
327+
process.on('SIGQUIT', () => shutdown({ ...opts, reason: 'SIGQUIT' }));
319328

320329
opts.workdir = RUNNER_PATH;
321330
const {

src/cml.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ class CML {
178178
} else if (data.includes('Listening for Jobs')) {
179179
log.status = 'ready';
180180
}
181-
return log;
181+
182+
const [, message] = data.split(/[A-Z]:\s/);
183+
return { ...log, message: (message || data).replace(/\n/g, '') };
182184
}
183185

184186
if (this.driver === GITLAB) {

src/drivers/github.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const url = require('url');
22
const { spawn } = require('child_process');
33
const { resolve } = require('path');
44
const fs = require('fs').promises;
5+
const fetch = require('node-fetch');
56

67
const github = require('@actions/github');
78
const { Octokit } = require('@octokit/rest');
@@ -207,9 +208,15 @@ class Github {
207208
await fs.unlink(runnerCfg);
208209
} catch (e) {
209210
const arch = process.platform === 'darwin' ? 'osx-x64' : 'linux-x64';
210-
const ver = '2.278.0';
211+
const { tag_name: ver } = await (
212+
await fetch(
213+
'https://api.github.com/repos/actions/runner/releases/latest'
214+
)
215+
).json();
211216
const destination = resolve(workdir, 'actions-runner.tar.gz');
212-
const url = `https://github.com/actions/runner/releases/download/v${ver}/actions-runner-${arch}-${ver}.tar.gz`;
217+
const url = `https://github.com/actions/runner/releases/download/${ver}/actions-runner-${arch}-${ver.substring(
218+
1
219+
)}.tar.gz`;
213220
await download({ url, path: destination });
214221
await tar.extract({ file: destination, cwd: workdir });
215222
await exec(`chmod -R 777 ${workdir}`);
@@ -219,7 +226,7 @@ class Github {
219226
`${resolve(
220227
workdir,
221228
'config.sh'
222-
)} --token "${await this.runnerToken()}" --url "${
229+
)} --unattended --token "${await this.runnerToken()}" --url "${
223230
this.repo
224231
}" --name "${name}" --labels "${labels}" --work "${resolve(
225232
workdir,

0 commit comments

Comments
 (0)