@@ -21,40 +21,57 @@ jobs:
2121 with :
2222 node-version : 20
2323
24- # Update package.json version to match the release tag
24+ # Call `npm version`. It increments the version and commits the changes.
25+ # We'll save the output (new version string) for use in the following
26+ # steps
2527 - name : Update package version
2628 id : update-package-version
2729 run : |
2830 git tag -d "${{ github.event.release.tag_name }}"
2931 VERSION=$(npm version "${{ github.event.release.tag_name }}" --no-git-tag-version)
3032 git add package.json package-lock.json
3133 git commit -m "[skip ci] Bump $VERSION"
32- git pull --rebase origin main
3334 git push origin HEAD:main
3435
35- # Build and test
36+ # Now carry on, business as usual
3637 - name : Perform npm tasks
3738 run : npm run ci
3839
39- # Create release with built artifacts
40- - name : Create release artifacts
40+ # Finally, create a detached commit containing the built artifacts and tag
41+ # it with the release. Note: the fact that the branch is locally updated
42+ # will not be relayed (pushed) to origin
43+ - name : Commit to release branch
4144 id : release_info
4245 run : |
43- # Validate semantic versioning
46+ # Check for semantic versioning
4447 longVersion="${{github.event.release.tag_name}}"
4548 echo "Preparing release for version $longVersion"
46- [[ $longVersion == v[0-9]*.[0-9]*.[0-9]* ]] || (echo "must follow semantic versioning" && exit 1)
49+ [[ $longVersion == v[0-9]*.[0-9]*.[0-9]* ]] || (echo "must follow semantic versioning" && exit 1)
50+ majorVersion=$(echo ${longVersion%.*.*})
51+ minorVersion=$(echo ${longVersion%.*})
4752
48- # Add the built artifacts (adjust folder names as needed)
53+ # Add the built artifacts. Using --force because dist/lib should be in
54+ # .gitignore
4955 git add --force dist lib
5056
51- # Create commit with built code
57+ # Make the commit
5258 MESSAGE="Build for $(git rev-parse --short HEAD)"
5359 git commit --allow-empty -m "$MESSAGE"
54-
55- # Tag this commit with the release version
5660 git tag -f -a -m "Release $longVersion" $longVersion
61+
62+ # Get the commit of the tag you just released
63+ commitHash=$(git rev-list -n 1 $longVersion)
64+
65+ # Delete the old major and minor version tags locally
66+ git tag -d $majorVersion || true
67+ git tag -d $minorVersion || true
68+
69+ # Make new major and minor version tags locally that point to the commit you got from the "git rev-list" above
70+ git tag -f $majorVersion $commitHash
71+ git tag -f $minorVersion $commitHash
5772
58- # Push the release tag
59- echo "Pushing new tag "
73+ # Force push the new minor version tag to overwrite the old tag remotely
74+ echo "Pushing new tags "
6075 git push -f origin $longVersion
76+ git push -f origin $majorVersion
77+ git push -f origin $minorVersion
0 commit comments