diff --git a/cmds/update-rc.js b/cmds/update-rc.js new file mode 100644 index 000000000..cf05dbd33 --- /dev/null +++ b/cmds/update-rc.js @@ -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) + } +} diff --git a/src/publish-rc/index.js b/src/publish-rc/index.js index aefdd4d2b..5734a2fc7 100644 --- a/src/publish-rc/index.js +++ b/src/publish-rc/index.js @@ -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')) @@ -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 diff --git a/src/update-rc/index.js b/src/update-rc/index.js new file mode 100644 index 000000000..8ac9d91fd --- /dev/null +++ b/src/update-rc/index.js @@ -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