Skip to content

Commit

Permalink
fix(exec): Don't call bash for non-docker commands (#5175)
Browse files Browse the repository at this point in the history
  • Loading branch information
zharinov authored and rarkins committed Jan 16, 2020
1 parent 4e7c938 commit ad0708d
Show file tree
Hide file tree
Showing 18 changed files with 145 additions and 127 deletions.
34 changes: 19 additions & 15 deletions lib/util/exec/index.ts
Expand Up @@ -68,7 +68,6 @@ export async function exec(
cmd: string | string[],
opts: ExecOptions = {}
): Promise<ExecResult> {
const startTime = hrtime();
const { env, extraEnv, docker } = opts;
const cwd = opts.cwd || localDir;
const childEnv = createChildEnv(env, extraEnv);
Expand All @@ -84,28 +83,33 @@ export async function exec(
cwd,
};

// TODO: simplify after callers' refactoring
const singleCommand = typeof cmd === 'string' ? cmd : cmd.join(' && ');
let pExecCommand = singleCommand.startsWith('docker run')
? singleCommand
: `bash -l -c "${singleCommand.replace(/"/g, '\\"')}"`;

let commands = typeof cmd === 'string' ? [cmd] : cmd;
if (docker) {
const dockerOptions = {
...docker,
cwd,
envVars: dockerEnvVars(extraEnv, childEnv),
};

pExecCommand = dockerCmd(pExecCommand, dockerOptions);
let singleCommand = commands.join(' && ');
singleCommand = `bash -l -c "${singleCommand.replace(/"/g, '\\"')}"`;
singleCommand = dockerCmd(singleCommand, dockerOptions);
commands = [singleCommand];
}

let res: ExecResult | null = null;
for (const pExecCommand of commands) {
const startTime = hrtime();
res = await pExec(pExecCommand, pExecOptions);
const duration = hrtime(startTime);
const seconds = Math.round(duration[0] + duration[1] / 1e9);
if (res) {
logger.debug(
{ cmd, seconds, stdout: res.stdout, stderr: res.stderr },
'exec completed'
);
}
}

const res = await pExec(pExecCommand, pExecOptions);
const duration = hrtime(startTime);
const seconds = Math.round(duration[0] + duration[1] / 1e9);
logger.debug(
{ cmd, seconds, stdout: res.stdout, stderr: res.stderr },
'exec completed'
);
return res;
}
6 changes: 3 additions & 3 deletions test/manager/bundler/__snapshots__/artifacts.spec.ts.snap
Expand Up @@ -65,7 +65,7 @@ exports[`bundler.updateArtifacts() returns null if Gemfile.lock was not changed
exports[`bundler.updateArtifacts() returns null if Gemfile.lock was not changed 2`] = `
Array [
Object {
"cmd": "bash -l -c \\"bundle lock --update \\"",
"cmd": "bundle lock --update ",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand Down Expand Up @@ -95,7 +95,7 @@ Array [
exports[`bundler.updateArtifacts() works explicit global binarySource 2`] = `
Array [
Object {
"cmd": "bash -l -c \\"bundle lock --update \\"",
"cmd": "bundle lock --update ",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand Down Expand Up @@ -125,7 +125,7 @@ Array [
exports[`bundler.updateArtifacts() works for default binarySource 2`] = `
Array [
Object {
"cmd": "bash -l -c \\"bundle lock --update \\"",
"cmd": "bundle lock --update ",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand Down
4 changes: 2 additions & 2 deletions test/manager/cargo/__snapshots__/artifacts.spec.ts.snap
Expand Up @@ -14,7 +14,7 @@ Array [
exports[`.updateArtifacts() returns null if unchanged 1`] = `
Array [
Object {
"cmd": "bash -l -c \\"cargo update --manifest-path /tmp/github/some/repo/Cargo.toml --package dep1\\"",
"cmd": "cargo update --manifest-path /tmp/github/some/repo/Cargo.toml --package dep1",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand All @@ -33,7 +33,7 @@ Array [
exports[`.updateArtifacts() returns updated Cargo.lock 1`] = `
Array [
Object {
"cmd": "bash -l -c \\"cargo update --manifest-path /tmp/github/some/repo/Cargo.toml --package dep1\\"",
"cmd": "cargo update --manifest-path /tmp/github/some/repo/Cargo.toml --package dep1",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand Down
10 changes: 5 additions & 5 deletions test/manager/composer/__snapshots__/artifacts.spec.ts.snap
Expand Up @@ -25,7 +25,7 @@ Array [
exports[`.updateArtifacts() performs lockFileMaintenance 1`] = `
Array [
Object {
"cmd": "bash -l -c \\"composer install --ignore-platform-reqs --no-ansi --no-interaction --no-scripts --no-autoloader\\"",
"cmd": "composer install --ignore-platform-reqs --no-ansi --no-interaction --no-scripts --no-autoloader",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand All @@ -45,7 +45,7 @@ Array [
exports[`.updateArtifacts() returns null if unchanged 1`] = `
Array [
Object {
"cmd": "bash -l -c \\"composer update --with-dependencies --ignore-platform-reqs --no-ansi --no-interaction --no-scripts --no-autoloader\\"",
"cmd": "composer update --with-dependencies --ignore-platform-reqs --no-ansi --no-interaction --no-scripts --no-autoloader",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand All @@ -65,7 +65,7 @@ Array [
exports[`.updateArtifacts() returns updated composer.lock 1`] = `
Array [
Object {
"cmd": "bash -l -c \\"composer update --with-dependencies --ignore-platform-reqs --no-ansi --no-interaction --no-scripts --no-autoloader\\"",
"cmd": "composer update --with-dependencies --ignore-platform-reqs --no-ansi --no-interaction --no-scripts --no-autoloader",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand Down Expand Up @@ -105,7 +105,7 @@ Array [
exports[`.updateArtifacts() supports global mode 1`] = `
Array [
Object {
"cmd": "bash -l -c \\"composer update --with-dependencies --ignore-platform-reqs --no-ansi --no-interaction --no-scripts --no-autoloader\\"",
"cmd": "composer update --with-dependencies --ignore-platform-reqs --no-ansi --no-interaction --no-scripts --no-autoloader",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand All @@ -125,7 +125,7 @@ Array [
exports[`.updateArtifacts() uses hostRules to write auth.json 1`] = `
Array [
Object {
"cmd": "bash -l -c \\"composer update --with-dependencies --ignore-platform-reqs --no-ansi --no-interaction --no-scripts --no-autoloader\\"",
"cmd": "composer update --with-dependencies --ignore-platform-reqs --no-ansi --no-interaction --no-scripts --no-autoloader",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand Down
6 changes: 3 additions & 3 deletions test/manager/gomod/__snapshots__/artifacts.spec.ts.snap
Expand Up @@ -18,7 +18,7 @@ exports[`.updateArtifacts() returns if no go.sum found 1`] = `Array []`;
exports[`.updateArtifacts() returns null if unchanged 1`] = `
Array [
Object {
"cmd": "bash -l -c \\"go get -d ./...\\"",
"cmd": "go get -d ./...",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand All @@ -38,7 +38,7 @@ Array [
exports[`.updateArtifacts() returns updated go.sum 1`] = `
Array [
Object {
"cmd": "bash -l -c \\"go get -d ./...\\"",
"cmd": "go get -d ./...",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand Down Expand Up @@ -133,7 +133,7 @@ Array [
exports[`.updateArtifacts() supports global mode 1`] = `
Array [
Object {
"cmd": "bash -l -c \\"go get -d ./...\\"",
"cmd": "go get -d ./...",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand Down
22 changes: 11 additions & 11 deletions test/manager/gradle/__snapshots__/index.spec.ts.snap
Expand Up @@ -3,7 +3,7 @@
exports[`manager/gradle extractPackageFile should configure the renovate report plugin 1`] = `
Array [
Object {
"cmd": "bash -l -c \\"./gradlew --init-script renovate-plugin.gradle renovate\\"",
"cmd": "./gradlew --init-script renovate-plugin.gradle renovate",
"options": Object {
"cwd": "localDir",
"encoding": "utf-8",
Expand All @@ -23,7 +23,7 @@ Array [
exports[`manager/gradle extractPackageFile should execute gradlew when available 1`] = `
Array [
Object {
"cmd": "bash -l -c \\"./gradlew --init-script renovate-plugin.gradle renovate\\"",
"cmd": "./gradlew --init-script renovate-plugin.gradle renovate",
"options": Object {
"cwd": "localDir",
"encoding": "utf-8",
Expand All @@ -43,7 +43,7 @@ Array [
exports[`manager/gradle extractPackageFile should return empty if renovate report is invalid 1`] = `
Array [
Object {
"cmd": "bash -l -c \\"./gradlew --init-script renovate-plugin.gradle renovate\\"",
"cmd": "./gradlew --init-script renovate-plugin.gradle renovate",
"options": Object {
"cwd": "localDir",
"encoding": "utf-8",
Expand All @@ -63,7 +63,7 @@ Array [
exports[`manager/gradle extractPackageFile should return empty if there are no dependencies 1`] = `
Array [
Object {
"cmd": "bash -l -c \\"./gradlew --init-script renovate-plugin.gradle renovate\\"",
"cmd": "./gradlew --init-script renovate-plugin.gradle renovate",
"options": Object {
"cwd": "localDir",
"encoding": "utf-8",
Expand All @@ -83,7 +83,7 @@ Array [
exports[`manager/gradle extractPackageFile should return empty if there is no dependency report 1`] = `
Array [
Object {
"cmd": "bash -l -c \\"gradle --init-script renovate-plugin.gradle renovate\\"",
"cmd": "gradle --init-script renovate-plugin.gradle renovate",
"options": Object {
"cwd": "localDir",
"encoding": "utf-8",
Expand Down Expand Up @@ -226,7 +226,7 @@ Array [
exports[`manager/gradle extractPackageFile should return gradle dependencies 2`] = `
Array [
Object {
"cmd": "bash -l -c \\"./gradlew --init-script renovate-plugin.gradle renovate\\"",
"cmd": "./gradlew --init-script renovate-plugin.gradle renovate",
"options": Object {
"cwd": "localDir",
"encoding": "utf-8",
Expand Down Expand Up @@ -310,7 +310,7 @@ Array [
exports[`manager/gradle extractPackageFile should return gradle dependencies for build.gradle in subdirectories if there is gradlew in the same directory 2`] = `
Array [
Object {
"cmd": "bash -l -c \\"./gradlew --init-script renovate-plugin.gradle renovate\\"",
"cmd": "./gradlew --init-script renovate-plugin.gradle renovate",
"options": Object {
"cwd": "localDir/foo",
"encoding": "utf-8",
Expand Down Expand Up @@ -453,7 +453,7 @@ Array [
exports[`manager/gradle extractPackageFile should return gradle.kts dependencies 2`] = `
Array [
Object {
"cmd": "bash -l -c \\"./gradlew --init-script renovate-plugin.gradle renovate\\"",
"cmd": "./gradlew --init-script renovate-plugin.gradle renovate",
"options": Object {
"cwd": "localDir",
"encoding": "utf-8",
Expand All @@ -475,7 +475,7 @@ exports[`manager/gradle extractPackageFile should return null and gradle should
exports[`manager/gradle extractPackageFile should run gradlew through \`sh\` when available but not executable 1`] = `
Array [
Object {
"cmd": "bash -l -c \\"sh gradlew --init-script renovate-plugin.gradle renovate\\"",
"cmd": "sh gradlew --init-script renovate-plugin.gradle renovate",
"options": Object {
"cwd": "localDir",
"encoding": "utf-8",
Expand All @@ -497,7 +497,7 @@ exports[`manager/gradle extractPackageFile should throw registry failure if grad
exports[`manager/gradle extractPackageFile should throw registry failure if gradle execution fails 2`] = `
Array [
Object {
"cmd": "bash -l -c \\"./gradlew --init-script renovate-plugin.gradle renovate\\"",
"cmd": "./gradlew --init-script renovate-plugin.gradle renovate",
"options": Object {
"cwd": "localDir",
"encoding": "utf-8",
Expand Down Expand Up @@ -598,7 +598,7 @@ Array [
exports[`manager/gradle extractPackageFile should use repositories only for current project 2`] = `
Array [
Object {
"cmd": "bash -l -c \\"./gradlew --init-script renovate-plugin.gradle renovate\\"",
"cmd": "./gradlew --init-script renovate-plugin.gradle renovate",
"options": Object {
"cwd": "localDir",
"encoding": "utf-8",
Expand Down
2 changes: 1 addition & 1 deletion test/manager/mix/__snapshots__/artifacts.spec.ts.snap
Expand Up @@ -14,7 +14,7 @@ Array [
exports[`.updateArtifacts() returns null if unchanged 1`] = `
Array [
Object {
"cmd": "bash -l -c \\"mix deps.update plug\\"",
"cmd": "mix deps.update plug",
"options": Object {
"cwd": "/tmp/github/some/repo",
"encoding": "utf-8",
Expand Down
6 changes: 3 additions & 3 deletions test/manager/pip_setup/__snapshots__/extract.spec.ts.snap
Expand Up @@ -5,7 +5,7 @@ exports[`lib/manager/pip_setup/extract getPythonAlias returns the python alias t
exports[`lib/manager/pip_setup/extract getPythonAlias returns the python alias to use 2`] = `
Array [
Object {
"cmd": "bash -l -c \\"python --version\\"",
"cmd": "python --version",
"options": Object {
"cwd": null,
"encoding": "utf-8",
Expand All @@ -19,7 +19,7 @@ Array [
},
},
Object {
"cmd": "bash -l -c \\"python3 --version\\"",
"cmd": "python3 --version",
"options": Object {
"cwd": null,
"encoding": "utf-8",
Expand All @@ -33,7 +33,7 @@ Array [
},
},
Object {
"cmd": "bash -l -c \\"python3.8 --version\\"",
"cmd": "python3.8 --version",
"options": Object {
"cwd": null,
"encoding": "utf-8",
Expand Down

0 comments on commit ad0708d

Please sign in to comment.