Skip to content

Commit 973f8b7

Browse files
committed
ci: publish npm packages via npm OIDC provenance
1 parent fc58e8b commit 973f8b7

1 file changed

Lines changed: 31 additions & 17 deletions

File tree

.github/workflows/publish-npm.yml

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
name: Publish to npm
22

3-
# Uses NPM_TOKEN secret for publishing. Caller must pass secrets: inherit.
4-
# TODO: Switch back to npm provenance (tokenless) once we resolve provenance issues.
5-
# Provenance requires id-token: write and --provenance on publish commands.
3+
# We intentionally use npm publish (not bun publish) for releases because npm currently
4+
# provides the trusted publishing OIDC + provenance path used by this workflow.
5+
# Bun remains the package manager/build tool in this repo; npm is used only for final
6+
# registry publication security guarantees.
67

78
on:
89
workflow_call:
@@ -30,8 +31,7 @@ jobs:
3031
needs: [build-binaries]
3132
permissions:
3233
contents: read
33-
env:
34-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
34+
id-token: write # Required so npm can verify GitHub OIDC identity and issue provenance attestations.
3535
steps:
3636
- uses: actions/checkout@v6
3737
with:
@@ -47,7 +47,6 @@ jobs:
4747
uses: actions/setup-node@v5
4848
with:
4949
node-version: '24'
50-
registry-url: 'https://registry.npmjs.org'
5150

5251
- name: Setup Bun
5352
uses: ./.github/actions/setup-bun
@@ -123,7 +122,7 @@ jobs:
123122
- name: Verify packaged binary permissions
124123
run: bash scripts/verify-cli-node-pack-perms.sh
125124

126-
- name: Validate publishable package tarballs
125+
- name: Validate publishable package tarballs (npm parity dry-run)
127126
run: |
128127
set -euo pipefail
129128
for pkg in \
@@ -135,37 +134,52 @@ jobs:
135134
packages/cli-node-linux-arm64-musl \
136135
packages/core \
137136
packages/cli-node; do
138-
echo "Dry-run packing ${pkg}"
139-
bun pm pack --cwd "${pkg}" --dry-run --ignore-scripts >/dev/null
137+
echo "Dry-run publishing ${pkg} with npm provenance"
138+
npm publish --workspace "${pkg}" --dry-run --access public --provenance >/dev/null
140139
done
141140
142141
- name: Build Node packages
143142
run: |
144143
bun run --cwd packages/cli-node build
145144
145+
- name: Verify OIDC environment for npm trusted publishing
146+
run: |
147+
set -euo pipefail
148+
149+
if [[ -z "${ACTIONS_ID_TOKEN_REQUEST_URL:-}" || -z "${ACTIONS_ID_TOKEN_REQUEST_TOKEN:-}" ]]; then
150+
echo "Error: GitHub OIDC token environment is unavailable."
151+
echo "Ensure this job has permissions.id-token=write and runs on a GitHub-hosted runner."
152+
exit 1
153+
fi
154+
155+
echo "OIDC environment detected for npm trusted publishing."
156+
157+
# Use npm publish with --provenance so npm can generate attestations from this
158+
# workflow's OIDC identity. With trusted publishing, npm uses OIDC for auth.
159+
# --provenance preserves explicit attestation intent for this release path.
146160
- name: Publish @opencode-cloud/cli-node-darwin-arm64
147-
run: bun publish --cwd packages/cli-node-darwin-arm64 --access public
161+
run: npm publish --workspace packages/cli-node-darwin-arm64 --access public --provenance
148162

149163
- name: Publish @opencode-cloud/cli-node-darwin-x64
150-
run: bun publish --cwd packages/cli-node-darwin-x64 --access public
164+
run: npm publish --workspace packages/cli-node-darwin-x64 --access public --provenance
151165

152166
- name: Publish @opencode-cloud/cli-node-linux-x64
153-
run: bun publish --cwd packages/cli-node-linux-x64 --access public
167+
run: npm publish --workspace packages/cli-node-linux-x64 --access public --provenance
154168

155169
- name: Publish @opencode-cloud/cli-node-linux-arm64
156-
run: bun publish --cwd packages/cli-node-linux-arm64 --access public
170+
run: npm publish --workspace packages/cli-node-linux-arm64 --access public --provenance
157171

158172
- name: Publish @opencode-cloud/cli-node-linux-x64-musl
159-
run: bun publish --cwd packages/cli-node-linux-x64-musl --access public
173+
run: npm publish --workspace packages/cli-node-linux-x64-musl --access public --provenance
160174

161175
- name: Publish @opencode-cloud/cli-node-linux-arm64-musl
162-
run: bun publish --cwd packages/cli-node-linux-arm64-musl --access public
176+
run: npm publish --workspace packages/cli-node-linux-arm64-musl --access public --provenance
163177

164178
- name: Publish @opencode-cloud/core
165-
run: bun publish --cwd packages/core --access public
179+
run: npm publish --workspace packages/core --access public --provenance
166180

167181
- name: Publish opencode-cloud
168-
run: bun publish --cwd packages/cli-node --access public
182+
run: npm publish --workspace packages/cli-node --access public --provenance
169183

170184
- name: Summary
171185
run: |

0 commit comments

Comments
 (0)