Skip to content

Commit

Permalink
Merge pull request #1 from centralnicgroup-opensource/additional-options
Browse files Browse the repository at this point in the history
feat(additional options): added support for additional parameters
  • Loading branch information
AsifNawaz-cnic authored Nov 13, 2024
2 parents 45b8903 + 7973a0a commit 42c21fa
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 23 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ Was inspired by https://github.com/conveyal/maven-semantic-release. It differs i
| snapshotCommitMessage | <code>string</code> | <code>&quot;&#x27;chore:&quot;</code> | setting next snapshot version [skip ci]' The commit message used if a new snapshot version should be created. |
| debug | <code>boolean</code> | <code>false</code> | Sets the `-X` option for all maven calls. |
| mvnw | <code>boolean</code> | <code>false</code> | Use the mvnw script instead of mvn |
| [options] | <code>string</code> | | Sets the additional options e.g. `-Pdev` |
<!-- AUTO_GENERATED_OPTIONS -->
31 changes: 25 additions & 6 deletions src/maven.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,31 @@ function settingsOption(settingsPath) {
}
}

/**
* @param {string|undefined} additionalOpts
* @returns {string[]}
* @private
*/
function setOpts(additionalOpts) {
if (additionalOpts) {
return additionalOpts.split(' ');
} else {
return [];
}
}

/**
* @param {Logger} logger
* @param {boolean} mvnw
* @param {string} versionStr
* @param {string|undefined} settingsPath
* @param {boolean} processAllModules
* @param {boolean} debug
* @param {string} options
* @returns {Promise<void>}
* @private
*/
async function updateVersion(logger, mvnw, versionStr, settingsPath, processAllModules, debug) {
async function updateVersion(logger, mvnw, versionStr, settingsPath, processAllModules, debug, options) {
logger.log(`Updating pom.xml to version ${versionStr}`);

const command = mvnw ? './mvnw' : 'mvn';
Expand All @@ -50,7 +64,8 @@ async function updateVersion(logger, mvnw, versionStr, settingsPath, processAllM
'--no-transfer-progress',
'-DgenerateBackupPoms=false',
`-DnewVersion=${versionStr}`,
...processAllModulesOption
...processAllModulesOption,
...setOpts(options)
]
);
} catch (e) {
Expand All @@ -66,10 +81,11 @@ async function updateVersion(logger, mvnw, versionStr, settingsPath, processAllM
* @param {string|undefined} settingsPath
* @param {boolean} processAllModules
* @param {boolean} debug
* @param {string} options
* @returns {Promise<void>}
* @private
*/
async function updateSnapshotVersion(logger, mvnw, settingsPath, processAllModules, debug) {
async function updateSnapshotVersion(logger, mvnw, settingsPath, processAllModules, debug, options) {
logger.log('Update pom.xml to next snapshot version');

const command = mvnw ? './mvnw' : 'mvn';
Expand All @@ -87,7 +103,8 @@ async function updateSnapshotVersion(logger, mvnw, settingsPath, processAllModul
'--no-transfer-progress',
'-DnextSnapshot=true',
'-DgenerateBackupPoms=false',
...processAllModulesOption
...processAllModulesOption,
...setOpts(options)
]
);
} catch (e) {
Expand All @@ -105,10 +122,11 @@ async function updateSnapshotVersion(logger, mvnw, settingsPath, processAllModul
* @param {string|undefined} settingsPath
* @param {boolean} clean
* @param {boolean} debug
* @param {string} options
* @returns {Promise<void>}
* @private
*/
async function deploy(logger, mvnw, nextVersion, mavenTarget, settingsPath, clean, debug) {
async function deploy(logger, mvnw, nextVersion, mavenTarget, settingsPath, clean, debug, options) {
logger.log(`Deploying version ${nextVersion} with maven`);

const command = mvnw ? './mvnw' : 'mvn';
Expand All @@ -125,7 +143,8 @@ async function deploy(logger, mvnw, nextVersion, mavenTarget, settingsPath, clea
...debugOption,
'--batch-mode',
'--no-transfer-progress',
'-DskipTests'
'-DskipTests',
...setOpts(options)
]
);
} catch (e) {
Expand Down
4 changes: 3 additions & 1 deletion src/plugin-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* @property {string} snapshotCommitMessage='chore: setting next snapshot version [skip ci]' The commit message used if a new snapshot version should be created.
* @property {boolean} debug=false Sets the `-X` option for all maven calls.
* @property {boolean} mvnw=false Use the mvnw script instead of mvn
* @property {string} opts=assign additional set of options
*/

const SemanticReleaseError = require("@semantic-release/error");
Expand All @@ -29,7 +30,8 @@ function evaluateConfig(config) {
updateSnapshotVersion: false,
snapshotCommitMessage: 'chore: setting next snapshot version [skip ci]',
debug: false,
mvnw: false
mvnw: false,
opts: ''
}, config);

if (withDefaults.settingsPath && !/^[\w~./-]*$/.test(withDefaults.settingsPath)) {
Expand Down
5 changes: 3 additions & 2 deletions src/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ module.exports = async function prepare(pluginConfig, {
settingsPath,
processAllModules,
debug,
mvnw
mvnw,
opts
} = evaluateConfig(pluginConfig);

await updateVersion(logger, mvnw, nextRelease.version, settingsPath, processAllModules, debug);
await updateVersion(logger, mvnw, nextRelease.version, settingsPath, processAllModules, debug, opts);
};
5 changes: 3 additions & 2 deletions src/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ module.exports = async function publish(pluginConfig, {
mavenTarget,
clean,
debug,
mvnw
mvnw,
opts
} = evaluateConfig(pluginConfig);

await deploy(logger, mvnw, nextRelease.version, mavenTarget, settingsPath, clean, debug);
await deploy(logger, mvnw, nextRelease.version, mavenTarget, settingsPath, clean, debug, opts);
};
5 changes: 3 additions & 2 deletions src/success.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ module.exports = async function success(pluginConfig, {
processAllModules,
debug,
settingsPath,
mvnw
mvnw,
opts
} = evaluateConfig(pluginConfig)

if (!updateSnapshotVersionOpt) {
return;
}

await updateSnapshotVersion(logger, mvnw, settingsPath, processAllModules, debug);
await updateSnapshotVersion(logger, mvnw, settingsPath, processAllModules, debug, opts);
if (!options?.repositoryUrl) {
logger.error('No git repository url configured. No files are commited.');
return;
Expand Down
20 changes: 11 additions & 9 deletions test/maven.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('maven', () => {
});

test('updateVersion with all options off', () => {
updateVersion(logger, false, '1.1.1', undefined, false, false);
updateVersion(logger, false, '1.1.1', undefined, false, false, "");
expect(exec).toBeCalledWith(
'mvn',
[
Expand All @@ -32,7 +32,7 @@ describe('maven', () => {
});

test('updateVersion with all options on', () => {
updateVersion(logger, true, '1.1.2', 'some/path', true, true);
updateVersion(logger, true, '1.1.2', 'some/path', true, true, "");
expect(exec).toBeCalledWith(
'./mvnw',
[
Expand All @@ -54,7 +54,7 @@ describe('maven', () => {
});

test('updateSnapshotVersion with all options off', () => {
updateSnapshotVersion(logger, false, undefined, false, false);
updateSnapshotVersion(logger, false, undefined, false, false, "");

expect(exec).toBeCalledWith(
'mvn',
Expand All @@ -73,7 +73,7 @@ describe('maven', () => {
});

test('updateSnapshotVersion with all options on', () => {
updateSnapshotVersion(logger, true, 'some/path', true, true);
updateSnapshotVersion(logger, true, 'some/path', true, true, "-Pdev");

expect(exec).toBeCalledWith(
'./mvnw',
Expand All @@ -86,7 +86,8 @@ describe('maven', () => {
'--no-transfer-progress',
'-DnextSnapshot=true',
'-DgenerateBackupPoms=false',
'-DprocessAllModules'
'-DprocessAllModules',
'-Pdev'
]
);

Expand All @@ -96,15 +97,15 @@ describe('maven', () => {
});

test('deploy with all options off', () => {
deploy(logger, false, '1.1.3', 'deploy', undefined, false, false);
deploy(logger, false, '1.1.3', 'deploy', undefined, false, false, "");

expect(exec).toBeCalledWith(
'mvn',
[
'deploy',
'--batch-mode',
'--no-transfer-progress',
'-DskipTests',
'-DskipTests'
]
);

Expand All @@ -114,7 +115,7 @@ describe('maven', () => {
});

test('deploy with all options on', () => {
deploy(logger, true, '1.1.4', 'deploy jib:build', 'some/path', true, true);
deploy(logger, true, '1.1.4', 'deploy jib:build', 'some/path', true, true, "-Pdev");

expect(exec).toBeCalledWith(
'./mvnw',
Expand All @@ -127,7 +128,8 @@ describe('maven', () => {
'-X',
'--batch-mode',
'--no-transfer-progress',
'-DskipTests'
'-DskipTests',
'-Pdev'
]
);

Expand Down
2 changes: 1 addition & 1 deletion test/plugin-config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const {evaluateConfig} = require("../src/plugin-config");
describe('evaluateConfig', () => {
test('will reject settings path with illegal characters', () => {
expect(() => {
evaluateConfig({ settingsPath: '; echo "test"' });
evaluateConfig({ settingsPath: '; echo "test"', opts: '-Pdev' });
}).toThrow('Config settingsPath contains disallowed characters')
});

Expand Down

0 comments on commit 42c21fa

Please sign in to comment.