Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH runner auto update #679

Merged
merged 11 commits into from
Jul 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions bin/cml-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const shutdown = async (opts) => {
RUNNER_SHUTTING_DOWN = true;

const { error, cloud } = opts;
const { name, workdir = '', tfResource, noRetry } = opts;
const { name, workdir = '', tfResource, noRetry, reason } = opts;
const tfPath = workdir;

const unregisterRunner = async () => {
Expand Down Expand Up @@ -95,10 +95,14 @@ const shutdown = async (opts) => {
}
};

if (error) console.log(error);
console.log(
JSON.stringify({ level: error ? 'error' : 'info', status: 'terminated' })
JSON.stringify({
level: error ? 'error' : 'info',
status: 'terminated',
reason
})
);
if (error) console.error(error);
await sleep(RUNNER_DESTROY_DELAY);

if (cloud) {
Expand Down Expand Up @@ -273,14 +277,18 @@ const runLocal = async (opts) => {

proc.stderr.on('data', dataHandler);
proc.stdout.on('data', dataHandler);
proc.on('uncaughtException', () => shutdown(opts));
proc.on('disconnect', () => shutdown(opts));
proc.on('exit', () => shutdown(opts));
proc.on('uncaughtException', () =>
shutdown({ ...opts, reason: 'proc_uncaughtException' })
);
proc.on('disconnect', () => shutdown({ ...opts, reason: 'proc_disconnect' }));
proc.on('exit', () => shutdown({ ...opts, reason: 'proc_exit' }));

if (!noRetry) {
try {
console.log(`EC2 id ${await SpotNotifier.instanceId()}`);
SpotNotifier.on('termination', () => shutdown(opts));
SpotNotifier.on('termination', () =>
shutdown({ ...opts, reason: 'spot_termination' })
);
SpotNotifier.start();
} catch (err) {
console.log('SpotNotifier can not be started.');
Expand All @@ -290,7 +298,7 @@ const runLocal = async (opts) => {
if (parseInt(idleTimeout) !== 0) {
const watcher = setInterval(() => {
RUNNER_TIMEOUT_TIMER > idleTimeout &&
shutdown(opts) &&
shutdown({ ...opts, reason: `timeout:${idleTimeout}` }) &&
clearInterval(watcher);

if (!RUNNER_JOBS_RUNNING.length) RUNNER_TIMEOUT_TIMER++;
Expand All @@ -304,7 +312,8 @@ const runLocal = async (opts) => {
new Date().getTime() - new Date(job.date).getTime() >
GH_5_MIN_TIMEOUT
)
shutdown(opts) && clearInterval(watcher);
shutdown({ ...opts, reason: 'timeout:72h' }) &&
clearInterval(watcher);
});
}, 60 * 1000);
}
Expand All @@ -313,9 +322,9 @@ const runLocal = async (opts) => {
};

const run = async (opts) => {
process.on('SIGTERM', () => shutdown(opts));
process.on('SIGINT', () => shutdown(opts));
process.on('SIGQUIT', () => shutdown(opts));
process.on('SIGTERM', () => shutdown({ ...opts, reason: 'SIGTERM' }));
process.on('SIGINT', () => shutdown({ ...opts, reason: 'SIGINT' }));
process.on('SIGQUIT', () => shutdown({ ...opts, reason: 'SIGQUIT' }));

opts.workdir = RUNNER_PATH;
const {
Expand Down
4 changes: 3 additions & 1 deletion src/cml.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ class CML {
} else if (data.includes('Listening for Jobs')) {
log.status = 'ready';
}
return log;

const [, message] = data.split(/[A-Z]:\s/);
return { ...log, message: (message || data).replace(/\n/g, '') };
}

if (this.driver === GITLAB) {
Expand Down
13 changes: 10 additions & 3 deletions src/drivers/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const url = require('url');
const { spawn } = require('child_process');
const { resolve } = require('path');
const fs = require('fs').promises;
const fetch = require('node-fetch');

const github = require('@actions/github');
const { Octokit } = require('@octokit/rest');
Expand Down Expand Up @@ -207,9 +208,15 @@ class Github {
await fs.unlink(runnerCfg);
} catch (e) {
const arch = process.platform === 'darwin' ? 'osx-x64' : 'linux-x64';
const ver = '2.278.0';
const { tag_name: ver } = await (
await fetch(
'https://api.github.com/repos/actions/runner/releases/latest'
)
).json();
casperdcl marked this conversation as resolved.
Show resolved Hide resolved
const destination = resolve(workdir, 'actions-runner.tar.gz');
const url = `https://github.com/actions/runner/releases/download/v${ver}/actions-runner-${arch}-${ver}.tar.gz`;
const url = `https://github.com/actions/runner/releases/download/${ver}/actions-runner-${arch}-${ver.substring(
1
)}.tar.gz`;
await download({ url, path: destination });
await tar.extract({ file: destination, cwd: workdir });
await exec(`chmod -R 777 ${workdir}`);
Expand All @@ -219,7 +226,7 @@ class Github {
`${resolve(
workdir,
'config.sh'
)} --token "${await this.runnerToken()}" --url "${
)} --unattended --token "${await this.runnerToken()}" --url "${
this.repo
}" --name "${name}" --labels "${labels}" --work "${resolve(
workdir,
Expand Down