Skip to content

Commit 904959b

Browse files
committed
[CI] Publish the npm package on tags via trusted publishing
Add a Release on NPM workflow, modeled on symfony/ux, that publishes @symfony/reprise on a v*.*.* tag push. It uses OIDC trusted publishing (no NPM_TOKEN, id-token: write), verifies the tag is on main, builds with pnpm, and runs pnpm publish --recursive --access public --no-git-checks --provenance. Adapted for Reprise's single package on main (dist is built in CI, not committed).
1 parent b4234fd commit 904959b

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Release on NPM
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
permissions:
9+
id-token: write # Required for OIDC
10+
contents: read
11+
12+
concurrency:
13+
group: release-on-npm-${{ github.ref_name }}
14+
cancel-in-progress: false
15+
16+
jobs:
17+
release:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
21+
with:
22+
ref: ${{ github.ref }}
23+
persist-credentials: false
24+
fetch-depth: 0
25+
26+
- name: Verify tag is on the main branch
27+
run: |
28+
set -euo pipefail
29+
git fetch --no-tags origin refs/heads/main:refs/remotes/origin/main
30+
if ! git merge-base --is-ancestor "${GITHUB_SHA}" refs/remotes/origin/main; then
31+
echo "::error::Tag ${GITHUB_REF_NAME} (${GITHUB_SHA}) is not an ancestor of main. Refusing to publish."
32+
exit 1
33+
fi
34+
echo "Tag ${GITHUB_REF_NAME} verified as ancestor of main."
35+
36+
# Pinned explicitly to avoid pulling a compromised "latest" at release time; bump via dedicated PR.
37+
- run: npm i -g corepack@0.35.0 && corepack enable
38+
# setup-node does not enable any package-manager cache here (no `cache:` input),
39+
# so cache poisoning is not a concern on this release workflow.
40+
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # zizmor: ignore[cache-poisoning] v6.4.0
41+
with:
42+
registry-url: 'https://registry.npmjs.org'
43+
node-version-file: '.nvmrc'
44+
45+
# npm 11.5.1 or later is required for OIDC. Pinned explicitly to avoid
46+
# pulling a compromised "latest" at release time; bump via dedicated PR.
47+
- run: npm install -g npm@11.16.0
48+
49+
- name: Install root JS dependencies
50+
run: pnpm install --frozen-lockfile
51+
52+
- name: Build JS assets
53+
run: pnpm run build
54+
55+
- name: Publish on NPM
56+
run: pnpm publish --recursive --access public --no-git-checks --provenance

0 commit comments

Comments
 (0)