Release package to NPM #39
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: Release package to NPM | |
on: | |
workflow_dispatch: | |
inputs: | |
release_type: | |
description: "Type of release (major, minor, patch)" | |
required: true | |
default: "minor" | |
type: choice | |
options: | |
- major | |
- minor | |
- patch | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
permissions: | |
packages: write | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install pnpm | |
uses: pnpm/action-setup@v4 | |
with: | |
version: 9.4.0 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: 22 | |
cache: "pnpm" | |
- run: pnpm install | |
- run: pnpm test | |
- run: pnpm build | |
- name: Configure Git | |
run: | | |
git config --local user.email "${{ github.actor }}@users.noreply.github.com" | |
git config --local user.name "${{ github.actor }}" | |
- name: Bump version and push tag | |
run: | | |
if [ "${{ github.event.inputs.release_type }}" == "major" ]; then | |
export NEW_VERSION=$(npm version major) | |
elif [ "${{ github.event.inputs.release_type }}" == "minor" ]; then | |
export NEW_VERSION=$(npm version minor) | |
else | |
export NEW_VERSION=$(npm version patch) | |
fi | |
echo "New version: $NEW_VERSION" | |
git add package.json | |
git push origin HEAD:main | |
git push origin $NEW_VERSION | |
- uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
commit_message: Released $VERSION | |
- run: npm publish | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |