Unverified Commit 475e7da2 authored by Robert Knight's avatar Robert Knight Committed by GitHub

Merge pull request #922 from hypothesis/remove-package-version-updates

Stop updating package.json version field during deployments from Jenkins
parents e9712269 fc2cc58e
...@@ -29,38 +29,33 @@ node { ...@@ -29,38 +29,33 @@ 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()
// Update local information about tags to match the remote,
// including removing any local tags that no longer exist.
//
// The `--prune-tags` option is not supported in Git 2.11 so we
// use the workaround from https://github.com/git/git/commit/97716d217c1ea00adfc64e4f6bb85c1236d661ff
sh "git fetch --quiet --prune origin 'refs/tags/*:refs/tags/*' "
// 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)
stage('Build') { if (versionSuffix != "") {
nodeEnv.inside("-e HOME=${workspace}") { newPkgVersion = newPkgVersion + "-" + versionSuffix
sh "echo Building Hypothesis client"
sh 'make clean'
sh 'make'
}
} }
echo "Building and testing ${newPkgVersion}"
stage('Test') { stage('Test') {
nodeEnv.inside("-e HOME=${workspace}") { nodeEnv.inside("-e HOME=${workspace}") {
...@@ -108,9 +103,6 @@ node { ...@@ -108,9 +103,6 @@ node {
""" """
} }
} }
// Revert back to the pre-QA commit.
sh "git checkout ${lastCommitHash}"
} }
milestone() milestone()
...@@ -118,11 +110,6 @@ node { ...@@ -118,11 +110,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}") {
...@@ -134,10 +121,8 @@ node { ...@@ -134,10 +121,8 @@ node {
[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 's3-cdn'] [$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 's3-cdn']
]) { ]) {
// Configure commit author for version bump commit and auth credentials // Configure author for tag and auth credentials for pushing tag to GitHub.
// for pushing tag to GitHub. // See https://git-scm.com/docs/git-credential-store.
//
// See https://git-scm.com/docs/git-credential-store
sh """ sh """
git config --replace-all user.email ${env.GITHUB_USERNAME}@hypothes.is git config --replace-all user.email ${env.GITHUB_USERNAME}@hypothes.is
git config --replace-all user.name ${env.GITHUB_USERNAME} git config --replace-all user.name ${env.GITHUB_USERNAME}
...@@ -145,22 +130,21 @@ node { ...@@ -145,22 +130,21 @@ node {
echo https://${env.GITHUB_USERNAME}:${env.GITHUB_TOKEN}@github.com >> \$HOME/.git-credentials echo https://${env.GITHUB_USERNAME}:${env.GITHUB_TOKEN}@github.com >> \$HOME/.git-credentials
""" """
// Update local information about tags to match the remote, // Create and push a git tag.
// including removing any local tags that no longer exist. sh "git tag v${newPkgVersion}"
// sh "git push https://github.com/hypothesis/client.git v${newPkgVersion}"
// The `--prune-tags` option is not supported in Git 2.11 so we sh "sleep 2" // Give GitHub a moment to realize the tag exists.
// use the workaround from https://github.com/git/git/commit/97716d217c1ea00adfc64e4f6bb85c1236d661ff
sh "git fetch --quiet --prune origin 'refs/tags/*:refs/tags/*' "
// Bump the package version and create the tag and GitHub release. // Bump the package version and create the GitHub release.
sh "yarn version --new-version ${newPkgVersion}" sh "yarn version --no-git-tag-version --new-version ${newPkgVersion}"
sh "scripts/create-github-release.js"
// 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.
// See https://github.com/yarnpkg/yarn/pull/3391. // See https://github.com/yarnpkg/yarn/pull/3391.
sh "echo '//registry.npmjs.org/:_authToken=${env.NPM_TOKEN}' >> \$HOME/.npmrc" sh "echo '//registry.npmjs.org/:_authToken=${env.NPM_TOKEN}' >> \$HOME/.npmrc"
sh "npm publish --tag ${npmTag}" sh "npm publish --tag ${npmTag}"
sh "scripts/wait-for-npm-release.sh" sh "scripts/wait-for-npm-release.sh ${npmTag}"
// Deploy the client to cdn.hypothes.is, where the embedded // Deploy the client to cdn.hypothes.is, where the embedded
// client is served from by https://hypothes.is/embed.js. // client is served from by https://hypothes.is/embed.js.
...@@ -178,7 +162,7 @@ node { ...@@ -178,7 +162,7 @@ node {
String bumpMinorVersion(String version) { String bumpMinorVersion(String version) {
def parts = version.tokenize('.') def parts = version.tokenize('.')
if (parts.size() != 3) { if (parts.size() != 3) {
throw new IllegalArgumentException("${version} is not a valid MAJOR.MINOR.PATCH version") error "${version} is not a valid MAJOR.MINOR.PATCH version"
} }
def newMinorVersion = parts[1].toInteger() + 1 def newMinorVersion = parts[1].toInteger() + 1
......
{ {
"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",
...@@ -148,7 +148,6 @@ ...@@ -148,7 +148,6 @@
"test": "gulp test", "test": "gulp test",
"report-coverage": "codecov -f coverage/coverage-final.json", "report-coverage": "codecov -f coverage/coverage-final.json",
"version": "make clean build/manifest.json", "version": "make clean build/manifest.json",
"postversion": "./scripts/postversion.sh",
"prepublish": "yarn run build" "prepublish": "yarn run build"
} }
} }
#!/bin/sh
set -eu
cd "$(dirname "$0")"
# Skip GitHub release creation for QA releases.
is_prerelease=$(node -p "require('../package.json').version.includes('-')")
if [ $is_prerelease = "true" ]; then
echo "Skipping GitHub release creation for pre-release"
exit 0
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
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