Skip to content

Commit

Permalink
Merge pull request #6 from terrestris/deploy-and-jib
Browse files Browse the repository at this point in the history
Deploy and jib
  • Loading branch information
simonseyock authored Jan 16, 2023
2 parents 04ec8c7 + b7c7adb commit d5c20ff
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ Was inspired by https://github.com/conveyal/maven-semantic-release.

* `npm i -D semantic-release @terrestris/maven-semantic-release`
* Add `@terrestris/maven-semantic-release` as a plugin (https://semantic-release.gitbook.io/semantic-release/usage/plugins)
* Configure `mavenSettingsPath` or ensure that a maven settings file exists at the expected location
* Configure `settingsPath` or ensure that a maven settings file exists at the expected location
* Make sure that the `@semantic-release/git` plugin runs after this plugin and includes the `pom.xml` if you want to use it.

## Options

* `settingsPath`: path to a maven settings file (default: `'.m2/settings.xml'`)
* `deployMethod`: either `'deploy'` or `'jib'`. This determines which mvn targets are used to deploy. `deploy` uses the `deploy` target and `jib` uses `package jib:build` (default: `'deploy'`)
* `clean`: either `true` or `false`. Whether the `clean` target will be applied before publishing. (default: `true`)
* `mavenTarget`: possible values: `deploy`, `package jib:build`, `deploy jib:build`. This determines which mvn targets are used to publish. (default: `'deploy'`)
* `updateSnapshotVersion`: either `true` or `false`. Whether a new snapshot version should be set after releasing. (default: `false`)
* `snapshotCommitMessage`: the commit message used if a new snapshot version should be created (default: `'chore: setting next snapshot version [skip ci]'`)
29 changes: 15 additions & 14 deletions src/maven.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,26 @@ async function updateSnapshotVersion(logger) {
);
}

async function deploy(logger, nextVersion, deployMethod, settingsFile) {
async function deploy(logger, nextVersion, mavenTarget, settingsPath, clean) {
logger.log('Deploying version %s with maven', nextVersion);

if (!['deploy', 'jib'].includes(deployMethod)) {
throw new Error(`unrecognized deploy method ${deployMethod}`);
const availableTargets = [
'deploy',
'package jib:build',
'deploy jib:build'
];

if (!availableTargets.includes(mavenTarget)) {
throw new Error(`unrecognized maven target ${mavenTarget}`);
}

const cleanTarget = clean ? ['clean'] : [];

try {
if (deployMethod === 'deploy') {
await exec(
'mvn',
['clean', 'deploy', '-DskipTests', '--settings', settingsFile]
);
} else if (deployMethod === 'jib') {
await exec(
'mvn',
['clean', 'package', 'jib:build', '-DskipTests', '--settings', settingsFile]
);
}
await exec(
'mvn',
[...cleanTarget, ...mavenTarget.split(' '), '-DskipTests', '--settings', settingsPath]
);
} catch (e) {
logger.error('failed to deploy to maven');
logger.error(e);
Expand Down
11 changes: 8 additions & 3 deletions src/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ module.exports = async function publish(pluginConfig, {
}) {
logger.log('publish mvn release');

const settingsFile = pluginConfig.settingsPath || '.m2/settings.xml';
const deployMethod = pluginConfig.deployMethod || 'deploy';
const settingsPath = pluginConfig.settingsPath || '.m2/settings.xml';
const mavenTarget = pluginConfig.mavenTarget || 'deploy';
const clean = pluginConfig.clean || true;

await deploy(logger, nextRelease.version, deployMethod, settingsFile);
if (!/^[\w~./]$/.test(settingsPath)) {
throw new Error('config settingsPath contains disallowed characters');
}

await deploy(logger, nextRelease.version, mavenTarget, settingsPath, clean);
};

0 comments on commit d5c20ff

Please sign in to comment.