diff --git a/lib/git.js b/lib/git.js index ed2034f..ab46dd4 100644 --- a/lib/git.js +++ b/lib/git.js @@ -35,19 +35,13 @@ async function push (origin, branch, execaOpts) { await execa('git', ['push', '--follow-tags', origin, `HEAD:${branch}`], execaOpts) } -/** - * Merges the master branch into the dev branch. The devBranch must be specified - * in the options for this to work. - */ -async function mergeMasterIntoDev (context) { +async function configureGit (context) { const {env, cwd, logger, options} = context const execaOpts = {env, cwd} - const {branch, devBranch, repositoryUrl} = options - - logger.log('Merging master branch into dev branch') // fetch all branches because Travis doesn't do it for us // code copied from https://stackoverflow.com/a/44036486/269834 + logger.log('configuring git') await execa( 'git', [ @@ -60,24 +54,41 @@ async function mergeMasterIntoDev (context) { ) // fetch everything + logger.log('fetching branches') await execa('git', ['fetch'], execaOpts) - // checkout master branch - // this is done because otherwise the commit seems to be the one just before - // the snapshot release - await execa('git', ['checkout', branch], execaOpts) + // checkout master and pull latest + logger.log('checking out release branch') + await execa('git', ['checkout', options.branch], execaOpts) - // pull changes into master + logger.log('pulling') await execa('git', ['pull'], execaOpts) +} + +/** + * Merges the master branch into the dev branch. The devBranch must be specified + * in the options for this to work. + */ +async function mergeMasterIntoDev (context) { + const {env, cwd, logger, options} = context + const execaOpts = {env, cwd} + const {branch, devBranch, repositoryUrl} = options + + logger.log('Merging master branch into dev branch') // checkout dev branch + logger.log('checking out dev branch') await execa('git', ['checkout', devBranch], execaOpts) // merge + logger.log('merging release branch into dev branch') await execa('git', ['merge', branch], execaOpts) // push + logger.log('pushing dev branch') await push(repositoryUrl, devBranch, execaOpts) + + logger.log('merge and push successful!') } /** @@ -107,9 +118,12 @@ async function saveChangesToPomXml (context, versionStr) { logger.log('pushing changes') await push(repositoryUrl, branch, execaOpts) + + logger.log('changes pushed') } module.exports = { + configureGit, mergeMasterIntoDev, saveChangesToPomXml } diff --git a/lib/publish.js b/lib/publish.js index 1a6a956..6ed2280 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -1,4 +1,4 @@ -const {mergeMasterIntoDev, saveChangesToPomXml} = require('./git') +const {configureGit, mergeMasterIntoDev, saveChangesToPomXml} = require('./git') const {updateVersionInPomXml, deploy} = require('./maven') /** @@ -13,6 +13,9 @@ module.exports = async function publish (pluginConfig, context) { // special logic to do some extra Conveyal-specific tasks if (options.useConveyalWorkflow) { + // do some extra configuration to allow pushing more than 1 commit + await configureGit(context) + // bump to snapshot version const nextSnapshotVersion = nextRelease.version.split('.').map(s => parseInt(s, 10)) nextSnapshotVersion[2] += 1