Skip to content

Commit 79b0364

Browse files
committed
ci: publish alpha releases via npm trusted publishing (OIDC)
Make release_alpha.yml self-contained (no longer calls npm_release.yml) and move npm auth from a long-lived NPM_TOKEN to OIDC trusted publishing with provenance. Node 22 + npm 11.5.1 via corepack meet the Trusted Publishing minimums. The version bump commit/tag are still pushed with the PAT secret. beta/latest continue to use npm_release.yml + NPM_TOKEN and are unaffected. Requires a one-time Trusted Publisher registration for @reearth/core on npmjs.com (repo reearth/core, workflow release_alpha.yml) before it runs.
1 parent a907bdf commit 79b0364

1 file changed

Lines changed: 73 additions & 10 deletions

File tree

Lines changed: 73 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,82 @@
1+
# Releases @reearth/core to the `alpha` dist-tag on npm.
2+
#
3+
# Publishing is secured via npm Trusted Publishing (OIDC): no long-lived
4+
# NPM_TOKEN is used, and every publish carries a provenance attestation
5+
# (verify with `npm audit signatures`).
6+
#
7+
# One-time prerequisite (do this BEFORE the first run on the alpha branch):
8+
# On npmjs.com: @reearth/core -> Settings -> Trusted publishers -> add
9+
# Organization/user: reearth
10+
# Repository: core
11+
# Workflow filename: release_alpha.yml
12+
# (Leave environment blank.) This tells npm to accept OIDC tokens minted by
13+
# this exact workflow instead of an NPM_TOKEN secret.
14+
#
15+
# The version bump commit + tag are still pushed to the protected alpha branch
16+
# using the PAT secret (an account that can push directly to alpha). Only the
17+
# npm publish step moved to OIDC; the git push credential is unchanged.
18+
#
19+
# beta/latest still publish via npm_release.yml + NPM_TOKEN and are unaffected.
20+
21+
name: Release Alpha
22+
123
on:
224
push:
325
branches: alpha
426
paths-ignore:
527
- "package.json"
628
workflow_dispatch:
729

30+
permissions:
31+
contents: write # push the version bump commit + tag
32+
id-token: write # mint the OIDC token for npm Trusted Publishing + provenance
33+
834
jobs:
935
release:
10-
permissions:
11-
contents: write
12-
uses: reearth/core/.github/workflows/npm_release.yml@beta
13-
with:
14-
branch: alpha
15-
tag: alpha
16-
version-args: --preid alpha prerelease
17-
secrets:
18-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
19-
PAT: ${{ secrets.PAT }}
36+
runs-on: ubuntu-latest
37+
steps:
38+
- uses: actions/checkout@v4
39+
with:
40+
# PAT (not GITHUB_TOKEN) so the bump commit/tag can be pushed
41+
# directly to the protected alpha branch.
42+
token: ${{ secrets.PAT }}
43+
- uses: actions/setup-node@v4
44+
with:
45+
# Trusted Publishing requires Node >=22.14 and npm >=11.5.1.
46+
node-version: 22
47+
registry-url: "https://registry.npmjs.org"
48+
- name: Activate npm via corepack
49+
# Node 22 ships npm 10.x; Trusted Publishing needs >=11.5.1. corepack
50+
# fetches a fresh npm binary directly, avoiding the broken self-upgrade
51+
# path in the bundled npm 10.x.
52+
run: |
53+
corepack enable npm
54+
corepack prepare npm@11.5.1 --activate
55+
npm --version
56+
- name: Get yarn cache directory path
57+
id: yarn-cache-dir-path
58+
run: echo "path=$(yarn cache dir)" >> $GITHUB_OUTPUT
59+
- uses: actions/cache@v4
60+
with:
61+
path: ${{ steps.yarn-cache-dir-path.outputs.path }}
62+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
63+
restore-keys: |
64+
${{ runner.os }}-yarn-
65+
- name: Run install
66+
run: yarn install --frozen-lockfile
67+
- name: Set up github actions user
68+
run: |
69+
git config --global user.name "keiya01"
70+
git config --global user.email "34934510+keiya01@users.noreply.github.com"
71+
- name: Run npm version
72+
# Triggers the preversion (yarn test run) and version (yarn build) npm
73+
# scripts, so the package is tested and built before publish.
74+
run: npm version --preid alpha prerelease
75+
- name: Git push
76+
run: |
77+
git push origin alpha
78+
git push --tags
79+
- name: Publish to npm with provenance (OIDC)
80+
# No NPM_TOKEN: auth is via the OIDC handshake configured as a Trusted
81+
# Publisher on npmjs.com. --access public because @reearth/core is scoped.
82+
run: npm publish --provenance --access public --tag alpha

0 commit comments

Comments
 (0)