v2.3.0 #20
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish | |
on: | |
release: | |
types: [published, edited] | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
outputs: | |
tag: ${{ steps.update-package-version.outputs.version }} | |
steps: | |
# Configure runner with the right stuff | |
- uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Configure git | |
run: | | |
git config user.name 'Release Action' | |
git config user.email '<>' | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
# Call `npm version`. It increments the version and commits the changes. | |
# We'll save the output (new version string) for use in the following | |
# steps | |
- name: Update package version | |
id: update-package-version | |
run: | | |
git tag -d "${{ github.event.release.tag_name }}" | |
VERSION=$(npm version "${{ github.event.release.tag_name }}" --no-git-tag-version) | |
echo "::set-output name=version::$VERSION" | |
git add package.json package-lock.json | |
git commit -m "[skip ci] Bump $VERSION" | |
git push origin HEAD:main | |
# Now carry on, business as usual | |
- name: Perform npm tasks | |
run: npm run ci | |
# Finally, create a detached commit containing the built artifacts and tag | |
# it with the release. Note: the fact that the branch is locally updated | |
# will not be relayed (pushed) to origin | |
- name: Commit to release branch | |
id: release_info | |
run: | | |
# Check for semantic versioning | |
echo "Preparing release for version $longVersion" | |
longVersion="${{github.event.release.tag_name}}" | |
[[ $longVersion == v[0-9]*.[0-9]*.[0-9]* ]] || (echo "must follow semantic versioning" && exit 1) | |
majorVersion=$(echo ${longVersion%.*.*}) | |
minorVersion=$(echo ${longVersion%.*}) | |
# Add the built artifacts. Using --force because dist/lib should be in | |
# .gitignore | |
git add --force dist lib | |
# Make the commit | |
MESSAGE="Build for $(git rev-parse --short HEAD)" | |
git commit --allow-empty -m "$MESSAGE" | |
git tag -f -a -m "Release $longVersion" $longVersion | |
# Get the commit of the tag you just released | |
commitHash=$(git rev-list -n 1 $longVersion) | |
# Delete the old major and minor version tags locally | |
git tag -d $majorVersion || true | |
git tag -d $minorVersion || true | |
# Make new major and minor version tags locally that point to the commit you got from the "git rev-list" above | |
git tag -f $majorVersion $commitHash | |
git tag -f $minorVersion $commitHash | |
# Force push the new minor version tag to overwrite the old tag remotely | |
echo "Pushing new tags" | |
git push -f origin $longVersion | |
git push -f origin $majorVersion | |
git push -f origin $minorVersion |