diff --git a/.github/PROCESS.md b/.github/PROCESS.md index 515cac91cc..1bba4c4107 100644 --- a/.github/PROCESS.md +++ b/.github/PROCESS.md @@ -240,6 +240,8 @@ Hotfixes bypass `master` and should only be used for urgent fixes that can't wai - For major or minor releases, ensure that the version number has an associated title (for example: `4.5.0 Boron`) - Commit these changes with the version number as the message, e.g. `git commit -m "4.5.0"` +1. *(Optional)* Run `npm run release -- --dry-run` to run the release without publishing and verify the version. + 1. Run `npm run release` 1. Click **Merge pull request**. Use the dropdown to select this option if necessary. diff --git a/.scripts/common.js b/.scripts/common.js index 03996cac99..7e07d80d2a 100644 --- a/.scripts/common.js +++ b/.scripts/common.js @@ -1,6 +1,7 @@ const fs = require('fs-extra'); const path = require('path'); const execa = require('execa'); +const inquirer = require('inquirer'); const Listr = require('listr'); const semver = require('semver'); const tc = require('turbocolor'); @@ -34,6 +35,34 @@ function projectPath(project) { return path.join(rootDir, project); } +async function askTag() { + const prompts = [ + { + type: 'list', + name: 'tag', + message: 'Select npm tag or specify a new tag', + choices: ['latest', 'next'] + .concat([ + new inquirer.Separator(), + { + name: 'Other (specify)', + value: null + } + ]) + }, + { + type: 'confirm', + name: 'confirm', + message: answers => { + return `Will publish to ${tc.cyan(answers.tag)}. Continue?`; + } + } + ]; + + const { tag, confirm } = await inquirer.prompt(prompts); + return { tag, confirm }; +} + function checkGit(tasks) { tasks.push( { @@ -300,6 +329,7 @@ function copyCDNLoader(tasks, version) { module.exports = { checkTestDist, checkGit, + askTag, isValidVersion, isVersionGreater, copyCDNLoader, diff --git a/.scripts/prepare.js b/.scripts/prepare.js index 0c47bd4864..0d37e4bbce 100644 --- a/.scripts/prepare.js +++ b/.scripts/prepare.js @@ -17,9 +17,13 @@ async function main() { throw new Error('env.GH_TOKEN is undefined'); } - const version = await askVersion(); + const { version, confirm } = await askVersion(); const install = process.argv.indexOf('--no-install') < 0; + if (!confirm) { + return; + } + // compile and verify packages await preparePackages(common.packages, version, install); @@ -85,8 +89,8 @@ async function askVersion() { } ]; - const {version} = await inquirer.prompt(prompts); - return version; + const { version, confirm } = await inquirer.prompt(prompts); + return { version, confirm }; } diff --git a/.scripts/release.js b/.scripts/release.js index 97c69b66fa..4c49149518 100644 --- a/.scripts/release.js +++ b/.scripts/release.js @@ -13,6 +13,8 @@ const fs = require('fs-extra'); async function main() { try { + const dryRun = process.argv.indexOf('--dry-run') > -1; + if (!process.env.GH_TOKEN) { throw new Error('env.GH_TOKEN is undefined'); } @@ -26,15 +28,31 @@ async function main() { // repo must be clean common.checkGit(tasks); - // publish each package in NPM - common.publishPackages(tasks, common.packages, version); + const { tag, confirm } = await common.askTag(); - // push tag to git remote - publishGit(tasks, version, changelog); + if (!confirm) { + return; + } + + if(!dryRun) { + // publish each package in NPM + common.publishPackages(tasks, common.packages, version, tag); + + // push tag to git remote + publishGit(tasks, version, changelog); + } const listr = new Listr(tasks); await listr.run(); - console.log(`\nionic ${version} published!! 🎉\n`); + + // Dry run doesn't publish to npm or git + if (dryRun) { + console.log(` + \n${tc.yellow('Did not publish. Remove the "--dry-run" flag to publish:')}\n${tc.green(version)} to ${tc.cyan(tag)}\n + `); + } else { + console.log(`\nionic ${version} published to ${tag}!! 🎉\n`); + } } catch (err) { console.log('\n', tc.red(err), '\n');