Publish to npm #1
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: | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| inputs: | |
| dry_run: | |
| description: 'Dry-run only (skip the actual publish)' | |
| type: boolean | |
| default: false | |
| permissions: | |
| contents: read | |
| id-token: write # required for npm provenance attestations | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: pnpm/action-setup@v4 | |
| with: | |
| version: 9 | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'pnpm' | |
| registry-url: 'https://registry.npmjs.org' | |
| - run: pnpm install --frozen-lockfile | |
| - name: Verify tag matches package.json version | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| run: | | |
| TAG="${GITHUB_REF#refs/tags/v}" | |
| PKG=$(node -p "require('./packages/ui/package.json').version") | |
| if [ "$TAG" != "$PKG" ]; then | |
| echo "::error::Git tag v$TAG does not match package.json version $PKG" | |
| exit 1 | |
| fi | |
| echo "Tag and package.json agree on $PKG" | |
| - run: pnpm --filter @kidcash/ui test -- --run | |
| - run: pnpm --filter @kidcash/ui build | |
| - name: Publish (dry run) | |
| if: github.event_name == 'workflow_dispatch' && inputs.dry_run | |
| run: npm publish --access public --provenance --dry-run | |
| working-directory: packages/ui | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| - name: Publish | |
| if: "!(github.event_name == 'workflow_dispatch' && inputs.dry_run)" | |
| run: npm publish --access public --provenance | |
| working-directory: packages/ui | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |