mirror of
https://github.com/actions/setup-java.git
synced 2026-06-23 17:58:23 +01:00
Set MAVEN_ARGS to include -ntp (--no-transfer-progress) so Maven invocations in the job produce cleaner CI logs without download/transfer progress noise. Add a new optional 'show-download-progress' input (default false); set it to true to keep the progress output. The change preserves any existing MAVEN_ARGS value (the flag is appended, not overwritten) and is idempotent (it won't add the flag twice if -ntp or --no-transfer-progress is already present). Applies on all platforms; honored by Maven 3.9.0+ and the Maven Wrapper, and is a no-op for non-Maven builds. - action.yml: add show-download-progress input - src/constants.ts: add input + MAVEN_ARGS constants - src/maven-args.ts: new configureMavenArgs() - src/setup-java.ts: invoke configureMavenArgs() during setup - __tests__/maven-args.test.ts: unit tests - docs/advanced-usage.md: document the behavior and input - dist: rebuild bundled action Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
105 lines
3.0 KiB
TypeScript
105 lines
3.0 KiB
TypeScript
import * as core from '@actions/core';
|
|
|
|
import {configureMavenArgs} from '../src/maven-args';
|
|
import {
|
|
INPUT_SHOW_DOWNLOAD_PROGRESS,
|
|
MAVEN_ARGS_ENV,
|
|
MAVEN_NO_TRANSFER_PROGRESS_FLAG
|
|
} from '../src/constants';
|
|
|
|
describe('configureMavenArgs', () => {
|
|
let inputs: Record<string, string>;
|
|
let spyGetInput: jest.SpyInstance;
|
|
let spyExportVariable: jest.SpyInstance;
|
|
let spyInfo: jest.SpyInstance;
|
|
let spyDebug: jest.SpyInstance;
|
|
const originalMavenArgs = process.env[MAVEN_ARGS_ENV];
|
|
|
|
beforeEach(() => {
|
|
inputs = {};
|
|
|
|
spyGetInput = jest.spyOn(core, 'getInput');
|
|
spyGetInput.mockImplementation((name: string) => inputs[name] ?? '');
|
|
|
|
spyExportVariable = jest.spyOn(core, 'exportVariable');
|
|
spyExportVariable.mockImplementation((name: string, value: string) => {
|
|
process.env[name] = value;
|
|
});
|
|
|
|
spyInfo = jest.spyOn(core, 'info');
|
|
spyInfo.mockImplementation(() => undefined);
|
|
|
|
spyDebug = jest.spyOn(core, 'debug');
|
|
spyDebug.mockImplementation(() => undefined);
|
|
|
|
delete process.env[MAVEN_ARGS_ENV];
|
|
});
|
|
|
|
afterEach(() => {
|
|
jest.restoreAllMocks();
|
|
if (originalMavenArgs === undefined) {
|
|
delete process.env[MAVEN_ARGS_ENV];
|
|
} else {
|
|
process.env[MAVEN_ARGS_ENV] = originalMavenArgs;
|
|
}
|
|
});
|
|
|
|
it('sets MAVEN_ARGS with -ntp by default', () => {
|
|
configureMavenArgs();
|
|
|
|
expect(spyExportVariable).toHaveBeenCalledWith(
|
|
MAVEN_ARGS_ENV,
|
|
MAVEN_NO_TRANSFER_PROGRESS_FLAG
|
|
);
|
|
expect(process.env[MAVEN_ARGS_ENV]).toBe(MAVEN_NO_TRANSFER_PROGRESS_FLAG);
|
|
});
|
|
|
|
it('does not modify MAVEN_ARGS when show-download-progress is true', () => {
|
|
inputs[INPUT_SHOW_DOWNLOAD_PROGRESS] = 'true';
|
|
|
|
configureMavenArgs();
|
|
|
|
expect(spyExportVariable).not.toHaveBeenCalled();
|
|
expect(process.env[MAVEN_ARGS_ENV]).toBeUndefined();
|
|
});
|
|
|
|
it('preserves an existing MAVEN_ARGS value and appends -ntp', () => {
|
|
process.env[MAVEN_ARGS_ENV] = '-B -Dstyle.color=always';
|
|
|
|
configureMavenArgs();
|
|
|
|
expect(spyExportVariable).toHaveBeenCalledWith(
|
|
MAVEN_ARGS_ENV,
|
|
`-B -Dstyle.color=always ${MAVEN_NO_TRANSFER_PROGRESS_FLAG}`
|
|
);
|
|
});
|
|
|
|
it('does not duplicate the flag when -ntp is already present', () => {
|
|
process.env[MAVEN_ARGS_ENV] = '-B -ntp';
|
|
|
|
configureMavenArgs();
|
|
|
|
expect(spyExportVariable).not.toHaveBeenCalled();
|
|
expect(process.env[MAVEN_ARGS_ENV]).toBe('-B -ntp');
|
|
});
|
|
|
|
it('does not duplicate the flag when --no-transfer-progress is already present', () => {
|
|
process.env[MAVEN_ARGS_ENV] = '--no-transfer-progress -B';
|
|
|
|
configureMavenArgs();
|
|
|
|
expect(spyExportVariable).not.toHaveBeenCalled();
|
|
expect(process.env[MAVEN_ARGS_ENV]).toBe('--no-transfer-progress -B');
|
|
});
|
|
|
|
it('keeps the existing MAVEN_ARGS when show-download-progress is true', () => {
|
|
inputs[INPUT_SHOW_DOWNLOAD_PROGRESS] = 'true';
|
|
process.env[MAVEN_ARGS_ENV] = '-B';
|
|
|
|
configureMavenArgs();
|
|
|
|
expect(spyExportVariable).not.toHaveBeenCalled();
|
|
expect(process.env[MAVEN_ARGS_ENV]).toBe('-B');
|
|
});
|
|
});
|