fix: use async/await in the runner

This commit is contained in:
Jeroen de Bruijn 2020-05-04 08:07:16 +02:00
parent cd7e423dd8
commit e300660370
No known key found for this signature in database
GPG key ID: 3A2677A1DF38FF9F
2 changed files with 14 additions and 13 deletions

View file

@ -2,14 +2,16 @@ import * as core from '@actions/core';
import Input from './input'; import Input from './input';
import Renovate from './renovate'; import Renovate from './renovate';
function run(): Promise<void> { async function run(): Promise<void> {
const input = new Input(); try {
const renovate = new Renovate(input.configurationFile, input.token); const input = new Input();
const renovate = new Renovate(input.configurationFile, input.token);
return renovate.runDockerContainer(); await renovate.runDockerContainer();
} catch (error) {
console.error(error);
core.setFailed(error.message);
}
} }
run().catch((error) => { run();
console.error(error);
core.setFailed(error.message);
});

View file

@ -19,18 +19,17 @@ class Renovate {
this.docker = new Docker(); this.docker = new Docker();
} }
runDockerContainer(): Promise<void> { async runDockerContainer(): Promise<void> {
const commandArguments = [ const commandArguments = [
'run',
'--rm', '--rm',
`--env ${this.configFileEnv}=${this.configFileMountPath()}`, `--env ${this.configFileEnv}=${this.configFileMountPath()}`,
`--env ${this.tokenEnv}=${this.token}`, `--env ${this.tokenEnv}=${this.token}`,
`--volume ${this.configFile}:${this.configFileMountPath()}`, `--volume ${this.configFile}:${this.configFileMountPath()}`,
this.docker.image(), this.docker.image(),
]; ];
const command = `docker`; const command = `docker run ${commandArguments.join(' ')}`;
const code = exec(command, commandArguments); const code = await exec(command);
if (code !== 0) { if (code !== 0) {
new Error(`'docker run' failed with exit code ${code}.`); new Error(`'docker run' failed with exit code ${code}.`);
} }