Skip to content

Commit 5332f6e

Browse files
authored
fix: make publish-npm its own job with specific permissions (openai#3767)
The build for `v0.37.0-alpha.3` failed on the `Create GitHub Release` step: https://github.com/openai/codex/actions/runs/17786866086/job/50556513221 with: ``` ⚠️ GitHub release failed with status: 403 {"message":"Resource not accessible by integration","documentation_url":"https://docs.github.com/rest/releases/releases#create-a-release","status":"403"} Skip retry — your GitHub token/PAT does not have the required permission to create a release ``` I believe I should have not introduced a top-level `permissions` for the workflow in openai#3431 because that affected the `permissions` for each job in the workflow. This PR introduces `publish-npm` as its own job, which allows us to: - consolidate all the Node.js-related steps required for publishing - limit the reach of the `id-token: write` permission - skip it altogether if is an alpha build With this PR, each of `release`, `publish-npm`, and `update-branch` has an explicit `permissions` block.
1 parent 5d87f5d commit 5332f6e

File tree

1 file changed

+44
-28
lines changed

1 file changed

+44
-28
lines changed

.github/workflows/rust-release.yml

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ on:
1111
tags:
1212
- "rust-v*.*.*"
1313

14-
permissions:
15-
id-token: write # Required for OIDC
16-
1714
concurrency:
1815
group: ${{ github.workflow }}
1916
cancel-in-progress: true
@@ -170,6 +167,12 @@ jobs:
170167
needs: build
171168
name: release
172169
runs-on: ubuntu-latest
170+
permissions:
171+
contents: write
172+
actions: read
173+
outputs:
174+
version: ${{ steps.release_name.outputs.name }}
175+
tag: ${{ github.ref_name }}
173176

174177
steps:
175178
- name: Checkout repository
@@ -190,28 +193,6 @@ jobs:
190193
version="${GITHUB_REF_NAME#rust-v}"
191194
echo "name=${version}" >> $GITHUB_OUTPUT
192195
193-
# Publish to npm using OIDC authentication.
194-
# July 31, 2025: https://github.blog/changelog/2025-07-31-npm-trusted-publishing-with-oidc-is-generally-available/
195-
# npm docs: https://docs.npmjs.com/trusted-publishers
196-
197-
# package.json has `packageManager: "pnpm@`, so we must get pnpm on the
198-
# PATH before setting up Node.js.
199-
- name: Setup pnpm
200-
uses: pnpm/action-setup@v4
201-
with:
202-
run_install: false
203-
204-
- name: Setup Node.js
205-
uses: actions/setup-node@v5
206-
with:
207-
node-version: 22
208-
registry-url: "https://registry.npmjs.org"
209-
scope: "@openai"
210-
211-
# Trusted publishing requires npm CLI version 11.5.1 or later.
212-
- name: Update npm
213-
run: npm install -g npm@latest
214-
215196
- name: Stage npm package
216197
env:
217198
GH_TOKEN: ${{ github.token }}
@@ -245,11 +226,46 @@ jobs:
245226
tag: ${{ github.ref_name }}
246227
config: .github/dotslash-config.json
247228

229+
# Publish to npm using OIDC authentication.
230+
# July 31, 2025: https://github.blog/changelog/2025-07-31-npm-trusted-publishing-with-oidc-is-generally-available/
231+
# npm docs: https://docs.npmjs.com/trusted-publishers
232+
publish-npm:
233+
# Skip this step for pre-releases (alpha/beta).
234+
if: ${{ !contains(needs.release.outputs.version, '-') }}
235+
name: publish-npm
236+
needs: release
237+
runs-on: ubuntu-latest
238+
permissions:
239+
id-token: write # Required for OIDC
240+
contents: read
241+
242+
steps:
243+
- name: Setup Node.js
244+
uses: actions/setup-node@v5
245+
with:
246+
node-version: 22
247+
registry-url: "https://registry.npmjs.org"
248+
scope: "@openai"
249+
250+
# Trusted publishing requires npm CLI version 11.5.1 or later.
251+
- name: Update npm
252+
run: npm install -g npm@latest
253+
254+
- name: Download npm tarball from release
255+
env:
256+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
257+
run: |
258+
set -euo pipefail
259+
version="${{ needs.release.outputs.version }}"
260+
tag="${{ needs.release.outputs.tag }}"
261+
mkdir -p dist/npm
262+
gh release download "$tag" \
263+
--pattern "codex-npm-${version}.tgz" \
264+
--dir dist/npm
265+
248266
# No NODE_AUTH_TOKEN needed because we use OIDC.
249267
- name: Publish to npm
250-
# Do not publish alphas to npm.
251-
if: ${{ !contains(steps.release_name.outputs.name, '-') }}
252-
run: npm publish "${GITHUB_WORKSPACE}/dist/npm/codex-npm-${{ steps.release_name.outputs.name }}.tgz"
268+
run: npm publish "${GITHUB_WORKSPACE}/dist/npm/codex-npm-${{ needs.release.outputs.version }}.tgz"
253269

254270
update-branch:
255271
name: Update latest-alpha-cli branch

0 commit comments

Comments
 (0)