Publish Package #25
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: Install npm 11+ for OIDC provenance publishing | |
| run: corepack enable npm && corepack install -g npm@latest | |
| env: | |
| COREPACK_ENABLE_STRICT: 0 | |
| - 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: | | |
| pnpm 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 | |
| env: | |
| COREPACK_ENABLE_STRICT: 0 | |
| - 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 }} |