Browse Source

Add the publish step to the release and clean up lerna handling

Steven Silvester 6 years ago
parent
commit
eeb93bdf13

+ 0 - 6
RELEASE.md

@@ -85,12 +85,6 @@ functionality.
 
 - Run `jlpm bumpversion release` to switch to an `rc` version
   (run `jlpm bumpversion build` to increment `rc` versions).
-- Prep the static assets for release:
-
-```bash
-jlpm run build:update
-```
-
 - Commit and tag and push the tag
 - Create the Python release artifacts:
 

+ 44 - 29
buildutils/src/bumpversion.ts

@@ -4,57 +4,72 @@
 |----------------------------------------------------------------------------*/
 
 import commander from 'commander';
+import { prepublish, publish } from './publish';
 import * as utils from './utils';
 
 // Specify the program signature.
 commander
+  .description('Update the version and publish')
   .option('--dry-run', 'Dry run')
-  .arguments('<version>')
-  .action((v: any, opts: any) => {
+  .arguments('<spec>')
+  .action((spec: any, opts: any) => {
+    // Get the previous version.
+    const prev = utils.getVersion();
+
     // Make sure we have a valid version spec.
-    const options = ['major', 'minor', 'patch', 'release', 'build'];
-    if (options.indexOf(v) === -1) {
-      console.error('Version type must be one of:', options);
-      process.exit(1);
+    const options = ['major', 'minor', 'release', 'build'];
+    if (options.indexOf(spec) === -1) {
+      throw new Error(`Version spec must be one of: ${options}`);
     }
-
-    // Make sure we start in a clean git state.
-    console.log('***', utils.checkStatus('git diff --quiet'));
-    if (utils.checkStatus('git diff --quiet') !== 0) {
-      throw new Error('Must be in a clean git state');
+    if (
+      prev.indexOf('a') === 0 &&
+      prev.indexOf('rc') === 0 &&
+      spec === 'release'
+    ) {
+      throw new Error('Use "major" or "minor" to switch back to alpha release');
+    }
+    if (
+      prev.indexOf('a') === 0 &&
+      prev.indexOf('rc') === 0 &&
+      spec === 'build'
+    ) {
+      throw new Error('Cannot increment a build on a final release');
     }
 
-    // Ensure bump2version is installed (active fork of bumpversion).
+    // Ensure bump2version is installed (active fork of bumpversion)
     utils.run('python -m pip install bump2version');
 
     // Handle dry runs.
     if (opts.dryRun) {
-      utils.run(`bumpversion --dry-run --verbose ${v}`);
+      utils.run(`bumpversion --dry-run --verbose ${spec}`);
       return;
     }
 
-    // For major or minor bumps, bump all of the JS packages as well to alpha
-    if (v === 'major' || v === 'minor') {
-      let cmd = `lerna version preminor --yes --no-git-tag-version --force-publish=* -m \"Prerelease version\" --no-push`;
-      utils.run(cmd);
-      utils.run('git commit -a -m "bump packages to preminor"');
-    }
+    prepublish();
 
     // Bump the version.
-    utils.run(`bumpversion ${v}`);
+    utils.run(`bumpversion ${spec}`);
 
-    // For patch releases, skip alpha and rc
-    if (v === 'patch') {
-      utils.run('bumpversion release');
-      utils.run('bumpversion release');
+    // Determine the version spec to use for lerna.
+    let lernaVersion = 'preminor';
+    if (spec === 'build') {
+      lernaVersion = 'prerelease';
+      // a -> rc
+    } else if (spec === 'release' && prev.indexOf('a') !== 0) {
+      lernaVersion = 'prerelease --pre-id=rc';
+      // rc -> final
+    } else if (spec === 'release' && prev.indexOf('rc') !== 0) {
+      lernaVersion = 'patch';
     }
+    let cmd = `lerna version -m \"New version\" --no-push ${lernaVersion}`;
+    utils.run(cmd);
 
-    // Get the current version from dev_mode/package.json
-    let cmd = 'python setup.py --version';
-    let version = utils.run(cmd, { stdio: 'pipe' });
+    // Our work is done if this is a major or minor bump.
+    if (spec in ['major', 'minor']) {
+      return;
+    }
 
-    utils.run('node buildutils/lib/update-core-mode.js');
-    utils.run(`git tag v${version}`);
+    publish();
   });
 
 commander.parse(process.argv);

+ 11 - 3
buildutils/src/patch-release.ts

@@ -6,6 +6,7 @@
 import * as fs from 'fs-extra';
 import * as path from 'path';
 import * as utils from './utils';
+import { publish, prepublish } from './publish';
 
 // Make sure we have required command line arguments.
 if (process.argv.length < 3) {
@@ -14,6 +15,8 @@ if (process.argv.length < 3) {
   process.exit(1);
 }
 
+prepublish();
+
 // Extract the desired package target(s).
 process.argv.slice(2).forEach(target => {
   let packagePath = path.resolve(path.join('packages', target));
@@ -40,6 +43,11 @@ process.argv.slice(2).forEach(target => {
 });
 
 // Patch the python version
-utils.run('jlpm bumpversion patch');
-
-console.log('\n\nFinished, make sure to push the commit(s) and tag(s).');
+// Ensure bump2version is installed (active fork of bumpversion)
+utils.run('python -m pip install bump2version');
+utils.run('bumpversion patch'); // switches to alpha
+utils.run('bumpversion release'); // switches to rc
+utils.run('bumpversion release'); // switches to final.
+
+// Publish the python package.
+publish();

+ 0 - 19
buildutils/src/prepublish.ts

@@ -1,19 +0,0 @@
-/*-----------------------------------------------------------------------------
-| Copyright (c) Jupyter Development Team.
-| Distributed under the terms of the Modified BSD License.
-|----------------------------------------------------------------------------*/
-import * as utils from './utils';
-
-// Make sure we start in a clean git state.
-if (utils.checkStatus('git diff --quiet') !== 0) {
-  throw new Error('Must be in a clean git state');
-}
-
-// Make sure we are logged in.
-if (utils.checkStatus('npm whomai') !== 0) {
-  throw new Error('Must be logged into npm');
-}
-
-utils.run('npm run clean:slate');
-utils.run('jlpm run build:packages');
-utils.run('jlpm integrity');

+ 53 - 0
buildutils/src/publish.ts

@@ -0,0 +1,53 @@
+/*-----------------------------------------------------------------------------
+| Copyright (c) Jupyter Development Team.
+| Distributed under the terms of the Modified BSD License.
+|----------------------------------------------------------------------------*/
+
+import * as utils from './utils';
+
+/**
+ * Publish
+ */
+export function publish() {
+  const curr = utils.getVersion();
+
+  // Publish JS to the appropriate tag.
+  if (curr.indexOf('rc') === -1 && curr.indexOf('a') === -1) {
+    utils.run('lerna publish from-git -m "Publish"');
+  } else {
+    utils.run('lerna publish from-git --npm-tag=next -m "Publish"');
+  }
+
+  // Update the core mode.
+  utils.run('node buildutils/lib/update-core-mode.js');
+
+  // Create a git tag and commit.
+  utils.run(`git tag v${curr}`);
+  utils.run(`git commit -am "Publish ${curr}"`);
+
+  // Make the Python release.
+  utils.run('rm -rf dist build');
+  utils.run('python setup.py sdist');
+  utils.run('python setup.py bdist_wheel --universal');
+  utils.run('python -m pip install twine');
+  utils.run('twine upload dist/*');
+}
+
+/**
+ * Prepublish.
+ */
+export function prepublish() {
+  // Make sure we start in a clean git state.
+  if (utils.checkStatus('git diff --quiet') !== 0) {
+    throw new Error('Must be in a clean git state');
+  }
+
+  // Make sure we are logged in.
+  if (utils.checkStatus('npm whomai') !== 0) {
+    throw new Error('Must be logged into npm');
+  }
+
+  utils.run('npm run clean:slate');
+  utils.run('jlpm run build:packages');
+  utils.run('jlpm integrity');
+}

+ 9 - 0
buildutils/src/utils.ts

@@ -98,6 +98,15 @@ export function checkStatus(cmd: string) {
   return data.status;
 }
 
+/**
+ * Get the current version of JupyterLab
+ */
+export function getVersion() {
+  let filePath = path.resolve(path.join('.', 'dev_mode', 'package.json'));
+  let data = readJSONFile(filePath);
+  return data.jupyterlab.version;
+}
+
 /**
  * Run a command with terminal output.
  *

+ 1 - 13
package.json

@@ -1,7 +1,6 @@
 {
   "private": true,
   "scripts": {
-    "pre-publish": "jlpm && cd buildutils && npm run build && cd .. && node buildutils/lib/prepublish.js",
     "add:sibling": "node buildutils/lib/add-sibling.js",
     "analyze": "jlpm run analyze:dev",
     "analyze:dev": "cd dev_mode && jlpm run build --analyze && opn static/stats.html",
@@ -15,7 +14,6 @@
     "build:src": "lerna run build --scope \"@jupyterlab/!(test-|example-|application-top)*\" --concurrency 1",
     "build:test": "lerna run build --scope \"@jupyterlab/test-*\" --concurrency 1",
     "build:testutils": "cd testutils && jlpm run build",
-    "build:update": "jlpm run pre-publish && node buildutils/lib/update-core-mode.js",
     "build:utils": "cd buildutils && jlpm run build",
     "bumpversion": "node buildutils/lib/bumpversion.js",
     "clean": "jlpm run clean:dev && jlpm run clean:packages",
@@ -39,11 +37,7 @@
     "integrity": "node buildutils/lib/ensure-repo.js",
     "lint": "jlpm && jlpm run prettier && jlpm run eslint && jlpm run tslint",
     "lint:check": "jlpm run prettier:check && jlpm run eslint:check && jlpm run tslint:check",
-    "patch:release": "jlpm run pre-publish && node buildutils/lib/patch-release.js",
-    "publish:all": "jlpm run pre-publish && lerna publish --force-publish=* -m \"Publish\"",
-    "publish:next": "jlpm run pre-publish && lerna publish --npm-tag=next -m \"Publish with 'next' tag\"",
-    "publish:next:all": "jlpm run pre-publish && lerna publish --npm-tag=next --force-publish=* -m \"Publish with 'next' tag\"",
-    "publish:next:from-git": "jlpm run pre-publish && lerna publish from-git --npm-tag=next",
+    "patch:release": "node buildutils/lib/patch-release.js",
     "remove:dependency": "node buildutils/lib/remove-dependency.js",
     "remove:package": "node buildutils/lib/remove-package.js",
     "remove:sibling": "node buildutils/lib/remove-package.js",
@@ -57,12 +51,6 @@
     "prettier": "prettier --write '**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}'",
     "prettier:check": "prettier --list-different '**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}'",
     "update:dependency": "node buildutils/lib/update-dependency.js --lerna",
-    "update:dist-tag": "node buildutils/lib/update-dist-tag.js --lerna",
-    "update:local": "node buildutils/lib/update-local.js",
-    "version:choose": "jlpm run pre-publish && lerna version -m \"New version\" --no-push",
-    "version:choose:all": "jlpm run pre-publish && lerna version --force-publish=* -m \"New version\" --no-push",
-    "version:prerelease": "jlpm run pre-publish && lerna version prerelease -m \"Prerelease version\" --no-push",
-    "version:prerelease:all": "jlpm run pre-publish && lerna version prerelease --force-publish=* -m \"Prerelease version\" --no-push",
     "watch": "python scripts/watch_dev.py",
     "watch:main": "jlpm run watch",
     "watch:packages": "python scripts/watch_packages.py"