Skip to content

Commit

Permalink
Merge pull request #12 from conveyal/dev
Browse files Browse the repository at this point in the history
New release
  • Loading branch information
evansiroky authored Jan 4, 2019
2 parents 260bc9b + 74b7a7e commit 6a78377
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 41 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Optionally, you can also use this enable this tool to create and push some commi

This tool is intended to automate the releases of maven projects to maven central. However, a lot of manual steps unfortunately must be taken to get your maven project setup so it can work properly. Big thanks to Nathan Fischer for detailing how to do a lot of these steps in a blog post [here](http://www.debonair.io/post/maven-cd/).

If your project merely wants to take advantage of committing version numbers and creating nice release notes on your github project, you can skip steps 1-4. In step 5, the creation of the maven artifact signing key can be skipped and the `skip-maven-deploy` flag must be set.

### Step 1: Setup an account with OSSRH

Follow [this guide](http://central.sonatype.org/pages/ossrh-guide.html#initial-setup).
Expand Down Expand Up @@ -76,6 +78,13 @@ after_success:
- semantic-release --prepare @conveyal/maven-semantic-release --publish @semantic-release/github,@conveyal/maven-semantic-release --verify-conditions @semantic-release/github,@conveyal/maven-semantic-release --verify-release @conveyal/maven-semantic-release --use-conveyal-workflow --dev-branch=dev
```

It is also possible to skip deploying to maven central, but still incrementing the version in pom.xml by setting the flag `skip-maven-deploy`. For example:

```
after_success:
- semantic-release --prepare @conveyal/maven-semantic-release --publish @semantic-release/github,@conveyal/maven-semantic-release --verify-conditions @semantic-release/github,@conveyal/maven-semantic-release --verify-release @conveyal/maven-semantic-release --use-conveyal-workflow --dev-branch=dev --skip-maven-deploy
```

#### before_install

Be sure to include the import of your signing keys. If you followed everything correctly in step 4 you should have something like the following added to your .travis.yml file:
Expand Down
2 changes: 1 addition & 1 deletion lib/maven.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {exec, getError} = require('./util')

/**
* Change the pom.xml file, commit the change and then push it to the repo
* Change the version number in the pom.xml file(s)
*/
async function updateVersionInPomXml (logger, versionStr) {
logger.log(`Updating pom.xml to version ${versionStr}`)
Expand Down
4 changes: 3 additions & 1 deletion lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ module.exports = async function publish (pluginConfig, context) {
const {logger, nextRelease, options} = context
printVersion(logger)

await deploy(logger, nextRelease)
if (!options.skipMavenDeploy) {
await deploy(logger, nextRelease)
}

// special logic to do some extra Conveyal-specific tasks
if (options.useConveyalWorkflow) {
Expand Down
20 changes: 11 additions & 9 deletions lib/verify-conditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {getError, getPomInfo, printVersion} = require('./util')
* Verify that the maven project is properly setup to allow deployment to maven central
*/
module.exports = async function verifyConditions (pluginConfig, context) {
const {logger} = context
const {logger, options} = context
printVersion(logger)

// make sure pom.xml file is good to go
Expand All @@ -16,17 +16,19 @@ module.exports = async function verifyConditions (pluginConfig, context) {
validatePomXml(pomXml)
logger.log('pom.xml validation successful')

// make sure maven-settings file exists
logger.log('validating maven-settings.xml')
const stats = await fs.stat('./maven-settings.xml')
if (!options.skipMavenDeploy) {
// make sure maven-settings file exists
logger.log('validating maven-settings.xml')
const stats = await fs.stat('./maven-settings.xml')

if (!stats) {
throw getError('ENOMAVENSETTINGS')
}
if (!stats) {
throw getError('ENOMAVENSETTINGS')
}

logger.log('validating maven-settings.xml')
logger.log('maven-settings.xml validation successful')

// HELP WANTED: do more validation of maven-settings.xml file and OSSRH login
// HELP WANTED: do more validation of maven-settings.xml file and OSSRH login
}
}

/**
Expand Down
71 changes: 41 additions & 30 deletions lib/verify-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,19 @@ module.exports = async function verifyRelease (pluginConfig, context) {

const pomXml = await getPomInfo(logger)
const pomVersion = pomXml.project.version[0]
const mavenCentralVersion = await getLatestVersionFromMavenCentral(
pomXml,
logger
)
const lastReleaseVersion = context.lastRelease.version

if (!semver.valid(mavenCentralVersion)) {
logger.log(
'WARNING: maven central version of %s is an invalid semver version',
mavenCentralVersion
)
}

// check integrity of pom version
if (!semver.valid(pomVersion)) {
logger.log(
'WARNING: pom.xml version of %s is an invalid semver version',
pomVersion
)
}

if (
semver.inc(mavenCentralVersion, 'patch') !==
semver.inc(pomVersion, 'patch')
) {
logger.log(
'WARNING: maven central version of %s differs widely from pom version of %s',
mavenCentralVersion,
pomVersion
)
}

if (lastReleaseVersion !== mavenCentralVersion) {
logger.log(
'WARNING: maven central version of %s differs from last version of %s found in git history',
mavenCentralVersion,
lastReleaseVersion
)
}

// make sure the difference in versions doesn't differ too much
// this is sort of a safegaurd against the pom.xml version straying from the
// git version too much through manual edits to pom.xml
if (semver.inc(lastReleaseVersion, 'patch') !== semver.inc(pomVersion, 'patch')) {
// only throw an error if using the Conveyal workflow
if (options.useConveyalWorkflow) {
Expand All @@ -61,6 +35,43 @@ module.exports = async function verifyRelease (pluginConfig, context) {
)
}
}

// if deploying to maven central, do some more checks of the version found in
// the pom.xml versus what is on maven central
// These checks only result in warnings as the git tags are the source of
// truth for the last version number
if (!options.skipMavenDeploy) {
const mavenCentralVersion = await getLatestVersionFromMavenCentral(
pomXml,
logger
)

if (!semver.valid(mavenCentralVersion)) {
logger.log(
'WARNING: maven central version of %s is an invalid semver version',
mavenCentralVersion
)
}

if (
semver.inc(mavenCentralVersion, 'patch') !==
semver.inc(pomVersion, 'patch')
) {
logger.log(
'WARNING: maven central version of %s differs widely from pom version of %s',
mavenCentralVersion,
pomVersion
)
}

if (lastReleaseVersion !== mavenCentralVersion) {
logger.log(
'WARNING: maven central version of %s differs from last version of %s found in git history',
mavenCentralVersion,
lastReleaseVersion
)
}
}
}

/**
Expand Down

0 comments on commit 6a78377

Please sign in to comment.