Skip to content

fix(publish): move git sha to build metadata - #1507

Closed
hutson wants to merge 1 commit into
lerna:masterfrom
hutson:fix/publish/canary
Closed

hutson wants to merge 1 commit into
lerna:masterfrom
hutson:fix/publish/canary

Conversation

@hutson

@hutson hutson commented Jul 19, 2018

Copy link
Copy Markdown

Move the git commit sha from the pre-release string of the semantic
version number to the build metadata string.

Git commit shas are not always valid pre-release strings according to
the Semantic Versioning Specification 2.0. For example, SemVer requires
that a numeric pre-release segment (a segment consisting of only
numbers) must not contain a leading zero. However, it's possible for
a git commit sha to be all numbers and for the first number to be zero.

The same rule does not apply to the build metadata string placed
after a + character. Therefore, to ensure the version contains git sha
information, but is still valid, we are moving the sha to the build
metadata string.

BREAKING CHANGE:

Git commit sha is now contained in the build metadata string of the
semantic version number.

So 1.1.0-alpha.81e3b443 now becomes 1.1.0-alpha+81e3b443 when you
run lerna --canary.

To increment the pre-release number after alpha please include it in
the string passed to the --canary flag:

lerna --canary=alpha.0

For convience, consider using the build number typically set in your
build environment by your CI platform:

lerna --canary=alpha.${BUILD_NUMBER}

Fixes #1118


Description

Please see commit message.

Motivation and Context

Please see #1118.

How Has This Been Tested?

Please see snapshots.

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 did not use the latest version of npm. I used a Docker container, and you can't upgrade older versions of npm in Docker because of an npm bug.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Move the git commit sha from the pre-release string of the semantic
version number to the build metadata string.

Git commit shas are not always valid pre-release strings according to
the Semantic Versioning Specification 2.0. For example, SemVer requires
that a numeric pre-release segment (a segment consisting of only
numbers) must not contain a leading zero. However, it's possible for
a git commit sha to be all numbers and for the first number to be zero.

The same rule does **not** apply to the build metadata string placed
after a `+` character. Therefore, to ensure the version contains git sha
information, but is still valid, we are moving the sha to the build
metadata string.

BREAKING CHANGE:

Git commit sha is now contained in the build metadata string of the
semantic version number.

So `1.1.0-alpha.81e3b443` now becomes `1.1.0-alpha+81e3b443` when you
run `lerna --canary`.

To increment the pre-release number after `alpha` please include it in
the string passed to the `--canary` flag:

```bash
lerna --canary=alpha.0
```

For convience, consider using the build number typically set in your
build environment by your CI platform:

```bash
lerna --canary=alpha.${BUILD_NUMBER}
```

Fixes #1118
@hutson

hutson commented Jul 19, 2018 •

Copy link
Copy Markdown
Author

@evocateur I'm not sure why most of those snapshots were updated.

When I ran npm test it notified me that I needed to update my snapshots. So I did.

I understand why the canary snapshot was updated, but not the others.

My development environment is a Node 8 Docker container using the version of npm and git that comes with it.

I also don't understand why npm mangled the package-lock.json file.

What do I need to do to get a working local build, and one that plays nicely with Lerna's CI setup?


Edit: Even a Docker Node 10 image does not work for me (same snapshot issues, and build failure):

node@29c44ab42d4b:/app$ git --version
git version 2.1.4
node@29c44ab42d4b:/app$ npm --version
6.1.0
node@29c44ab42d4b:/app$ node --version
v10.6.0

@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.

The vast majority of the snapshots should not have changed (nor the lockfile). I don’t work in a Docker container, so I can’t say what’s wrong. It works well enough in Travis, so it’s not containers generally...

@evocateur

Copy link
Copy Markdown
Member

There is a snapshot serializer that may need to be updated due to the version format change.

I’m still not a huge fan of passing in the numeric bit of the release ID. I’m in the process of major refactoring in this area, FYI (splitting version command out of publish).

@evocateur

Copy link
Copy Markdown
Member

v2.1.4 of git seems rather old, since the latest release is v2.17.x...

@hutson

hutson commented Jul 20, 2018

Copy link
Copy Markdown
Author

The vast majority of the snapshots should not have changed (nor the lockfile).

I'll pull down the Travis CI docker image so that I can have a development environment with the proper tools.

There is a snapshot serializer that may need to be updated due to the version format change.

I'll keep an eye out for that.

I’m still not a huge fan of passing in the numeric bit of the release ID.

Me neither, but the next option was to use the canary value, query the npm registry, find all package releases that match the version and canary identifier, then find the next available number.

For example, if 1.0.0-beta.0 was published, I would expect Lerna to query the npm registry, see beta.0, increment the number, and append it to the canary string.

However, that seemed like way too much complexity to introduce to address just this issue.

Would your refactor provide something like that?

v2.1.4 of git seems rather old, since the latest release is v2.17.x...

Not unheard of though.

At my company we use Lerna 2.0 publish on RHEL 6 boxes rocking git version 1.8. 😉 (We'll have access to a newer version soonish, but even then, we use RHEL and LTS versions of Ubuntu using the versions of packages that come with those distributions. So we'll still be using a older version of git than what is added to the Travis CI build environment (Travis CI upgrades the version of git in their images beyond what comes by default with Ubuntu Trusty))

@fenduru

fenduru commented Jul 26, 2018

Copy link
Copy Markdown

@evocateur @hbetts what needs to be done to get this merged and released? I currently cannot use Lerna canaries for my projects that publish to Artifactory which is quite unfortunate.

@hutson

hutson commented Jul 26, 2018

Copy link
Copy Markdown
Author

@fenduru I need to update this change so that unrelated snapshots are not updated. That will require a little time to build out a custom Docker image to provide a compatible development environment. (Longer story is copied below)

The other part of this is determining what @evocateur means by I’m still not a huge fan of passing in the numeric bit of the release ID. I’m in the process of major refactoring in this area, FYI (splitting version command out of publish)..


As known, most of the snapshots should not have changed. So, I spent this morning trying to get a reproducible development environment on my laptop. Using the official node:8 docker image is not sufficient because it uses Debian Jessie (Version 8), which has git 2.1.4 installed. Lerna uses Travis CI as their build environment and Travis CI maintains their own custom Docker images, which are based on Ubuntu Trusty, with a newer version of git manually installed into the container image.

Therefore, to get a development environment that matches that of the core maintainer and their CI environment, I need to pull the Travis CI image. So, in addition to learning why git was too old in the standard Node images, I then started downloading the ~3GB Docker image for Travis CI.

However, Travis CI images do not contain Node, or any of the tooling needed to setup a Node development environment (such as nvm). Instead, anyone pulling their custom images are expected to install any tools or runtimes they require.

Therefore, I'm going to need to build a Docker image off of the Travis CI image, and manually install the required version of Node I need for Lerna development.

@fenduru

fenduru commented Jul 26, 2018 •

Copy link
Copy Markdown

I was able to come up with a workaround for the time being:

yarn lerna publish --skip-git --cd-version=prerelease --preid=beta+`git rev-parse --short HEAD` --npm-tag next --exact --yes

Which yields a version like 2.2.1-beta+8e77993.0

@hutson

hutson commented Jul 26, 2018

Copy link
Copy Markdown
Author

I believe @evocateur's answer is effectively #1522

I'm closing this PR out because the underlying code has been rewritten by @evocateur.

Furthermore, #1522 actually addresses this issue.

@hutson hutson closed this Jul 26, 2018
@hutson
hutson deleted the fix/publish/canary branch July 26, 2018 17:58
@evocateur

Copy link
Copy Markdown
Member

@hbetts Thanks for all your contributions, they've been especially helpful lately!

@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.

Invalid canary versions for certain SHAs

3 participants