Publish to npm with Provenance #17
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 with Provenance | |
| on: | |
| release: | |
| types: [published] | |
| workflow_dispatch: | |
| inputs: | |
| skip_integration: | |
| description: 'Skip integration tests' | |
| required: false | |
| default: 'false' | |
| jobs: | |
| # Run simulator tests with 100% coverage requirement | |
| test: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Install dependencies | |
| run: npm install | |
| - name: Run tests | |
| run: npm test | |
| # Cross-runtime integration tests | |
| integration: | |
| needs: test | |
| if: github.event.inputs.skip_integration != 'true' | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - runtime: node | |
| version: '18' | |
| - runtime: node | |
| version: '20' | |
| - runtime: node | |
| version: '22' | |
| - runtime: bun | |
| version: 'latest' | |
| - runtime: deno | |
| version: 'v1.x' | |
| runs-on: ubuntu-latest | |
| name: Integration (${{ matrix.runtime }} ${{ matrix.version }}) | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.runtime == 'node' && matrix.version || '20' }} | |
| - name: Setup Bun | |
| if: matrix.runtime == 'bun' | |
| uses: oven-sh/setup-bun@v1 | |
| with: | |
| bun-version: ${{ matrix.version }} | |
| - name: Setup Deno | |
| if: matrix.runtime == 'deno' | |
| uses: denoland/setup-deno@v1 | |
| with: | |
| deno-version: ${{ matrix.version }} | |
| - name: Install dependencies | |
| run: npm install | |
| - name: Run Node.js integration | |
| if: matrix.runtime == 'node' | |
| run: node integration/node/run.js | |
| - name: Run Bun integration | |
| if: matrix.runtime == 'bun' | |
| run: bun run integration/bun/run.ts | |
| - name: Run Deno integration | |
| if: matrix.runtime == 'deno' | |
| run: deno run --allow-all integration/deno/run.ts | |
| # Framework integration tests (Express, Next.js, etc.) | |
| framework-integration: | |
| needs: test | |
| if: github.event.inputs.skip_integration != 'true' | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| framework: [express, nextjs] | |
| runs-on: ubuntu-latest | |
| name: Integration (${{ matrix.framework }}) | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Install main dependencies | |
| run: npm install | |
| - name: Install framework dependencies | |
| run: cd integration/${{ matrix.framework }} && npm install | |
| - name: Run ${{ matrix.framework }} integration | |
| working-directory: integration | |
| run: node ${{ matrix.framework }}/test.js | |
| # Publish to npm (only on release events, not workflow_dispatch) | |
| # workflow_dispatch is for testing the pipeline without publishing | |
| publish: | |
| needs: [test, integration, framework-integration] | |
| if: github.event_name == 'release' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| id-token: write # Required for npm provenance | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Install dependencies | |
| run: npm install | |
| - name: Build browser bundle | |
| run: npx esbuild client/browser.js --bundle --minify --sourcemap --outfile=dist/ape.js | |
| - name: Publish to npm with provenance | |
| run: npm publish --provenance --access public | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |