Publish to NPM #2
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: | |
| release: | |
| types: [published, released] | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| description: 'Release tag to publish (e.g., v1.0.0)' | |
| required: true | |
| type: string | |
| permissions: | |
| contents: read | |
| id-token: write # Required for NPM provenance | |
| jobs: | |
| publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| registry-url: 'https://registry.npmjs.org' | |
| cache: 'npm' | |
| - name: Cache node-gyp | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cache/node-gyp | |
| ~/.node-gyp | |
| build/ | |
| key: ${{ runner.os }}-node-gyp-20-${{ hashFiles('binding.gyp', 'deps/**') }} | |
| restore-keys: | | |
| ${{ runner.os }}-node-gyp-20- | |
| ${{ runner.os }}-node-gyp- | |
| - name: Install system dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y build-essential cmake | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build native module | |
| run: npm run build | |
| - name: Run tests | |
| run: | | |
| npm test | |
| npm run test-families | |
| npm run test-lazy | |
| - name: Verify package can be packed | |
| run: npm pack --dry-run | |
| - name: Publish to NPM with provenance | |
| run: npm publish --provenance --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| publish-prerelease: | |
| runs-on: ubuntu-latest | |
| if: github.event.release.prerelease | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: recursive | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| registry-url: 'https://registry.npmjs.org' | |
| cache: 'npm' | |
| - name: Cache node-gyp | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cache/node-gyp | |
| ~/.node-gyp | |
| build/ | |
| key: ${{ runner.os }}-node-gyp-20-${{ hashFiles('binding.gyp', 'deps/**') }} | |
| restore-keys: | | |
| ${{ runner.os }}-node-gyp-20- | |
| ${{ runner.os }}-node-gyp- | |
| - name: Install system dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y build-essential cmake | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build native module | |
| run: npm run build | |
| - name: Run tests | |
| run: | | |
| npm test | |
| npm run test-families | |
| npm run test-lazy | |
| - name: Publish prerelease to NPM with beta tag | |
| run: npm publish --tag beta --provenance --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |