Release #3
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: | |
| release_type: | |
| description: 'Release type' | |
| required: true | |
| default: 'patch' | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| - prerelease | |
| env: | |
| NODE_VERSION: '22' | |
| jobs: | |
| release: | |
| name: Create Release | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| issues: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: latest | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'pnpm' | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Run tests | |
| run: | | |
| pnpm typecheck | |
| pnpm lint | |
| pnpm test:run | |
| pnpm build | |
| - name: Configure git | |
| run: | | |
| git config --local user.email "[email protected]" | |
| git config --local user.name "GitHub Action" | |
| - name: Bump version and create tag | |
| id: version | |
| run: | | |
| # Get current version | |
| CURRENT_VERSION=$(node -p "require('./package.json').version") | |
| echo "Current version: $CURRENT_VERSION" | |
| # Bump version | |
| NEW_VERSION=$(pnpm version ${{ github.event.inputs.release_type }} --no-git-tag-version | tail -1) | |
| NEW_VERSION="${NEW_VERSION#v}" # Remove 'v' prefix if present | |
| echo "New version: $NEW_VERSION" | |
| echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
| echo "tag=v$NEW_VERSION" >> $GITHUB_OUTPUT | |
| - name: Generate changelog | |
| id: changelog | |
| run: | | |
| # Get commits since last tag | |
| LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") | |
| if [ -z "$LAST_TAG" ]; then | |
| COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges) | |
| else | |
| COMMITS=$(git log --pretty=format:"- %s (%h)" --no-merges $LAST_TAG..HEAD) | |
| fi | |
| if [ -z "$COMMITS" ]; then | |
| COMMITS="- Initial release" | |
| fi | |
| # Create changelog | |
| CHANGELOG="## What's Changed | |
| $COMMITS | |
| **Full Changelog**: https://github.com/${{ github.repository }}/compare/$LAST_TAG...v${{ steps.version.outputs.version }}" | |
| # Save to file and output | |
| echo "$CHANGELOG" > changelog.md | |
| echo "changelog<<EOF" >> $GITHUB_OUTPUT | |
| echo "$CHANGELOG" >> $GITHUB_OUTPUT | |
| echo "EOF" >> $GITHUB_OUTPUT | |
| - name: Commit version bump | |
| run: | | |
| git add package.json | |
| git commit -m "chore: bump version to v${{ steps.version.outputs.version }}" | |
| git tag "v${{ steps.version.outputs.version }}" | |
| - name: Push changes | |
| run: | | |
| git push origin main | |
| git push origin "v${{ steps.version.outputs.version }}" | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: "v${{ steps.version.outputs.version }}" | |
| name: "Release v${{ steps.version.outputs.version }}" | |
| body: ${{ steps.changelog.outputs.changelog }} | |
| draft: false | |
| prerelease: ${{ contains(github.event.inputs.release_type, 'prerelease') }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup npm registry | |
| run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc | |
| - name: Publish to npm | |
| run: pnpm publish --access public --no-git-checks |