chore(release): version packages (#23) #10
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: Publish to npm | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - 'package.json' | |
| - '!.changeset/**' | |
| jobs: | |
| check-version: | |
| name: Check if version changed | |
| runs-on: ubuntu-latest | |
| outputs: | |
| changed: ${{ steps.check.outputs.changed }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 2 | |
| - name: Check if package.json version changed | |
| id: check | |
| run: | | |
| CURRENT_VERSION=$(jq -r .version package.json) | |
| PREVIOUS_VERSION=$(git show HEAD^:package.json | jq -r .version) | |
| if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| fi | |
| publish: | |
| name: Build & Publish | |
| needs: check-version | |
| if: needs.check-version.outputs.changed == 'true' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| id-token: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| cache: npm | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build | |
| run: npm run build | |
| - name: Run tests | |
| run: npm run test:ci | |
| - name: Setup Node.js for publish | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Publish to npm | |
| run: npm publish --provenance --access public | |
| - name: Get package info | |
| id: package | |
| run: | | |
| VERSION=$(jq -r .version package.json) | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Create git tag | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag -a "v${{ steps.package.outputs.version }}" -m "Release v${{ steps.package.outputs.version }}" | |
| git push https://x-access-token:${{ secrets.DISCORD_PAT }}@github.com/${{ github.repository }} "v${{ steps.package.outputs.version }}" | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v3 | |
| with: | |
| tag_name: v${{ steps.package.outputs.version }} | |
| generate_release_notes: true |