Publish Package #4
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 Package | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| version_type: | |
| description: "Version bump type" | |
| required: true | |
| default: "patch" | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| jobs: | |
| publish: | |
| name: Publish package | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| id-token: write # needed for OIDC token generation | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| cache: "pnpm" | |
| - name: Update npm for OIDC support | |
| run: npm install -g npm@latest # Needs 11.5.1+ for npm trusted publishing | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Run unit tests | |
| run: pnpm test:unit | |
| - name: Build package | |
| run: pnpm build | |
| - name: Configure git (for version bump) | |
| if: github.event_name == 'workflow_dispatch' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Bump version and create tag | |
| if: github.event_name == 'workflow_dispatch' | |
| id: version | |
| run: | | |
| npm version ${{ github.event.inputs.version_type }} | |
| echo "new_version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT | |
| git push --follow-tags | |
| - name: Publish to npm | |
| run: npm publish --provenance | |
| - name: Create GitHub release (manual trigger only) | |
| if: github.event_name == 'workflow_dispatch' | |
| run: | | |
| gh release create v${{ steps.version.outputs.new_version }} \ | |
| --title "Release v${{ steps.version.outputs.new_version }}" \ | |
| --generate-notes | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |