-
Notifications
You must be signed in to change notification settings - Fork 35
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
ci: publish prerelease versions #2548
Changes from all commits
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ on: | |
push: | ||
branches: | ||
- master | ||
- 'prerelease/**' | ||
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. |
||
jobs: | ||
build: | ||
name: 'Build' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
def parseSemanticVersion(String version) { | ||
def semanticVersionRegex = /^(((([0-9]+)\.[0-9]+)\.[0-9]+)(?:\-.+)?)$/ | ||
def (_, prerelease, patch, minor, major) = (version =~ semanticVersionRegex)[0] | ||
return [major, minor, patch, prerelease] | ||
} | ||
Comment on lines
+1
to
+5
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. Tested this in a repl. Try executing the following in https://www.jdoodle.com/execute-groovy-online/: def parseSemanticVersion(String version) {
def semanticVersionRegex = /^(((([0-9]+)\.[0-9]+)\.[0-9]+)(?:\-.+)?)$/
def (_, prerelease, patch, minor, major) = (version =~ semanticVersionRegex)[0]
return [major, minor, patch, prerelease]
}
def printVersion(String version) {
def (major, minor, patch, prerelease) = parseSemanticVersion(version)
println "== ${version} =="
println "Major: ${major}"
println "Minor: ${minor}"
println "Patch: ${patch}"
println "Prerelease: ${prerelease}"
}
printVersion("123.456.789-pre.1")
print "\n"
printVersion("123.456.789") |
||
|
||
node('heavy && linux && docker') { | ||
checkout scm | ||
def tag = sh(script: "git tag --contains", returnStdout: true).trim() | ||
def isBump = !!tag | ||
def isMaster = env.BRANCH_NAME == 'master' | ||
def isOnReleaseBranch = env.BRANCH_NAME == 'master' | ||
def isOnPrereleaseBranch = env.BRANCH_NAME.startsWith('prerelease/') | ||
|
||
if (!isMaster) { | ||
if (!isOnReleaseBranch && !isOnPrereleaseBranch) { | ||
return | ||
} | ||
|
||
|
@@ -32,12 +39,14 @@ node('heavy && linux && docker') { | |
sh 'git clean -f' | ||
} | ||
|
||
withDockerContainer(image: 'node:16', args: '-u=root -e HOME=/tmp -e NPM_CONFIG_PREFIX=/tmp/.npm') { | ||
stage('Npm publish') { | ||
withCredentials([ | ||
string(credentialsId: 'NPM_TOKEN', variable: 'NPM_TOKEN')]) { | ||
sh "echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > ~/.npmrc" | ||
sh 'npm run npm:publish:alpha || true' | ||
if (isOnReleaseBranch) { | ||
withDockerContainer(image: 'node:16', args: '-u=root -e HOME=/tmp -e NPM_CONFIG_PREFIX=/tmp/.npm') { | ||
stage('Npm publish') { | ||
withCredentials([ | ||
string(credentialsId: 'NPM_TOKEN', variable: 'NPM_TOKEN')]) { | ||
sh "echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > ~/.npmrc" | ||
sh 'npm run npm:publish:alpha || true' | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -48,23 +57,22 @@ node('heavy && linux && docker') { | |
headless = readJSON file: 'packages/headless/package.json' | ||
atomic = readJSON file: 'packages/atomic/package.json' | ||
atomicReact = readJSON file: 'packages/atomic-react/package.json' | ||
semanticVersionRegex = /^([^\.]*)\.[^\.]*/ | ||
|
||
(headlessMinor, headlessMajor) = (headless.version =~ semanticVersionRegex)[0] | ||
(atomicMinor, atomicMajor) = (atomic.version =~ semanticVersionRegex)[0] | ||
(atomicReactMinor, atomicReactMajor) = (atomicReact.version =~ semanticVersionRegex)[0] | ||
|
||
(headlessMajor, headlessMinor, headlessPatch) = parseSemanticVersion(headless.version) | ||
(atomicMajor, atomicMinor, atomicPatch) = parseSemanticVersion(atomic.version) | ||
(atomicReactMajor, atomicReactMinor, atomicReactPatch) = parseSemanticVersion(atomicReact) | ||
|
||
sh "deployment-package package create --with-deploy \ | ||
--resolve HEADLESS_MAJOR_VERSION=${headlessMajor} \ | ||
--resolve HEADLESS_MINOR_VERSION=${headlessMinor} \ | ||
--resolve HEADLESS_PATCH_VERSION=${headless.version} \ | ||
--resolve HEADLESS_PATCH_VERSION=${headlessPatch} \ | ||
--resolve ATOMIC_MAJOR_VERSION=${atomicMajor} \ | ||
--resolve ATOMIC_MINOR_VERSION=${atomicMinor} \ | ||
--resolve ATOMIC_PATCH_VERSION=${atomic.version} \ | ||
--resolve ATOMIC_PATCH_VERSION=${atomicPatch} \ | ||
--resolve ATOMIC_REACT_MAJOR_VERSION=${atomicReactMajor} \ | ||
--resolve ATOMIC_REACT_MINOR_VERSION=${atomicReactMinor} \ | ||
--resolve ATOMIC_REACT_PATCH_VERSION=${atomicReact.version} \ | ||
--resolve ATOMIC_REACT_PATCH_VERSION=${atomicReactPatch} \ | ||
--resolve STOP_AT_DEV=${!isOnReleaseBranch} \ | ||
|| true" | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,23 @@ | ||
const {promisify} = require('util'); | ||
const exec = promisify(require('child_process').exec); | ||
|
||
async function getHeadCommitHash() { | ||
const {stdout} = await exec('git rev-parse HEAD'); | ||
return stdout; | ||
} | ||
|
||
async function getHeadCommitTag() { | ||
const {stdout} = await exec('git tag --points-at HEAD'); | ||
return stdout; | ||
} | ||
|
||
async function checkoutLatestMaster() { | ||
await exec('git checkout master'); | ||
await exec('git pull origin master'); | ||
} | ||
const { | ||
isOnReleaseBranch, | ||
getHowManyCommitsBehind, | ||
getHeadCommitTag, | ||
} = require('../git'); | ||
|
||
async function bumpVersionAndPush() { | ||
try { | ||
await exec( | ||
`npx --no-install lerna version --conventional-commits --conventional-graduate --no-private --yes --exact` | ||
); | ||
const flags = [ | ||
'--conventional-commits', | ||
(await isOnReleaseBranch()) | ||
? '--conventional-graduate' | ||
: '--conventional-prerelease', | ||
'--no-private', | ||
'--yes', | ||
'--exact', | ||
]; | ||
await exec(`npx --no-install lerna version ${flags.join(' ')}`); | ||
} catch (e) { | ||
console.error( | ||
'Failed to bump version. Exiting to not publish local changes.', | ||
|
@@ -32,13 +29,9 @@ async function bumpVersionAndPush() { | |
|
||
async function main() { | ||
try { | ||
const buildCommitHash = await getHeadCommitHash(); | ||
await checkoutLatestMaster(); | ||
const masterCommitHash = await getHeadCommitHash(); | ||
|
||
if (buildCommitHash !== masterCommitHash) { | ||
if ((await getHowManyCommitsBehind()) !== 0) { | ||
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. I changed the condition here since we now execute this script on more branches than just |
||
console.log( | ||
'Build commit does not match latest master commit. Skipping version bump.' | ||
'Build commit does not match latest commit. Skipping version bump.' | ||
); | ||
return; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const {promisify} = require('util'); | ||
const exec = promisify(require('child_process').exec); | ||
|
||
const releaseBranch = 'master'; | ||
|
||
async function getBranchName() { | ||
const {stdout} = await exec('git branch --show-current'); | ||
return stdout; | ||
} | ||
|
||
async function isOnReleaseBranch() { | ||
return (await getBranchName()) === releaseBranch; | ||
} | ||
|
||
async function getHowManyCommitsBehind() { | ||
const {stdout} = await exec('git rev-list --count HEAD..@{u}'); | ||
return parseInt(stdout); | ||
} | ||
|
||
async function getHeadCommitTag() { | ||
const {stdout} = await exec('git tag --points-at HEAD'); | ||
return stdout; | ||
} | ||
|
||
module.exports = {isOnReleaseBranch, getHowManyCommitsBehind, getHeadCommitTag}; |
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.
The quotation marks are missing here, and it's on purpose. This will be replaced by the variable directly.
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.
If you don't like the syntax error here, I can convert the file to YAML.