-
Notifications
You must be signed in to change notification settings - Fork 204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stop updating package.json version field during deployments from Jenkins #922
Changes from all commits
c896ec4
753272e
53618fe
e900bc6
46eba2b
fc2cc58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,38 +29,33 @@ node { | |
npmTag = "prerelease" | ||
} | ||
|
||
lastCommitAuthor = sh ( | ||
script: 'git show HEAD --no-patch --format="%an"', | ||
returnStdout: true | ||
).trim() | ||
|
||
lastCommitHash = sh ( | ||
script: 'git show HEAD --no-patch --format="%h"', | ||
returnStdout: true | ||
).trim() | ||
|
||
if (lastCommitAuthor == "jenkins-hypothesis") { | ||
echo "Skipping build of automated commit created by Jenkins" | ||
return | ||
} | ||
|
||
pkgName = sh ( | ||
script: 'cat package.json | jq -r .name', | ||
returnStdout: true | ||
).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 ( | ||
script: 'cat package.json | jq -r .version', | ||
script: 'git tag --list | sort --version-sort --reverse | head -n1 | tail -c +2', | ||
returnStdout: true | ||
).trim() | ||
|
||
stage('Build') { | ||
nodeEnv.inside("-e HOME=${workspace}") { | ||
sh "echo Building Hypothesis client" | ||
sh 'make clean' | ||
sh 'make' | ||
} | ||
newPkgVersion = bumpMinorVersion(pkgVersion) | ||
if (versionSuffix != "") { | ||
newPkgVersion = newPkgVersion + "-" + versionSuffix | ||
} | ||
echo "Building and testing ${newPkgVersion}" | ||
|
||
stage('Test') { | ||
nodeEnv.inside("-e HOME=${workspace}") { | ||
|
@@ -108,21 +103,13 @@ node { | |
""" | ||
} | ||
} | ||
|
||
// Revert back to the pre-QA commit. | ||
sh "git checkout ${lastCommitHash}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No git commit is created during the QA release process, so this is unnecessary |
||
} | ||
|
||
milestone() | ||
stage('Publish') { | ||
input(message: "Publish new client release?") | ||
milestone() | ||
|
||
newPkgVersion = bumpMinorVersion(pkgVersion) | ||
if (versionSuffix != "") { | ||
newPkgVersion = newPkgVersion + "-" + versionSuffix | ||
} | ||
|
||
echo "Publishing ${pkgName} v${newPkgVersion} from ${releaseFromBranch} branch." | ||
|
||
nodeEnv.inside("-e HOME=${workspace} -e BRANCH_NAME=${env.BRANCH_NAME}") { | ||
|
@@ -134,33 +121,30 @@ node { | |
[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 's3-cdn'] | ||
]) { | ||
|
||
// Configure commit author for version bump commit and auth credentials | ||
// for pushing tag to GitHub. | ||
// | ||
// See https://git-scm.com/docs/git-credential-store | ||
// Configure author for tag and auth credentials for pushing tag to GitHub. | ||
// See https://git-scm.com/docs/git-credential-store. | ||
sh """ | ||
git config --replace-all user.email ${env.GITHUB_USERNAME}@hypothes.is | ||
git config --replace-all user.name ${env.GITHUB_USERNAME} | ||
git config credential.helper store | ||
echo https://${env.GITHUB_USERNAME}:${env.GITHUB_TOKEN}@github.com >> \$HOME/.git-credentials | ||
""" | ||
|
||
// 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/*' " | ||
// Create and push a git tag. | ||
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 tag and GitHub release. | ||
sh "yarn version --new-version ${newPkgVersion}" | ||
// Bump the package version and create the GitHub release. | ||
sh "yarn version --no-git-tag-version --new-version ${newPkgVersion}" | ||
sh "scripts/create-github-release.js" | ||
|
||
// Publish the updated package to the npm registry. | ||
// Use `npm` rather than `yarn` for publishing. | ||
// See https://github.com/yarnpkg/yarn/pull/3391. | ||
sh "echo '//registry.npmjs.org/:_authToken=${env.NPM_TOKEN}' >> \$HOME/.npmrc" | ||
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 | ||
// client is served from by https://hypothes.is/embed.js. | ||
|
@@ -178,7 +162,7 @@ node { | |
String bumpMinorVersion(String version) { | ||
def parts = version.tokenize('.') | ||
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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The previous code never worked in Jenkins because you can't |
||
} | ||
def newMinorVersion = parts[1].toInteger() + 1 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "hypothesis", | ||
"version": "1.123.0", | ||
"version": "1.0.0-dummy-version", | ||
"description": "Annotate with anyone, anywhere.", | ||
"license": "BSD-2-Clause", | ||
"homepage": "https://hypothes.is", | ||
|
@@ -148,7 +148,6 @@ | |
"test": "gulp test", | ||
"report-coverage": "codecov -f coverage/coverage-final.json", | ||
"version": "make clean build/manifest.json", | ||
"postversion": "./scripts/postversion.sh", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic that used to be here has been moved to the Jenkinsfile. |
||
"prepublish": "yarn run build" | ||
} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This stage doesn't actually do anything useful.
make
on its own just prints help output. The client actually gets built during the "QA" and "prod" steps with the appropriate version number. If there is eg. a syntax error, it'll get flagged either during the Test or QA steps.