Skip to content
Snippets Groups Projects
Unverified Commit 4dc6d691 authored by Johannes Feichtner's avatar Johannes Feichtner Committed by GitHub
Browse files

refactor(manager/gradle): ignore stdout of artifact updates via stdio convenience option (#23088)

parent ed182aa6
No related branches found
No related tags found
No related merge requests found
......@@ -21,20 +21,6 @@ export function gradleWrapperFileName(): string {
return './gradlew';
}
export function nullRedirectionCommand(): string {
if (
os.platform() === 'win32' &&
GlobalConfig.get('binarySource') !== 'docker'
) {
// TODO: Windows environment without docker needs to be implemented
logger.debug(
'Updating artifacts may fail due to excessive output from "gradle.bat :dependencies" command.'
);
return '';
}
return ' > /dev/null';
}
export async function prepareGradleCommand(
gradlewFile: string
): Promise<string | null> {
......
......@@ -159,9 +159,10 @@ describe('modules/manager/gradle/artifacts', () => {
},
},
{
cmd: './gradlew --console=plain -q :dependencies --update-locks org.junit.jupiter:junit-jupiter-api,org.junit.jupiter:junit-jupiter-engine > /dev/null',
cmd: './gradlew --console=plain -q :dependencies --update-locks org.junit.jupiter:junit-jupiter-api,org.junit.jupiter:junit-jupiter-engine',
options: {
cwd: '/tmp/github/some/repo',
stdio: ['pipe', 'ignore', 'pipe'],
},
},
]);
......@@ -204,6 +205,7 @@ describe('modules/manager/gradle/artifacts', () => {
cmd: 'gradlew.bat --console=plain -q :dependencies --update-locks org.junit.jupiter:junit-jupiter-api,org.junit.jupiter:junit-jupiter-engine',
options: {
cwd: '/tmp/github/some/repo',
stdio: ['pipe', 'ignore', 'pipe'],
},
},
]);
......@@ -243,9 +245,10 @@ describe('modules/manager/gradle/artifacts', () => {
},
},
{
cmd: './gradlew --console=plain -q :dependencies --update-locks org.springframework.boot:org.springframework.boot.gradle.plugin > /dev/null',
cmd: './gradlew --console=plain -q :dependencies --update-locks org.springframework.boot:org.springframework.boot.gradle.plugin',
options: {
cwd: '/tmp/github/some/repo',
stdio: ['pipe', 'ignore', 'pipe'],
},
},
]);
......@@ -293,9 +296,10 @@ describe('modules/manager/gradle/artifacts', () => {
},
},
{
cmd: './gradlew --console=plain -q :dependencies --write-locks > /dev/null',
cmd: './gradlew --console=plain -q :dependencies --write-locks',
options: {
cwd: '/tmp/github/some/repo',
stdio: ['pipe', 'ignore', 'pipe'],
},
},
]);
......@@ -355,9 +359,12 @@ describe('modules/manager/gradle/artifacts', () => {
' bash -l -c "' +
'install-tool java 16.0.1' +
' && ' +
'./gradlew --console=plain -q :dependencies --write-locks > /dev/null' +
'./gradlew --console=plain -q :dependencies --write-locks' +
'"',
options: { cwd: '/tmp/github/some/repo' },
options: {
cwd: '/tmp/github/some/repo',
stdio: ['pipe', 'ignore', 'pipe'],
},
},
]);
});
......@@ -390,8 +397,11 @@ describe('modules/manager/gradle/artifacts', () => {
},
{ cmd: 'install-tool java 16.0.1' },
{
cmd: './gradlew --console=plain -q :dependencies --write-locks > /dev/null',
options: { cwd: '/tmp/github/some/repo' },
cmd: './gradlew --console=plain -q :dependencies --write-locks',
options: {
cwd: '/tmp/github/some/repo',
stdio: ['pipe', 'ignore', 'pipe'],
},
},
]);
});
......@@ -426,9 +436,10 @@ describe('modules/manager/gradle/artifacts', () => {
},
},
{
cmd: './gradlew --console=plain -q :dependencies :sub1:dependencies :sub2:dependencies --write-locks > /dev/null',
cmd: './gradlew --console=plain -q :dependencies :sub1:dependencies :sub2:dependencies --write-locks',
options: {
cwd: '/tmp/github/some/repo',
stdio: ['pipe', 'ignore', 'pipe'],
},
},
]);
......@@ -527,8 +538,11 @@ describe('modules/manager/gradle/artifacts', () => {
},
{ cmd: 'install-tool java 11.0.1' },
{
cmd: './gradlew --console=plain -q :dependencies --write-locks > /dev/null',
options: { cwd: '/tmp/github/some/repo' },
cmd: './gradlew --console=plain -q :dependencies --write-locks',
options: {
cwd: '/tmp/github/some/repo',
stdio: ['pipe', 'ignore', 'pipe'],
},
},
]);
});
......
......@@ -14,7 +14,6 @@ import {
extractGradleVersion,
getJavaConstraint,
gradleWrapperFileName,
nullRedirectionCommand,
prepareGradleCommand,
} from '../gradle-wrapper/utils';
import type { UpdateArtifact, UpdateArtifactsResult } from '../types';
......@@ -163,16 +162,8 @@ export async function updateArtifacts({
cmd += ` --update-locks ${updatedDepNames.map(quote).join(',')}`;
}
// `./gradlew :dependencies` command can output huge text due to `:dependencies`
// that renders dependency graphs. Given the output can exceed `ExecOptions.maxBuffer` size,
// drop stdout from the command.
//
// Note: Windows without docker doesn't supported this yet
const nullRedirection = nullRedirectionCommand();
cmd += nullRedirection;
await writeLocalFile(packageFileName, newPackageFileContent);
await exec(cmd, execOptions);
await exec(cmd, { ...execOptions, ignoreStdout: true });
const res = await getUpdatedLockfiles(oldLockFileContentMap);
logger.debug('Returning updated Gradle dependency lockfiles');
......
......@@ -3,6 +3,8 @@ It does not call `gradle` directly in order to extract a list of dependencies.
### Updating lockfiles
Updating lockfiles is done with `./gradlew :dependencies --wirte/update-locks` command.
This command can output excessive text to the console.
While running the command, the output to stdout is dropped when you run Renovate on most platforms other than Windows.
The gradle manager supports gradle lock files in `.lockfile` artifacts, as well as lock files used by the [gradle-consistent-versions](https://github.com/palantir/gradle-consistent-versions) plugin.
During [lock file maintenance](https://docs.renovatebot.com/configuration-options/#lockfilemaintenance), renovate calls `./gradlew :dependencies --write-locks` on the root project and subprojects.
For regular dependency updates, renovate automatically updates lock state entries via the `--update-locks` command line flag.
As the output of these commands can be very large, any text other than errors (in `stderr`) is discarded.
......@@ -710,6 +710,29 @@ describe('util/exec/index', () => {
},
],
[
'Discarded stdout if ignoreStdout=true',
{
processEnv,
inCmd,
inOpts: {
ignoreStdout: true,
cwdFile: '/somefile',
},
outCmd,
outOpts: [
{
cwd,
encoding,
env: envMock.basic,
timeout: 900000,
maxBuffer: 10485760,
stdio: ['pipe', 'ignore', 'pipe'],
},
],
},
],
[
'Hermit',
{
......
......@@ -87,6 +87,11 @@ function getRawExecOptions(opts: ExecOptions): RawExecOptions {
// Set default max buffer size to 10MB
rawExecOptions.maxBuffer = rawExecOptions.maxBuffer ?? 10 * 1024 * 1024;
if (opts.ignoreStdout) {
rawExecOptions.stdio = ['pipe', 'ignore', 'pipe'];
}
return rawExecOptions;
}
......
......@@ -49,6 +49,7 @@ export interface ExecOptions {
docker?: Opt<DockerOptions>;
toolConstraints?: Opt<ToolConstraint[]>;
preCommands?: Opt<string[]>;
ignoreStdout?: boolean;
// Following are pass-through to child process
maxBuffer?: number | undefined;
timeout?: number | undefined;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment