From 45880862da9c212632777271869afb322e6561ae Mon Sep 17 00:00:00 2001 From: siosonel Date: Mon, 23 Oct 2023 14:33:12 -0500 Subject: [PATCH] use pre* version type based on the branch name, and do not use the commit hash in the tag, but delete/re-tag in pre* version types --- .github/workflows/CD-publish-app-image.yml | 2 +- .github/workflows/CD-publish-packages.yml | 23 +++++++------- build/bump.js | 29 +++++++++-------- build/ci-version-update.sh | 37 ++++++++++++++++------ 4 files changed, 55 insertions(+), 36 deletions(-) diff --git a/.github/workflows/CD-publish-app-image.yml b/.github/workflows/CD-publish-app-image.yml index 8fb1c05257..9633d2592f 100644 --- a/.github/workflows/CD-publish-app-image.yml +++ b/.github/workflows/CD-publish-app-image.yml @@ -69,7 +69,7 @@ jobs: - name: Run version bump run: | - . ./build/ci-version-update.sh $VERTYPE -w + ./build/ci-version-update.sh $VERTYPE -w # !!! --- merge back to master --- !!! - name: Login to GitHub Container Registry diff --git a/.github/workflows/CD-publish-packages.yml b/.github/workflows/CD-publish-packages.yml index 9a3691fe1c..66f09c0b27 100644 --- a/.github/workflows/CD-publish-packages.yml +++ b/.github/workflows/CD-publish-packages.yml @@ -4,7 +4,7 @@ on: push: branches: - publish-packages - - fake-release + - fake-publish paths-ignore: - '**.md' - '**.txt' @@ -82,8 +82,8 @@ jobs: - name: Run version bump run: | - # initial dot makes the variables of the call script in-scope - . ./build/ci-version-update.sh -w -x=container + UPDATED=$(./build/bump.js -x=container) + ./build/ci-version-update.sh -w -x=container echo "UPDATED=$UPDATED" >> $GITHUB_ENV - name: Publish packages @@ -92,23 +92,22 @@ jobs: if [[ "$BRANCH" != "publish-packages" && "$BRANCH" != "release-chain" && "$BRANCH" != "master" && ${{ github.event_name }} != 'workflow_dispatch' ]]; then echo "skipping publishing" else - ./build/ci-npm-publish.sh "$UPDATED" + TAG=v$(node -p "require('./package.json').version") + REMOTETAG=$(git ls-remote origin refs/tags/$TAG) + if [[ "$REMOTETAG" != "" ]]; then + echo "Tag $TAG already exists on remote='origin' and may have been published already" + exit 1 + fi + ./build/ci-npm-publish.sh "$UPDATED" if [[ "$BRANCH" != "master" ]]; then - TAG=v$(node -p "require('./package.json').version") - REMOTETAG=$(git ls-remote origin refs/tags/$TAG) - if [[ "$REMOTETAG" != "" ]]; then - echo "Tag $TAG already exists on remote='origin'" - exit 1 - fi echo "merging to master" N=$(git rev-list master.. --count) git fetch --depth=N origin $BRANCH:$BRANCH git fetch --depth=1 origin master:master git switch master git merge $BRANCH - git push - git tag $TAG + git push git push origin $TAG fi fi diff --git a/build/bump.js b/build/bump.js index dfee17176c..49995cac4b 100755 --- a/build/bump.js +++ b/build/bump.js @@ -73,20 +73,23 @@ for (const k of process.argv.slice(3)) { // ****************************************** if (opts.refCommit.endsWith('^{commit}')) { - const tagExists = ex(`git tag -l v${rootPkg.version}`) - if (!tagExists) { - const errorMsg = ex(`git fetch --depth 1 origin tag v${rootPkg.version}`, { - message: `Error fetching the tag v${rootPkg.version}: cannot diff for changes` - }) - if (errorMsg) process.exit(1) - const commitMsg = ex(`git tag -l --format='%(contents)' v${rootPkg.version}`, { - message: `Error finding a commit message prefixed with v${rootPkg.version}: cannot verify tag` - }) - if (!commitMsg) process.exit(1) - if (!commitMsg.startsWith(`v${rootPkg.version} `)) { - console.error(`the reference tag's commit message does not start with v${rootPkg.version}`) - process.exit(1) + try { + const tagExists = ex(`git tag -l v${rootPkg.version}`) + if (!tagExists) { + const errorMsg = ex(`git fetch --depth 1 origin tag v${rootPkg.version}`, { + message: `Error fetching the tag v${rootPkg.version}: cannot diff for changes` + }) + if (errorMsg) throw errorMsg + const commitMsg = ex(`git tag -l --format='%(contents)' v${rootPkg.version}`, { + message: `Error finding a commit message prefixed with v${rootPkg.version}: cannot verify tag` + }) + if (!commitMsg) throw `error in finding commit message` + if (!commitMsg.startsWith(`v${rootPkg.version} `)) { + throw `the reference tag's commit message does not start with v${rootPkg.version}` + } } + } catch (e) { + throw e } } const newVersion = semver.inc(rootPkg.version, verType) diff --git a/build/ci-version-update.sh b/build/ci-version-update.sh index ca45d35297..292704e095 100755 --- a/build/ci-version-update.sh +++ b/build/ci-version-update.sh @@ -19,6 +19,11 @@ elif [[ "$NOTES" == *"Fixes:"* ]]; then VERTYPE=patch fi +BRANCH=$(git rev-parse --abbrev-ref HEAD) +if [[ "$VERTYPE" != "pre"* && "$BRANCH" != "publish-"* && "$BRANCH" != "release-chain"* && "$BRANCH" != "master" ]]; then + VERTYPE="pre$VERTYPE" +fi + ########## # CONTEXT ########## @@ -29,17 +34,20 @@ if [[ "$UPDATED" == "" ]]; then exit 1 fi - ######################## # Update the change log ######################## VERSION="$(node -p "require('./package.json').version")" -if [[ "$(grep 'Unreleased' CHANGELOG.md)" == "" ]]; then - echo "No unreleased changes to publish" - exit 1 +if [[ "$VERTYPE" != "pre"* ]]; then + if [[ "$(grep 'Unreleased' CHANGELOG.md)" == "" ]]; then + echo "No unreleased changes to publish" + exit 1 + fi + + # only update the change log if the version type is not prepatch, preminor, prerelease, pre* + sed -i.bak "s|Unreleased|$VERSION|" CHANGELOG.md fi -sed -i.bak "s|Unreleased|$VERSION|" CHANGELOG.md ################# # COMMIT CHANGES @@ -47,11 +55,6 @@ sed -i.bak "s|Unreleased|$VERSION|" CHANGELOG.md npm i --package-lock-only TAG="v$VERSION" -BRANCH=$(git rev-parse --abbrev-ref HEAD) -if [[ "$BRANCH" != "release" && "$BRANCH" != "master" ]]; then - HASH=$(git rev-parse --short HEAD) - TAG="$TAG-$HASH" -fi COMMITMSG="$TAG $UPDATED" echo "$COMMITMSG" echo "committing version change ..." @@ -59,6 +62,20 @@ git config --global user.email "PPTeam@STJUDE.ORG" git config --global user.name "PPTeam CI" git add --all git commit -m "$COMMITMSG" +echo "VERTYPE=[$VERTYPE]" + +EXISTINGTAG=$(git tag -l "$TAG") +if [[ "$VERTYPE" == "pre"* ]]; then + # delete existing tags that match + if [[ "$EXISTINGTAG" != "" ]]; then + git tag -d $TAG + fi + git push origin :refs/tags/$TAG +elif [[ "$EXISTINGTAG" != "" ]]; then + echo "Tag='$TAG' already exists" + exit 1 +fi + git tag $TAG BRANCH=$(git rev-parse --abbrev-ref HEAD) git push origin $BRANCH