From 1fd205ad2d101f441622c9bb7e2ccb480281e0a0 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Tue, 13 Feb 2018 11:44:27 -0800 Subject: [PATCH] Additional release script options for publishing canary versions (#12219) * Additional release script options for publishing canary versions - `branch` specifies a branch other than master - `local` skips pulling from the remote branch and checking CircleCI - `tag` specifies an npm dist tag other than `latest` or `next` We may add a higher-level `canary` option in the future. * Address Brian's feedback: - Updated description of `local` option - Throws if the `latest` tag is specified for a prerelease version --- .../build-commands/check-circle-ci-status.js | 3 +++ scripts/release/build-commands/update-git.js | 20 ++++++++++++------- scripts/release/config.js | 20 +++++++++++++++++++ .../publish-commands/check-build-status.js | 5 ++++- .../publish-commands/publish-to-npm.js | 10 ++++++++-- .../publish-commands/push-git-remote.js | 3 +++ 6 files changed, 51 insertions(+), 10 deletions(-) diff --git a/scripts/release/build-commands/check-circle-ci-status.js b/scripts/release/build-commands/check-circle-ci-status.js index c2c140d764bbb..406246945f479 100644 --- a/scripts/release/build-commands/check-circle-ci-status.js +++ b/scripts/release/build-commands/check-circle-ci-status.js @@ -43,5 +43,8 @@ const check = async ({cwd}) => { }; module.exports = async params => { + if (params.local) { + return; + } return logPromise(check(params), 'Checking CircleCI status'); }; diff --git a/scripts/release/build-commands/update-git.js b/scripts/release/build-commands/update-git.js index 58255a48ca084..467916a5784e4 100644 --- a/scripts/release/build-commands/update-git.js +++ b/scripts/release/build-commands/update-git.js @@ -6,15 +6,21 @@ const chalk = require('chalk'); const {exec} = require('child-process-promise'); const {logPromise} = require('../utils'); -const update = async ({cwd}) => { - await exec('git fetch', {cwd}); - await exec('git checkout master', {cwd}); - await exec('git pull', {cwd}); +const update = async ({cwd, branch, local}) => { + if (!local) { + await exec('git fetch', {cwd}); + } + await exec(`git checkout ${branch}`, {cwd}); + if (!local) { + await exec('git pull', {cwd}); + } }; -module.exports = async ({cwd}) => { +module.exports = async params => { return logPromise( - update({cwd}), - `Updating checkout ${chalk.yellow.bold(cwd)}` + update(params), + `Updating checkout ${chalk.yellow.bold( + params.cwd + )} on branch ${chalk.yellow.bold(params.branch)}}` ); }; diff --git a/scripts/release/config.js b/scripts/release/config.js index 367cc2ef89ba8..e270967cbc00d 100644 --- a/scripts/release/config.js +++ b/scripts/release/config.js @@ -23,6 +23,26 @@ const paramDefinitions = [ alias: 'v', description: 'Semantic version number', }, + { + name: 'branch', + type: String, + alias: 'b', + description: 'Branch to build from; defaults to [bold]{master}', + defaultValue: 'master', + }, + { + name: 'local', + type: Boolean, + description: + "Don't push or pull changes from remote repo. Don't check CI status.", + }, + { + name: 'tag', + type: String, + description: + 'The npm dist tag; defaults to [bold]{latest} for a stable' + + 'release, [bold]{next} for unstable', + }, ]; module.exports = { diff --git a/scripts/release/publish-commands/check-build-status.js b/scripts/release/publish-commands/check-build-status.js index b64d7e90ab0e7..02ecf20424c19 100644 --- a/scripts/release/publish-commands/check-build-status.js +++ b/scripts/release/publish-commands/check-build-status.js @@ -7,7 +7,10 @@ const {existsSync} = require('fs'); const {readJson} = require('fs-extra'); const {join} = require('path'); -module.exports = async ({cwd, version}) => { +module.exports = async ({cwd, version, local}) => { + if (local) { + return; + } const packagePath = join( cwd, 'build', diff --git a/scripts/release/publish-commands/publish-to-npm.js b/scripts/release/publish-commands/publish-to-npm.js index 6b34e12a7c19f..429b64cbd1867 100644 --- a/scripts/release/publish-commands/publish-to-npm.js +++ b/scripts/release/publish-commands/publish-to-npm.js @@ -8,10 +8,16 @@ const {join} = require('path'); const semver = require('semver'); const {execRead, execUnlessDry, logPromise} = require('../utils'); -const push = async ({cwd, dry, packages, version}) => { +const push = async ({cwd, dry, packages, version, tag}) => { const errors = []; const isPrerelease = semver.prerelease(version); - const tag = isPrerelease ? 'next' : 'latest'; + if (tag === undefined) { + // No tag was provided. Default to `latest` for stable releases and `next` + // for prereleases + tag = isPrerelease ? 'next' : 'latest'; + } else if (tag === 'latest' && isPrerelease) { + throw new Error('The tag `latest` can only be used for stable versions.'); + } const publishProject = async project => { try { diff --git a/scripts/release/publish-commands/push-git-remote.js b/scripts/release/publish-commands/push-git-remote.js index c30d035f289d5..6d487ac546d2e 100644 --- a/scripts/release/publish-commands/push-git-remote.js +++ b/scripts/release/publish-commands/push-git-remote.js @@ -10,5 +10,8 @@ const push = async ({cwd, dry}) => { }; module.exports = async params => { + if (params.local) { + return; + } return logPromise(push(params), 'Pushing to git remote'); };