Skip to content

Commit

Permalink
Merge pull request #15 from conveyal/dev
Browse files Browse the repository at this point in the history
Next release
  • Loading branch information
Landon Reed authored Mar 1, 2019
2 parents 6a78377 + e5551be commit c8f9ac0
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
/.idea/
/node_modules/
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,15 @@ 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

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:

<img src="https://raw.githubusercontent.com/conveyal/maven-semantic-release/master/github-token-example.png" />

## Which `mvn` will be used

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.
6 changes: 6 additions & 0 deletions lib/definitions/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 to package the project for an unknown reason.
Please check the logs on the CI server to see what happened.`
}),
ENOMAVENSETTINGS: () => ({
Expand Down
63 changes: 56 additions & 7 deletions lib/maven.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,51 @@
const {access, constants} = require('fs')
const {exec, getError} = require('./util')

/**
* Change the version number in the pom.xml file(s)
* @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). 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}`)
const command = await findCommand()
await exec(
'mvn',
['versions:set', 'versions:commit', `-DnewVersion=${versionStr}`]
command,
['versions:set', '-DgenerateBackupPoms=false', `-DnewVersion=${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)
try {
const command = await findCommand()
await exec(
'mvn',
command,
['deploy', '-DskipTests', '--settings', 'maven-settings.xml']
)
} catch (e) {
Expand All @@ -28,7 +55,29 @@ 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. 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')
try {
const command = await findCommand()
await exec(
command,
['package', '-DskipTests']
)
} catch (e) {
logger.error('failed to package with maven')
logger.error(e)
throw getError('EMAVENPACKAGE')
}
}

module.exports = {
updateVersionInPomXml,
deploy
deploy,
mvnPackage,
updateVersionInPomXml
}
11 changes: 10 additions & 1 deletion lib/publish.js
Original file line number Diff line number Diff line change
@@ -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')

/**
Expand All @@ -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
Expand Down

0 comments on commit c8f9ac0

Please sign in to comment.