Release #7
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: | |
| push: | |
| branches: [main] | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| name: Build & Publish | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| - name: Check for version change | |
| id: version | |
| run: | | |
| NEW=$(node -p "require('./package.json').version") | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| echo "version=$NEW" >> "$GITHUB_OUTPUT" | |
| echo "Manual dispatch, publishing $NEW" | |
| else | |
| OLD=$(git show HEAD~1:package.json 2>/dev/null | node -p "JSON.parse(require('fs').readFileSync('/dev/stdin','utf8')).version" 2>/dev/null || echo "") | |
| if [ "$NEW" != "$OLD" ]; then | |
| echo "changed=true" >> "$GITHUB_OUTPUT" | |
| echo "version=$NEW" >> "$GITHUB_OUTPUT" | |
| echo "Version changed: $OLD -> $NEW" | |
| else | |
| echo "changed=false" >> "$GITHUB_OUTPUT" | |
| echo "Version unchanged ($NEW), skipping publish" | |
| fi | |
| fi | |
| - uses: pnpm/action-setup@v4 | |
| if: steps.version.outputs.changed == 'true' | |
| with: | |
| version: 10 | |
| - uses: actions/setup-node@v4 | |
| if: steps.version.outputs.changed == 'true' | |
| with: | |
| node-version: 20 | |
| cache: pnpm | |
| registry-url: https://registry.npmjs.org | |
| - name: Install dependencies | |
| if: steps.version.outputs.changed == 'true' | |
| run: pnpm install --frozen-lockfile | |
| - name: Build | |
| if: steps.version.outputs.changed == 'true' | |
| run: pnpm build | |
| - name: Test | |
| if: steps.version.outputs.changed == 'true' | |
| run: pnpm test | |
| - name: Type tests | |
| if: steps.version.outputs.changed == 'true' | |
| run: pnpm test:types | |
| - name: Typecheck | |
| if: steps.version.outputs.changed == 'true' | |
| run: pnpm typecheck | |
| - name: Publish to npm | |
| if: steps.version.outputs.changed == 'true' | |
| run: npm publish --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Create GitHub Release | |
| if: steps.version.outputs.changed == 'true' | |
| run: gh release create "v${{ steps.version.outputs.version }}" --generate-notes | |
| env: | |
| GH_TOKEN: ${{ github.token }} |