Skip to content

Commit

Permalink
use pre* version type based on the branch name, and do not use the co…
Browse files Browse the repository at this point in the history
…mmit hash in the tag, but delete/re-tag in pre* version types
  • Loading branch information
siosonel committed Oct 23, 2023
1 parent 688bf17 commit 42d2661
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/CD-publish-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches:
- publish-packages
- fake-release
- fake-publish
paths-ignore:
- '**.md'
- '**.txt'
Expand Down Expand Up @@ -92,15 +92,15 @@ 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
Expand Down
28 changes: 19 additions & 9 deletions build/ci-version-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
##########
Expand All @@ -35,30 +40,35 @@ fi
########################

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
#################

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 ..."
git config --global user.email "[email protected]"
git config --global user.name "PPTeam CI"
git add --all
git commit -m "$COMMITMSG"
if [[ "$VERTYPE" == "pre"* ]]; then
# delete existing tags that match
git update-ref -d refs/heads/$TAG
git push origin :refs/tags/$TAG
fi

git tag $TAG
BRANCH=$(git rev-parse --abbrev-ref HEAD)
git push origin $BRANCH
Expand Down

0 comments on commit 42d2661

Please sign in to comment.