Skip to content
Source
Sign inSign up
TanStack/schemas
Open History to see the last commit

publish.yml

117 lines3.2 KB

1# Stage public workspace packages to npm via OIDC trusted publishing.
2#
3# No NPM_TOKEN. The npm CLI (not bun) exchanges a GitHub OIDC token for a
4# short-lived, stage-only credential. A maintainer then 2FA-approves each
5# staged version on npmjs.com. See README "Releasing on npm".
6#
7# Trusted-publisher config on every package MUST match:
8# repository: modelschemas/modelschemas
9# workflow filename: publish.yml
10# environment: npm
11# allowed action: npm stage publish only
12name: Publish
13​
14on:
15 push:
16 tags:
17 - 'v[0-9]*'
18 workflow_dispatch:
19 inputs:
20 dry_run:
21 description: Pack and verify tarballs; do not call npm stage publish
22 type: boolean
23 default: true
24​
25concurrency:
26 group: npm-publish
27 cancel-in-progress: false
28​
29permissions: {}
30​
31jobs:
32 ci:
33 uses: ./.github/workflows/ci.yml
34 permissions:
35 contents: read
36​
37 pack:
38 needs: ci
39 runs-on: ubuntu-latest
40 permissions:
41 contents: read
42 actions: write
43 steps:
44 - uses: actions/checkout@v5
45 with:
46 persist-credentials: false
47​
48 - uses: oven-sh/setup-bun@v2
49​
50 - name: Install dependencies
51 run: bun install --frozen-lockfile
52​
53 - name: Pack public packages
54 env:
55 RELEASE_TAG: ${{ github.ref_type == 'tag' && github.ref_name || '' }}
56 run: bun scripts/npm-pack.ts --pack-dir dist/npm
57​
58 - uses: actions/upload-artifact@v4
59 with:
60 name: npm-tarballs
61 path: dist/npm/*.tgz
62 if-no-files-found: error
63 retention-days: 7
64​
65 stage:
66 needs: pack
67 if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && !inputs.dry_run)
68 runs-on: ubuntu-latest
69 environment: npm
70 permissions:
71 contents: read
72 id-token: write
73 actions: read
74 steps:
75 - uses: actions/download-artifact@v4
76 with:
77 name: npm-tarballs
78 path: tarballs
79​
80 - uses: actions/setup-node@v6
81 with:
82 node-version: '24'
83 registry-url: 'https://registry.npmjs.org'
84 package-manager-cache: false
85​
86 - name: Install npm 11.19.0 (stage needs >= 11.15; npm 12 needs Node 24.15+)
87 run: npm install -g npm@11.19.0
88​
89 - name: Require npm >= 11.15.0
90 run: |
91 v=$(npm --version)
92 echo "npm $v"
93 maj=${v%%.*}
94 rest=${v#*.}
95 min=${rest%%.*}
96 if [ "$maj" -lt 11 ] || { [ "$maj" -eq 11 ] && [ "$min" -lt 15 ]; }; then
97 echo "npm >= 11.15.0 required for npm stage publish, got $v" >&2
98 exit 1
99 fi
100​
101 - name: Stage tarballs
102 working-directory: tarballs
103 run: |
104 shopt -s nullglob
105 tarballs=(*.tgz)
106 if [ ${#tarballs[@]} -eq 0 ]; then
107 echo "no tarballs downloaded" >&2
108 exit 1
109 fi
110 for tgz in "${tarballs[@]}"; do
111 echo "staging $tgz"
112 npm stage publish "$tgz" --access public
113 done
114 echo "Staged ${#tarballs[@]} package(s). Approve with 2FA at"
115 echo "https://www.npmjs.com/ (Staged Packages), in order:"
116 echo " @modelschemas/client, @modelschemas/codegen,"
117 echo " @modelschemas/rate-card, @modelschemas/vite, modelschemas"