mirror of
https://github.com/renovatebot/github-action.git
synced 2025-12-17 01:12:35 +00:00
fix: use @actions/exec to execute docker child process
This commit is contained in:
parent
23c4b5f227
commit
b435cadb65
4 changed files with 47 additions and 19 deletions
13
package-lock.json
generated
13
package-lock.json
generated
|
|
@ -9,6 +9,19 @@
|
|||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.4.tgz",
|
||||
"integrity": "sha512-YJCEq8BE3CdN8+7HPZ/4DxJjk/OkZV2FFIf+DlZTC/4iBlzYCD5yjRR6eiOS5llO11zbRltIRuKAjMKaWTE6cg=="
|
||||
},
|
||||
"@actions/exec": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.0.4.tgz",
|
||||
"integrity": "sha512-4DPChWow9yc9W3WqEbUj8Nr86xkpyE29ZzWjXucHItclLbEW6jr80Zx4nqv18QL6KK65+cifiQZXvnqgTV6oHw==",
|
||||
"requires": {
|
||||
"@actions/io": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"@actions/io": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@actions/io/-/io-1.0.2.tgz",
|
||||
"integrity": "sha512-J8KuFqVPr3p6U8W93DOXlXW6zFvrQAJANdS+vw0YhusLIq+bszW8zmK2Fh1C2kDPX8FMvwIl1OUcFgvJoXLbAg=="
|
||||
},
|
||||
"@babel/code-frame": {
|
||||
"version": "7.8.3",
|
||||
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.8.3.tgz",
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@
|
|||
},
|
||||
"homepage": "https://github.com/renovatebot/github-action#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "1.2.4"
|
||||
"@actions/core": "1.2.4",
|
||||
"@actions/exec": "1.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@commitlint/cli": "8.3.5",
|
||||
|
|
|
|||
13
src/index.ts
13
src/index.ts
|
|
@ -2,11 +2,14 @@ import * as core from '@actions/core';
|
|||
import Input from './input';
|
||||
import Renovate from './renovate';
|
||||
|
||||
try {
|
||||
function run(): Promise<void> {
|
||||
const input = new Input();
|
||||
const renovate = new Renovate(input.configurationFile, input.token);
|
||||
renovate.runDockerContainer();
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
core.setFailed(error.message);
|
||||
|
||||
return renovate.runDockerContainer();
|
||||
}
|
||||
|
||||
run().catch((error) => {
|
||||
console.error(error);
|
||||
core.setFailed(error.message);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import Docker from './docker';
|
||||
import child from 'child_process';
|
||||
import { exec } from '@actions/exec';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
|
|
@ -19,24 +19,35 @@ class Renovate {
|
|||
this.docker = new Docker();
|
||||
}
|
||||
|
||||
runDockerContainer(): void {
|
||||
const commandArguments = [
|
||||
'--rm',
|
||||
`--env ${this.configFileEnv}='${this.configFileMountPath()}'`,
|
||||
`--env ${this.tokenEnv}='${this.token}'`,
|
||||
`--volume ${this.configFile}:${this.configFileMountPath()}`,
|
||||
this.docker.image(),
|
||||
];
|
||||
const command = `docker run ${commandArguments.join(' ')}`;
|
||||
// console.log(commandArguments, command);
|
||||
runDockerContainer(): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const commandArguments = [
|
||||
'--rm',
|
||||
`--env ${this.configFileEnv}=${this.configFileMountPath()}`,
|
||||
`--env ${this.tokenEnv}=${this.token}`,
|
||||
`--volume ${this.configFile}:${this.configFileMountPath()}`,
|
||||
this.docker.image(),
|
||||
];
|
||||
const command = `docker run ${commandArguments.join(' ')}`;
|
||||
|
||||
child.execSync(command, { stdio: 'inherit' });
|
||||
exec(command)
|
||||
.then((code) => {
|
||||
if (code === 0) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Error(`'docker run' failed with exit code ${code}.`));
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private validateArguments(): void {
|
||||
if (!fs.existsSync(this.configFile)) {
|
||||
throw new Error(
|
||||
`Could not locate configuration file '${this.configFile}'.`,
|
||||
`Could not locate configuration file '${this.configFile}'.`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue