diff --git a/buildutils/src/release-bump.ts b/buildutils/src/release-bump.ts new file mode 100644 index 000000000..4cad823b9 --- /dev/null +++ b/buildutils/src/release-bump.ts @@ -0,0 +1,109 @@ +/* ----------------------------------------------------------------------------- +| Copyright (c) Jupyter Development Team. +| Distributed under the terms of the Modified BSD License. +|----------------------------------------------------------------------------*/ + +/** + * Inspired by: https://github.com/jupyterlab/jupyterlab/blob/master/buildutils/src/bumpversion.ts + */ + +import * as utils from '@jupyterlab/buildutils'; + +import commander from 'commander'; + +import { postbump } from './utils'; + +// Specify the program signature. +commander + .description('Update the version') + .option('--dry-run', 'Dry run') + .option('--force', 'Force the upgrade') + .arguments('') + .action((spec: any, opts: any) => { + // Get the previous version. + const prev = utils.getPythonVersion(); + + // Make sure we have a valid version spec. + const options = ['major', 'minor', 'release', 'build']; + if (options.indexOf(spec) === -1) { + throw new Error(`Version spec must be one of: ${options}`); + } + if ( + prev.indexOf('a') === -1 && + prev.indexOf('b') === -1 && + prev.indexOf('rc') === -1 && + spec === 'release' + ) { + throw new Error('Use "major" or "minor" to switch back to alpha release'); + } + if ( + prev.indexOf('a') === -1 && + prev.indexOf('b') === -1 && + prev.indexOf('rc') === -1 && + spec === 'build' + ) { + throw new Error('Cannot increment a build on a final release'); + } + + // Run pre-bump script. + utils.prebump(); + + // Handle dry runs. + if (opts.dryRun) { + utils.run(`bumpversion --dry-run --verbose ${spec}`); + return; + } + + // If this is a major release during the alpha cycle, bump + // just the Python version. + if (prev.indexOf('a') !== -1 && spec === 'major') { + // Bump the version. + utils.run(`bumpversion ${spec}`); + + // Run the post-bump script. + utils.postbump(); + + return; + } + + // Determine the version spec to use for lerna. + let lernaVersion = 'preminor'; + if (spec === 'build') { + lernaVersion = 'prerelease'; + // a -> b + } else if (spec === 'release' && prev.indexOf('a') !== -1) { + lernaVersion = 'prerelease --preid=beta'; + // b -> rc + } else if (spec === 'release' && prev.indexOf('b') !== -1) { + lernaVersion = 'prerelease --preid=rc'; + // rc -> final + } else if (spec === 'release' && prev.indexOf('rc') !== -1) { + lernaVersion = 'patch'; + } + if (lernaVersion === 'preminor') { + lernaVersion += ' --preid=alpha'; + } + + let cmd = `jlpm run lerna version --force-publish --no-push --no-git-tag-version ${lernaVersion}`; + if (opts.force) { + cmd += ' --yes'; + } + // For a preminor release, we bump 10 minor versions so that we do + // not conflict with versions during minor releases of the top + // level package. + if (lernaVersion === 'preminor') { + for (let i = 0; i < 10; i++) { + utils.run(cmd); + } + } else { + utils.run(cmd); + } + + // Bump the version. + utils.run(`bumpversion ${spec} --allow-dirty`); + + // Run the post-bump script. + postbump(); + }); + +commander.parse(process.argv); diff --git a/buildutils/src/release-patch.ts b/buildutils/src/release-patch.ts index a764d1c1c..682d04602 100644 --- a/buildutils/src/release-patch.ts +++ b/buildutils/src/release-patch.ts @@ -3,16 +3,15 @@ | Distributed under the terms of the Modified BSD License. |----------------------------------------------------------------------------*/ -import commander from 'commander'; +/** + * Inspired by: https://github.com/jupyterlab/jupyterlab/blob/master/buildutils/src/patch-release.ts + */ import * as utils from '@jupyterlab/buildutils'; -function postbump() { - // Commit the changes - const newPyVersion = utils.getPythonVersion(); - // Commit changes. - utils.run(`git commit -am "Release ${newPyVersion}"`); -} +import commander from 'commander'; + +import { postbump } from './utils'; // Specify the program signature. commander diff --git a/buildutils/src/utils.ts b/buildutils/src/utils.ts new file mode 100644 index 000000000..40c443deb --- /dev/null +++ b/buildutils/src/utils.ts @@ -0,0 +1,8 @@ +import { getPythonVersion, run } from '@jupyterlab/buildutils'; + +export function postbump(): void { + // Commit the changes + const newPyVersion = getPythonVersion(); + // Commit changes. + run(`git commit -am "Release ${newPyVersion}"`); +}