Skip to content

Commit

Permalink
feat: adds command to update release candidates (#421)
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain authored and hugomrdias committed Sep 16, 2019
1 parent 8d186af commit 36de3ff
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
27 changes: 27 additions & 0 deletions cmds/update-rc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict'

module.exports = {
command: 'update-rc [branch]',
desc: 'Update a release candidate',
builder: {
branch: {
describe: 'Where the latest release branch is',
type: 'string'
},
distTag: {
describe: 'The dist tag to publish the rc as',
type: 'string',
default: 'next'
},
preId: {
describe: 'What to call the rc',
type: 'string',
default: 'rc'
}
},
handler (argv) {
const publishRc = require('../src/update-rc')
const onError = require('../src/error-handler')
publishRc(argv).catch(onError)
}
}
11 changes: 10 additions & 1 deletion src/publish-rc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ async function publishRc (opts) {
console.info(`Checking out branch ${opts.branch}`) // eslint-disable-line no-console
await exec('git', ['checkout', opts.branch])

console.info(`Removing dependencies`) // eslint-disable-line no-console
await exec('rm', ['-rf', 'node_modules', 'package-lock.json'])

console.info(`Installing dependencies`) // eslint-disable-line no-console
await exec('npm', ['ci'])

console.info('Reading version number') // eslint-disable-line no-console
const pkg = require(path.join(process.cwd(), 'package.json'))

Expand Down Expand Up @@ -58,8 +64,11 @@ async function publishRc (opts) {
publish: true,
ghrelease: true,
docs: true,
ghtoken: process.env.AEGIR_GHTOKEN
ghtoken: opts.ghtoken || process.env.AEGIR_GHTOKEN
})

console.info(`Updating branch ${opts.branch}`) // eslint-disable-line no-console
await exec('git', ['push'])
}

module.exports = publishRc
52 changes: 52 additions & 0 deletions src/update-rc/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict'

const {
exec
} = require('../utils')
const release = require('../release')

async function updateRc (opts) {
try {
console.info(`Removing local copy of ${opts.branch}`) // eslint-disable-line no-console
await exec('git', ['branch', '-D', opts.branch])
} catch (err) {
if (!err.message.includes(`branch '${opts.branch}' not found`)) {
throw err
}
}

console.info('Fetching repo history') // eslint-disable-line no-console
await exec('git', ['fetch'])

console.info(`Checking out branch ${opts.branch}`) // eslint-disable-line no-console
await exec('git', ['checkout', opts.branch])

console.info(`Removing dependencies`) // eslint-disable-line no-console
await exec('rm', ['-rf', 'node_modules', 'package-lock.json'])

console.info(`Installing dependencies`) // eslint-disable-line no-console
await exec('npm', ['ci'])

console.info('Updating', opts.preId) // eslint-disable-line no-console
await release({
type: `prerelease`,
preid: opts.preId,
'dist-tag': opts.distTag,
build: false,
test: false,
lint: false,
docsFormats: ['html'],
contributors: true,
bump: true,
changelog: true,
publish: true,
ghrelease: true,
docs: true,
ghtoken: opts.ghtoken || process.env.AEGIR_GHTOKEN
})

console.info(`Updating branch ${opts.branch}`) // eslint-disable-line no-console
await exec('git', ['push'])
}

module.exports = updateRc

0 comments on commit 36de3ff

Please sign in to comment.