|
| 1 | +name: Publish to npm |
| 2 | + |
| 3 | +permissions: {} |
| 4 | + |
| 5 | +on: |
| 6 | + release: |
| 7 | + types: [published] |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: |
| 13 | + contents: read |
| 14 | + steps: |
| 15 | + - name: Checkout |
| 16 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 17 | + with: |
| 18 | + persist-credentials: false |
| 19 | + |
| 20 | + - name: Install pnpm |
| 21 | + uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093 # v6.0.8 |
| 22 | + |
| 23 | + - name: Use Node.js 24 |
| 24 | + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 |
| 25 | + with: |
| 26 | + node-version: 24 |
| 27 | + cache: pnpm |
| 28 | + |
| 29 | + - name: Install dependencies |
| 30 | + run: pnpm install --frozen-lockfile --ignore-scripts |
| 31 | + |
| 32 | + - name: Lint code |
| 33 | + run: pnpm lint:src |
| 34 | + |
| 35 | + - name: Lint types |
| 36 | + run: pnpm lint:types |
| 37 | + |
| 38 | + - name: Run tests |
| 39 | + run: pnpm test |
| 40 | + |
| 41 | + - name: Build |
| 42 | + run: pnpm build |
| 43 | + |
| 44 | + - name: Lint exports (attw) |
| 45 | + run: pnpm lint:exports |
| 46 | + |
| 47 | + - name: Lint publish (publint) |
| 48 | + run: pnpm lint:publish |
| 49 | + |
| 50 | + build: |
| 51 | + runs-on: ubuntu-latest |
| 52 | + permissions: |
| 53 | + contents: read |
| 54 | + outputs: |
| 55 | + tarball: ${{ steps.pack.outputs.tarball }} |
| 56 | + steps: |
| 57 | + - name: Checkout |
| 58 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 59 | + with: |
| 60 | + persist-credentials: false |
| 61 | + |
| 62 | + - name: Install pnpm |
| 63 | + uses: pnpm/action-setup@0e279bb959325dab635dd2c09392533439d90093 # v6.0.8 |
| 64 | + |
| 65 | + - name: Use Node.js 24 |
| 66 | + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 |
| 67 | + with: |
| 68 | + node-version: 24 |
| 69 | + cache: pnpm |
| 70 | + |
| 71 | + - name: Install dependencies |
| 72 | + run: pnpm install --frozen-lockfile --ignore-scripts |
| 73 | + |
| 74 | + - name: Build |
| 75 | + run: pnpm build |
| 76 | + |
| 77 | + - name: Align package.json version with release tag |
| 78 | + env: |
| 79 | + TAG_NAME: ${{ github.ref_name }} |
| 80 | + run: npm version "$TAG_NAME" --git-tag-version=false --allow-same-version |
| 81 | + |
| 82 | + - name: Pack tarball |
| 83 | + id: pack |
| 84 | + run: | |
| 85 | + TARBALL=$(npm pack) |
| 86 | + echo "tarball=$TARBALL" >> "$GITHUB_OUTPUT" |
| 87 | +
|
| 88 | + - name: Upload tarball artifact |
| 89 | + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
| 90 | + with: |
| 91 | + name: tarball |
| 92 | + path: ${{ steps.pack.outputs.tarball }} |
| 93 | + |
| 94 | + publish: |
| 95 | + needs: |
| 96 | + - test |
| 97 | + - build |
| 98 | + runs-on: ubuntu-latest |
| 99 | + permissions: |
| 100 | + id-token: write |
| 101 | + environment: publish |
| 102 | + env: |
| 103 | + TARBALL: ${{ needs.build.outputs.tarball }} |
| 104 | + steps: |
| 105 | + - name: Download tarball artifact |
| 106 | + uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0 |
| 107 | + with: |
| 108 | + name: tarball |
| 109 | + |
| 110 | + - name: Use Node.js 24 |
| 111 | + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 |
| 112 | + with: |
| 113 | + node-version: 24 |
| 114 | + registry-url: "https://registry.npmjs.org" |
| 115 | + |
| 116 | + - name: Publish to npm |
| 117 | + env: |
| 118 | + PRERELEASE: ${{ github.event.release.prerelease }} |
| 119 | + run: | |
| 120 | + if [ "$PRERELEASE" = "true" ]; then |
| 121 | + npm publish --provenance --access public --tag next "$TARBALL" |
| 122 | + else |
| 123 | + npm publish --provenance --access public "$TARBALL" |
| 124 | + fi |
0 commit comments