Commit c896ec41 authored by Robert Knight's avatar Robert Knight

Stop updating package.json version field during deployments from Jenkins

Creating a commit which updates the version number as part of
the release process prevents deployments of the master branch which are
not the latest commit, which is a surprising limitation compared to our
release process for h etc.

This commit resolves the issue by removing the version-bumping commit.
Instead package.json in the source tree contains a fixed, unchanging
version number which is set to the real version just before the package
is published to npm. The release version is obtained by fetching the tag
with the highest version number and incrementing the major part.
parent 5046b2ac
...@@ -29,30 +29,26 @@ node { ...@@ -29,30 +29,26 @@ node {
npmTag = "prerelease" npmTag = "prerelease"
} }
lastCommitAuthor = sh (
script: 'git show HEAD --no-patch --format="%an"',
returnStdout: true
).trim()
lastCommitHash = sh ( lastCommitHash = sh (
script: 'git show HEAD --no-patch --format="%h"', script: 'git show HEAD --no-patch --format="%h"',
returnStdout: true returnStdout: true
).trim() ).trim()
if (lastCommitAuthor == "jenkins-hypothesis") {
echo "Skipping build of automated commit created by Jenkins"
return
}
pkgName = sh ( pkgName = sh (
script: 'cat package.json | jq -r .name', script: 'cat package.json | jq -r .name',
returnStdout: true returnStdout: true
).trim() ).trim()
// Determine version number for next release.
pkgVersion = sh ( pkgVersion = sh (
script: 'cat package.json | jq -r .version', script: 'git tag --list | sort --version-sort --reverse | head -n1 | tail -c +2',
returnStdout: true returnStdout: true
).trim() ).trim()
newPkgVersion = bumpMinorVersion(pkgVersion)
if (versionSuffix != "") {
newPkgVersion = newPkgVersion + "-" + versionSuffix
}
echo "Building and testing ${newPkgVersion}"
stage('Build') { stage('Build') {
nodeEnv.inside("-e HOME=${workspace}") { nodeEnv.inside("-e HOME=${workspace}") {
...@@ -108,9 +104,6 @@ node { ...@@ -108,9 +104,6 @@ node {
""" """
} }
} }
// Revert back to the pre-QA commit.
sh "git checkout ${lastCommitHash}"
} }
milestone() milestone()
...@@ -118,11 +111,6 @@ node { ...@@ -118,11 +111,6 @@ node {
input(message: "Publish new client release?") input(message: "Publish new client release?")
milestone() milestone()
newPkgVersion = bumpMinorVersion(pkgVersion)
if (versionSuffix != "") {
newPkgVersion = newPkgVersion + "-" + versionSuffix
}
echo "Publishing ${pkgName} v${newPkgVersion} from ${releaseFromBranch} branch." echo "Publishing ${pkgName} v${newPkgVersion} from ${releaseFromBranch} branch."
nodeEnv.inside("-e HOME=${workspace} -e BRANCH_NAME=${env.BRANCH_NAME}") { nodeEnv.inside("-e HOME=${workspace} -e BRANCH_NAME=${env.BRANCH_NAME}") {
...@@ -152,8 +140,13 @@ node { ...@@ -152,8 +140,13 @@ node {
// use the workaround from https://github.com/git/git/commit/97716d217c1ea00adfc64e4f6bb85c1236d661ff // use the workaround from https://github.com/git/git/commit/97716d217c1ea00adfc64e4f6bb85c1236d661ff
sh "git fetch --quiet --prune origin 'refs/tags/*:refs/tags/*' " sh "git fetch --quiet --prune origin 'refs/tags/*:refs/tags/*' "
// Bump the package version and create the tag and GitHub release. // Create and push a git tag.
sh "yarn version --new-version ${newPkgVersion}" sh "git tag v${newPkgVersion}"
sh "git push https://github.com/hypothesis/client.git v${newPkgVersion}"
sh "sleep 2" // Give GitHub a moment to realize the tag exists.
// Bump the package version and create the GitHub release.
sh "yarn version --no-git-tag-version --new-version ${newPkgVersion}"
// Publish the updated package to the npm registry. // Publish the updated package to the npm registry.
// Use `npm` rather than `yarn` for publishing. // Use `npm` rather than `yarn` for publishing.
......
{ {
"name": "hypothesis", "name": "hypothesis",
"version": "1.123.0", "version": "1.0.0-dummy-version",
"description": "Annotate with anyone, anywhere.", "description": "Annotate with anyone, anywhere.",
"license": "BSD-2-Clause", "license": "BSD-2-Clause",
"homepage": "https://hypothes.is", "homepage": "https://hypothes.is",
......
...@@ -11,12 +11,4 @@ if [ $is_prerelease = "true" ]; then ...@@ -11,12 +11,4 @@ if [ $is_prerelease = "true" ]; then
exit 0 exit 0
fi fi
# nb. The remote refname is fully qualified because this script is run in a CI
# environment where not all heads may have been fetched.
git push https://github.com/hypothesis/client.git HEAD:refs/heads/$BRANCH_NAME \
--follow-tags --atomic
# Wait a moment to give GitHub a chance to realize that the tag exists
sleep 2
./create-github-release.js ./create-github-release.js
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment