-
Notifications
You must be signed in to change notification settings - Fork 860
feat: suppress Maven transfer progress via MAVEN_ARGS by default (add show-download-progress input) #1053
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
brunoborges
wants to merge
4
commits into
main
Choose a base branch
from
feature/maven-args-no-transfer-progress
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: suppress Maven transfer progress via MAVEN_ARGS by default (add show-download-progress input) #1053
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cf3151c
feat: suppress Maven transfer progress via MAVEN_ARGS by default
brunoborges 8e27c11
Potential fix for pull request finding
brunoborges fa20c15
Update generated dist for Maven args log change
Copilot 5c0f591
Merge branch 'main' into feature/maven-args-no-transfer-progress
brunoborges File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| 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'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import * as core from '@actions/core'; | ||
| import {getBooleanInput} from './util'; | ||
| import { | ||
| INPUT_SHOW_DOWNLOAD_PROGRESS, | ||
| MAVEN_ARGS_ENV, | ||
| MAVEN_NO_TRANSFER_PROGRESS_FLAG, | ||
| MAVEN_NO_TRANSFER_PROGRESS_LONG_FLAG | ||
| } from './constants'; | ||
|
|
||
| /** | ||
| * Configures the MAVEN_ARGS environment variable so that Maven suppresses | ||
| * artifact transfer/download progress output by default, producing cleaner | ||
| * CI logs. | ||
| * | ||
| * Behavior: | ||
| * - When `show-download-progress` is `false` (the default), `-ntp` | ||
| * (`--no-transfer-progress`) is appended to any existing MAVEN_ARGS value. | ||
| * - When `show-download-progress` is `true`, MAVEN_ARGS is left untouched so | ||
| * the user's own configuration (and Maven's default progress output) is | ||
| * preserved. | ||
| * | ||
| * The change is idempotent: if MAVEN_ARGS already disables transfer progress | ||
| * (via `-ntp` or `--no-transfer-progress`) nothing is added. Any pre-existing | ||
| * MAVEN_ARGS value is preserved. | ||
| * | ||
| * MAVEN_ARGS is honored by Maven 3.9.0+ and the Maven Wrapper; older Maven | ||
| * versions ignore it, so this is a no-op there. It has no effect on non-Maven | ||
| * builds such as Gradle or sbt. | ||
| */ | ||
| export function configureMavenArgs(): void { | ||
| const showDownloadProgress = getBooleanInput( | ||
| INPUT_SHOW_DOWNLOAD_PROGRESS, | ||
| false | ||
| ); | ||
|
|
||
| if (showDownloadProgress) { | ||
| core.debug( | ||
| `${INPUT_SHOW_DOWNLOAD_PROGRESS} is true; leaving ${MAVEN_ARGS_ENV} unchanged` | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| const existingArgs = (process.env[MAVEN_ARGS_ENV] ?? '').trim(); | ||
|
|
||
| const alreadyDisabled = existingArgs | ||
| .split(/\s+/) | ||
| .some( | ||
| arg => | ||
| arg === MAVEN_NO_TRANSFER_PROGRESS_FLAG || | ||
| arg === MAVEN_NO_TRANSFER_PROGRESS_LONG_FLAG | ||
| ); | ||
|
|
||
| if (alreadyDisabled) { | ||
| core.debug( | ||
| `${MAVEN_ARGS_ENV} already disables transfer progress; leaving it unchanged` | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| const updatedArgs = existingArgs | ||
| ? `${existingArgs} ${MAVEN_NO_TRANSFER_PROGRESS_FLAG}` | ||
| : MAVEN_NO_TRANSFER_PROGRESS_FLAG; | ||
|
|
||
| core.exportVariable(MAVEN_ARGS_ENV, updatedArgs); | ||
| core.info( | ||
| `Configured ${MAVEN_ARGS_ENV} to include ${MAVEN_NO_TRANSFER_PROGRESS_FLAG} to suppress Maven transfer progress logs. ` + | ||
| `Set '${INPUT_SHOW_DOWNLOAD_PROGRESS}: true' to keep the download progress output.` | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.