From 4c791ddddb26d0a51dd12dc50bbcd77d46e76926 Mon Sep 17 00:00:00 2001 From: Jeff Fairley Date: Mon, 7 Jan 2019 10:59:53 -0700 Subject: [PATCH 1/8] fix: explicitly ignore generated poms rather than immediately commit Reading more on the maven-versions-plugin documentation. For myself, the only reason I was using 'commit' was to clean up the generated pomBackup files. --- .gitignore | 3 ++- lib/maven.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 3c3629e..9f0fdca 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules +/.idea/ +/node_modules/ diff --git a/lib/maven.js b/lib/maven.js index 658df73..3a45bf6 100644 --- a/lib/maven.js +++ b/lib/maven.js @@ -7,7 +7,7 @@ async function updateVersionInPomXml (logger, versionStr) { logger.log(`Updating pom.xml to version ${versionStr}`) await exec( 'mvn', - ['versions:set', 'versions:commit', `-DnewVersion=${versionStr}`] + ['versions:set', '-DgenerateBackupPoms=false', `-DnewVersion=${versionStr}`] ) } From 7dbf0ef0e12f4e8a9d658fb6baeaa77ec4eb3f12 Mon Sep 17 00:00:00 2001 From: evansiroky Date: Wed, 13 Feb 2019 15:26:45 -0800 Subject: [PATCH 2/8] fix(publish): run mvn package when skip maven deploy flag is set --- lib/definitions/errors.js | 6 ++++++ lib/maven.js | 23 +++++++++++++++++++++-- lib/publish.js | 11 ++++++++++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/lib/definitions/errors.js b/lib/definitions/errors.js index 4bb10ac..8df3e7c 100644 --- a/lib/definitions/errors.js +++ b/lib/definitions/errors.js @@ -5,6 +5,12 @@ module.exports = { message: 'Deployment to maven failed.', details: `The deployment to maven failed for an unknown reason. +Please check the logs on the CI server to see what happened.` + }), + EMAVENPACKAGE: () => ({ + message: 'Packaging with maven failed.', + details: `Maven failed package the project for an unknown reason. + Please check the logs on the CI server to see what happened.` }), ENOMAVENSETTINGS: () => ({ diff --git a/lib/maven.js b/lib/maven.js index 3a45bf6..7dc9282 100644 --- a/lib/maven.js +++ b/lib/maven.js @@ -28,7 +28,26 @@ async function deploy (logger, nextRelease) { } } +/** + * Run the maven command to package the project. `package` is a reserved word, + * so that's why the function is named this way. + */ +async function mvnPackage (logger) { + logger.log('Packaging with maven') + try { + await exec( + 'mvn', + ['package', '-DskipTests'] + ) + } catch (e) { + logger.error('failed to package with maven') + logger.error(e) + throw getError('EMAVENPACKAGE') + } +} + module.exports = { - updateVersionInPomXml, - deploy + deploy, + mvnPackage, + updateVersionInPomXml } diff --git a/lib/publish.js b/lib/publish.js index a28e43e..fa7c72b 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -1,5 +1,5 @@ const {configureGit, mergeMasterIntoDev, saveChangesToPomXml} = require('./git') -const {updateVersionInPomXml, deploy} = require('./maven') +const {deploy, mvnPackage, updateVersionInPomXml} = require('./maven') const {printVersion} = require('./util') /** @@ -12,7 +12,16 @@ module.exports = async function publish (pluginConfig, context) { printVersion(logger) if (!options.skipMavenDeploy) { + // deploy the project to maven-central await deploy(logger, nextRelease) + } else if (options.useConveyalWorkflow) { + // Although this library is being ran with instructions to skip the + // deployment to maven central, the package command is still needed in the + // Conveyal workflow. This is because sometimes the jar that is generated + // from the package command when the project is in the release state commit + // is needed by other tasks in Travis. + // See https://github.com/conveyal/datatools-server/issues/181 + await mvnPackage(logger) } // special logic to do some extra Conveyal-specific tasks From 0b879b5d012e1deb965bc248b097d107433b5d70 Mon Sep 17 00:00:00 2001 From: evansiroky Date: Mon, 18 Feb 2019 11:21:32 -0800 Subject: [PATCH 3/8] refactor: use correct grammar in an error report and add comments re skipping tests --- lib/definitions/errors.js | 2 +- lib/maven.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/definitions/errors.js b/lib/definitions/errors.js index 8df3e7c..3104914 100644 --- a/lib/definitions/errors.js +++ b/lib/definitions/errors.js @@ -9,7 +9,7 @@ Please check the logs on the CI server to see what happened.` }), EMAVENPACKAGE: () => ({ message: 'Packaging with maven failed.', - details: `Maven failed package the project for an unknown reason. + details: `Maven failed to package the project for an unknown reason. Please check the logs on the CI server to see what happened.` }), diff --git a/lib/maven.js b/lib/maven.js index 7dc9282..c49085e 100644 --- a/lib/maven.js +++ b/lib/maven.js @@ -12,7 +12,9 @@ async function updateVersionInPomXml (logger, versionStr) { } /** - * Run the maven command to deploy the project + * Run the maven command to deploy the project. The tests are skipped because it + * is assumed that they have already successfully been ran in the script part of + * the CI build. */ async function deploy (logger, nextRelease) { logger.log('Deploying version %s with maven', nextRelease.version) @@ -30,7 +32,9 @@ async function deploy (logger, nextRelease) { /** * Run the maven command to package the project. `package` is a reserved word, - * so that's why the function is named this way. + * so that's why the function is named this way. The tests are skipped because + * it is assumed that they have already successfully been ran in the script part + * of the CI build. */ async function mvnPackage (logger) { logger.log('Packaging with maven') From 47cc3a5517f3ef04b0dbfdcc16065848f68ee634 Mon Sep 17 00:00:00 2001 From: Kengo TODA Date: Thu, 21 Feb 2019 12:36:13 +0800 Subject: [PATCH 4/8] feat: support Maven wrapper script --- lib/maven.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/maven.js b/lib/maven.js index c49085e..709e573 100644 --- a/lib/maven.js +++ b/lib/maven.js @@ -1,12 +1,33 @@ +const {access, constants} = require('fs') const {exec, getError} = require('./util') +/** + * @return './mvnw' if we have wrapper in the project root, 'mvn' otherwise + */ +async function findCommand () { + return new Promise((resolve, reject) => { + access('mvnw', constants.F_OK, (err) => { + if (err) { + if (err.code === 'ENOENT') { + resolve('mvn') + } else { + reject(err) + } + } else { + resolve('./mvnw') + } + }) + }) +} + /** * Change the version number in the pom.xml file(s) */ async function updateVersionInPomXml (logger, versionStr) { logger.log(`Updating pom.xml to version ${versionStr}`) + const command = await findCommand() await exec( - 'mvn', + command, ['versions:set', '-DgenerateBackupPoms=false', `-DnewVersion=${versionStr}`] ) } @@ -19,8 +40,9 @@ async function updateVersionInPomXml (logger, versionStr) { async function deploy (logger, nextRelease) { logger.log('Deploying version %s with maven', nextRelease.version) try { + const command = await findCommand() await exec( - 'mvn', + command, ['deploy', '-DskipTests', '--settings', 'maven-settings.xml'] ) } catch (e) { @@ -39,8 +61,9 @@ async function deploy (logger, nextRelease) { async function mvnPackage (logger) { logger.log('Packaging with maven') try { + const command = await findCommand() await exec( - 'mvn', + command, ['package', '-DskipTests'] ) } catch (e) { From a1f75311b6d6ecf85debc98dd12a974cf25e1e83 Mon Sep 17 00:00:00 2001 From: Kengo TODA Date: Thu, 21 Feb 2019 17:44:28 +0800 Subject: [PATCH 5/8] docs: explain how this plugin handles maven-wrapper script --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index a3f5de3..b8c6c8a 100644 --- a/README.md +++ b/README.md @@ -121,3 +121,7 @@ before_script: Create a Github token that will be used to make commits and create releases. Add the token to your travis environment variables as either `GH_TOKEN` or `GITHUB_TOKEN`. Add the following permissions to your token: + +## Which `mvn` will be used + +This plugin uses `mvn` command in your `PATH`. If you have [maven-wrapper script](https://github.com/takari/maven-wrapper) at the project root directory, this plugin will use it instead. From 6b3f1bc2844b94edfae08d49ea4fbd1368092a74 Mon Sep 17 00:00:00 2001 From: evansiroky Date: Thu, 21 Feb 2019 08:40:38 -0800 Subject: [PATCH 6/8] docs: make some small grammar changes in Maven wrapper notes --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b8c6c8a..afba99f 100644 --- a/README.md +++ b/README.md @@ -124,4 +124,4 @@ Create a Github token that will be used to make commits and create releases. Ad ## Which `mvn` will be used -This plugin uses `mvn` command in your `PATH`. If you have [maven-wrapper script](https://github.com/takari/maven-wrapper) at the project root directory, this plugin will use it instead. +This plugin uses the `mvn` command in your `PATH`. If you have [maven-wrapper script](https://github.com/takari/maven-wrapper) at the project root directory, this plugin will use that instead. From ca2348157ce082355cbd46c1e1acfb252de9b997 Mon Sep 17 00:00:00 2001 From: evansiroky Date: Thu, 21 Feb 2019 09:15:06 -0800 Subject: [PATCH 7/8] docs(maven): add note about -DgenerateBackupPoms flag --- lib/maven.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/maven.js b/lib/maven.js index 709e573..8400341 100644 --- a/lib/maven.js +++ b/lib/maven.js @@ -21,7 +21,10 @@ async function findCommand () { } /** - * Change the version number in the pom.xml file(s) + * Change the version number in the pom.xml file(s). This also includes the + * command option to delete the backup pom files as they are not needed and can + * create unneccessary files that shouldn't be checked in to version control. + * See https://www.mojohaus.org/versions-maven-plugin/set-mojo.html#generateBackupPoms */ async function updateVersionInPomXml (logger, versionStr) { logger.log(`Updating pom.xml to version ${versionStr}`) From e5551beb4ec266bb520ae5ff155bc0d04acf8f05 Mon Sep 17 00:00:00 2001 From: evansiroky Date: Thu, 21 Feb 2019 09:19:38 -0800 Subject: [PATCH 8/8] docs: pin semantic-release to v15 in example install command --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index afba99f..50660af 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ Also, you'll want to install maven-semantic-release and semantic-release in a st ``` before_script: - - yarn global add @conveyal/maven-semantic-release semantic-release + - yarn global add @conveyal/maven-semantic-release semantic-release@15 ``` ### Step 6: Add a github token to Travis