Skip to content

Improve support for semver prerelease identifiers when publishing - #960

Merged
evocateur merged 19 commits into
lerna:masterfrom
shawnbot:canary-cd-version
Aug 23, 2017
Merged

evocateur merged 19 commits into
lerna:masterfrom
shawnbot:canary-cd-version

Conversation

@shawnbot

@shawnbot shawnbot commented Aug 6, 2017 •

Copy link
Copy Markdown
Contributor

This updates the lerna publish command to accept any semver-compatible release type for --cd-version and allows you to use --canary and --cd-version together. It fixes #915 and #567 (and #936), and conflicts with #958 😬 .

Description

Here are the changes to the publish command:

  1. Any semver-compatible release type is for the value of --cd-version, rather than whitelisting "major", "minor", and "patch". The value coercion only fails if semver.inc("1.0.0", choice) throws an error.

  2. The --preid option can be used to specify the semver prerelease identifier (major.minor.patch-prerelease), e.g. with:

    lerna publish --cd-version=prerelease --preid=beta
    
  3. The --canary option now works with --cd-version to change how everything up to the prerelease identifier is changed, so you can do this:

    lerna publish --canary --cd-version=patch
    

Motivation and Context

I filed #915 while trying to tweak the way that our canary release were being automatically published by our Primer CI builds. Specifically, I wanted the prerelease identifier to be commit rather than alpha, and I wanted the releases to be incremented as patches rather than major versions, so that changes to 9.0.0 would publish canary builds for 9.0.1-commit.{sha} rather than 9.1.0-alpha.{sha}.

We set up release candidate automation for Primer release branches, which have updated package.json versions in git but need to have incremented prerelease identifiers, so we would go from 9.0.1 to 9.0.1-rc.0. This change allows you to do that with:

lerna publish --cd-version=prerelease --preid=rc

How Has This Been Tested?

I've added publish command tests for the following cases:

  • --cd-version=prerelease --preid=foo
  • --cd-version=prerelease (without a prerelease identifier, which semver handles transparently)
  • --canary --cd-version=patch

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@shawnbot shawnbot mentioned this pull request Aug 6, 2017

@evocateur evocateur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the direction this is headed. Perhaps you could coordinate with #958 to ensure this satisfies both parties?

Comment thread src/commands/PublishCommand.js Outdated
type: "string",
requiresArg: true,
},
"prerelease-id": {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only allow --preid, like the semver cli

Comment thread src/commands/PublishCommand.js Outdated
if (!["major", "minor", "patch"].some((inc) => choice === inc)) {
throw new Error(`--cd-version must be one of 'major', 'minor', or 'patch', got '${choice}'`);
try {
semver.inc("1.0.0", choice);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, interesting, this is much better than a static whitelist.

Comment thread src/commands/PublishCommand.js Outdated

this.updates.forEach((update) => {
versions[update.package.name] = semver.inc(update.package.version, this.options.cdVersion);
// TODO add semver.inc() argument for prerelease identifier

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This TODO seems satisfied? (but the one below is not)

Comment thread test/PublishCommand.js Outdated
* INDEPENDENT - CD VERSION - PRERELEASE
* ======================================================================= */

it("should bump to prerelease versions with --cd-version=prerelease --prerelease-id=foo", (done) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are great tests, what happens when you bump a non-canary prepatch with another prepatch?

I would expect 1.0.0-beta.0 bumps to 1.0.0-beta.1, but I don't see any tests to that effect.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prepatch will make it 1.0.1-beta.1 (actually, that's the difference between prepatch and prerelease)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah, I learned something! That makes sense.

Comment thread README.md Outdated

```sh
$ lerna publish --cd-version (patch | major | minor)
$ lerna publish --cd-version (patch | major | minor | prepatch | premajor | preminor | prerelease)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the ordering in the other PR, patch -> minor -> major

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about ordering these to be consistent with npm version, which, from npm help version is:

npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease | from-git]

Comment thread src/commands/PublishCommand.js Outdated
"cd-version": {
group: "Command Options:",
describe: "Skip the version selection prompt and increment semver 'major', 'minor', or 'patch'.",
describe: "Skip the version selection prompt and increment semver 'major', 'minor', 'patch', etc.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should still enumerate here the values that semver accepts currently

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, your PR's loop-generated string is preferable here.

Comment thread src/commands/PublishCommand.js Outdated
getCanaryVersion(version, metaName) {
if (metaName == null || typeof metaName !== "string") {
metaName = "alpha";
getCanaryVersion(version, prerelease) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preid maybe?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, that's a better name

@evocateur

evocateur commented Aug 10, 2017 via email

Copy link
Copy Markdown
Member

@shawnbot

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback, everyone! I'll get cracking on incorporating it this week.

@shawnbot

Copy link
Copy Markdown
Contributor Author

Okay @evocateur and @Hypnosphi, I think I've addressed all of your feedback. Let me know if you see anything else.

@shawnbot shawnbot changed the title Add support for publish w/--cd-version prerelease and --canary --cd-version Add support for publish w/--cd-version=pre*, --canary + --cd-version, and --preid Aug 23, 2017

@Hypnosphi Hypnosphi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@evocateur evocateur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to rebase to fix upstream conflicts, sorry. Almost there.

Comment thread src/commands/PublishCommand.js Outdated
coerce: (choice) => {
if (!["major", "minor", "patch"].some((inc) => choice === inc)) {
throw new Error(`--cd-version must be one of 'major', 'minor', or 'patch', got '${choice}'`);
if (!cdVersionOptions.includes(choice)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still support node v4, so we can't use Array#includes(). Can probably just restore the previous .some() iterator, or maybe just a plain old if (cdVersionOptions.indexOf(choice) === -1) { ? Not as fancy, but should get the job done.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, gotcha. I'll roll it back.

const defaultVersion = semver.inc(currentVersion, "prerelease", existingId);
const prompt = `(default: ${existingId ? `"${existingId}"` : "none"}, yielding ${defaultVersion})`;

// TODO: allow specifying prerelease identifier as CLI option to skip the prompt

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this TODO still valid?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I'm not sure. Should passing --preid skip the prompt?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like --preid, in this case, should possibly be able to provide an override (or fallback?) for the existingId above. It wouldn't skip the prompt, I don't think, unless they pass --yes.

In any case, let's leave the TODO and address it later (dunno how useful it would be, really)

@evocateur

Copy link
Copy Markdown
Member

@shawnbot Oh, and I, uh, rebased and fixed the array.includes bug for you. Apologies for the force push.

@shawnbot

Copy link
Copy Markdown
Contributor Author

No worries, @evocateur! ✌️

@evocateur evocateur changed the title Add support for publish w/--cd-version=pre*, --canary + --cd-version, and --preid Improve support for semver prerelease identifiers when publishing Aug 23, 2017
@evocateur

Copy link
Copy Markdown
Member

We can ignore the appveyor failure, it's some weird permissions problem with the npm cache :P

@evocateur
evocateur merged commit 681c60b into lerna:master Aug 23, 2017
@shawnbot
shawnbot deleted the canary-cd-version branch August 23, 2017 19:33
evocateur added a commit to evocateur/lerna that referenced this pull request Aug 26, 2017
evocateur added a commit that referenced this pull request Aug 27, 2017
The Inevitable One Line Fix (after 8 hours of refactoring tests)

Resolves #989

* fix ambiguous snapshot tests from #960
* add test/helpers/yargsRunner
* Command: run() returns a Promise; better validation errors
* DiffCommand: migrate tests to yargsRunner
* PublishCommand: migrate tests to yargsRunner
* Add test to confirm --cd-version choices
@spudly

spudly commented Sep 13, 2017

Copy link
Copy Markdown
Contributor

Question: The initial description for this pull request says that this fixes #567, but I don't see anything in the changed files that addresses that issue.

When you first publish a prerelease version (prerelease, premajor, preminor, prepatch) and later publish a regular version (major, minor, or patch), does this change force packages with the prerelease version to update to the non-prerelease version even if those packages haven't changed?

In other words, say I do the following:

  1. change pkgA and publish with a premajor bump (resulting in 1.0.0-rc.0)
  2. change pkgB and publish as a major bump (resulting in 1.0.0)

Will both pkgA and pkgB be on 1.0.0, or will pkgA still be on 1.0.0-rc.1?

@lock

lock Bot commented Dec 27, 2018

Copy link
Copy Markdown

This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock Bot locked as resolved and limited conversation to collaborators Dec 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

publish --canary doesn't work with custom values, or with --cd-version

5 participants