Release #2
This file contains hidden or 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 | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| bump: | |
| description: 'Version bump type (use "current" to publish as-is)' | |
| required: true | |
| type: choice | |
| options: | |
| - current | |
| - patch | |
| - minor | |
| - major | |
| permissions: | |
| contents: write | |
| id-token: write | |
| jobs: | |
| release: | |
| name: Bump, Tag & Publish | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| registry-url: https://registry.npmjs.org | |
| cache: npm | |
| - run: npm ci | |
| - run: npm test | |
| - name: Configure git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Determine version | |
| id: bump | |
| run: | | |
| OLD_VERSION=$(node -p "require('./package.json').version") | |
| if [ "${{ inputs.bump }}" = "current" ]; then | |
| NEW_VERSION="${OLD_VERSION}" | |
| echo "Publishing current version ${NEW_VERSION}" | |
| else | |
| npm version ${{ inputs.bump }} --no-git-tag-version | |
| NEW_VERSION=$(node -p "require('./package.json').version") | |
| echo "Bumped ${OLD_VERSION} → ${NEW_VERSION} (${{ inputs.bump }})" | |
| fi | |
| echo "old_version=${OLD_VERSION}" >> $GITHUB_OUTPUT | |
| echo "new_version=${NEW_VERSION}" >> $GITHUB_OUTPUT | |
| echo "is_bump=${{ inputs.bump != 'current' }}" >> $GITHUB_OUTPUT | |
| - name: Update CHANGELOG | |
| if: inputs.bump != 'current' | |
| run: | | |
| NEW_VERSION=${{ steps.bump.outputs.new_version }} | |
| DATE=$(date +%Y-%m-%d) | |
| LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") | |
| if [ -n "$LAST_TAG" ]; then | |
| COMMITS=$(git log ${LAST_TAG}..HEAD --pretty=format:"- %s" --no-merges) | |
| else | |
| COMMITS=$(git log --pretty=format:"- %s" --no-merges) | |
| fi | |
| ENTRY="## [${NEW_VERSION}] - ${DATE}\n\n${COMMITS}\n" | |
| if [ -f CHANGELOG.md ]; then | |
| sed -i "0,/^## /s//$(printf '%s\n\n' "${ENTRY}")## /" CHANGELOG.md 2>/dev/null || \ | |
| awk -v entry="$ENTRY" 'NR==1{print; print ""; print entry; next}1' CHANGELOG.md > CHANGELOG.tmp && mv CHANGELOG.tmp CHANGELOG.md | |
| fi | |
| - name: Commit, tag & push | |
| run: | | |
| NEW_VERSION=${{ steps.bump.outputs.new_version }} | |
| git add -A | |
| if git diff --cached --quiet; then | |
| echo "No changes to commit" | |
| else | |
| git commit -m "chore(release): v${NEW_VERSION}" | |
| fi | |
| git tag -a "v${NEW_VERSION}" -m "Release v${NEW_VERSION}" | |
| git push origin main --follow-tags | |
| - name: Publish to npm | |
| run: npm publish --provenance --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: v${{ steps.bump.outputs.new_version }} | |
| name: v${{ steps.bump.outputs.new_version }} | |
| generate_release_notes: true |