Repository navigation
282 lines (266 loc) · 13.4 KB
/
Copy pathrelease.yml
File metadata and controls
282 lines (266 loc) · 13.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
name: Auto-release
# Publishes a release when its release PR merges (#1650). A merged
# `chore: release ...` PR lands `changelog/<pkg>/<v>.md` files on main; the CI
# run for that push (ci.yml, `name: CI`) completing GREEN triggers this job
# through `workflow_run`, and it publishes every changelog file the commit
# added:
# 1. to npm.com via scripts/publish-npm.js (OIDC, with provenance),
# 2. to GitHub Packages via scripts/publish-github-packages.js,
# 3. as GitHub Releases via scripts/publish-release.js,
# 4. and the unscoped wrappers in lockstep when @webjsdev/cli moved.
# A push that adds no changelog file stops after a checkout and a git diff.
# The CDN purge is not here: purge-cdn.yml runs for every push to main (#1652).
#
# The other triggers are the manual and recovery paths: scripts/release.sh
# pushes `publish-<sha12>` at a release commit (it was the ONLY path between
# #1594 and #1650, when CI ran locally), and workflow_dispatch keeps the
# recovery inputs (republish_paths, lockstep_only, bootstrap_github_packages)
# for a publish that died. Everything is idempotent: a version already on a
# registry and a release that already exists are skipped, so an automatic
# run followed by release.sh, or a re-push of the tag, never duplicates.
# npm auth is TRUSTED PUBLISHING (OIDC), so there is no NPM_TOKEN
# secret to store, rotate, or let expire. Each of the 8 published
# packages carries its own Trusted Publisher configuration on
# npmjs.com naming owner `webjsdev`, repo `webjs`, and workflow
# `release.yml`. Renaming THIS FILE breaks every publish until all
# 8 are updated, and it fails as an opaque 404 on the publish PUT
# rather than as an auth error. See framework-dev.md.
on:
# The automatic path: CI finished on a push to main. The job's `if:` keeps
# only a GREEN run for a PUSH (a PR's CI run and a red run never publish).
# `workflows` must match the `name:` of .github/workflows/ci.yml exactly; a
# renamed CI workflow silently stops every release, which
# test/repo-health/release-workflow-trigger.test.mjs guards.
workflow_run:
workflows: [CI]
types: [completed]
branches: [main]
push:
tags:
- 'publish-*'
workflow_dispatch:
inputs:
bootstrap_github_packages:
description: 'Republish every existing changelog file to GitHub Packages (one-time bootstrap; npm.com + GH Releases steps are skipped)'
type: boolean
default: false
lockstep_only:
description: 'Only (re)publish the unscoped wrappers (create-webjs, webjsdev) at the current @webjsdev/cli version. Use to recover a release whose wrapper publish did not land.'
type: boolean
default: false
republish_paths:
description: 'Space or comma separated changelog paths to (re)publish to npm, e.g. "changelog/core/0.7.52.md changelog/server/0.8.66.md". Recovery path for a release whose npm publish failed. Leave empty for a normal run.'
type: string
default: ''
permissions:
contents: write # gh release create (scripts/publish-release.js)
packages: write # npm publish to GitHub Packages
id-token: write # mint the OIDC credential npm trusted publishing exchanges
# One release run per commit: an automatic run and a manually pushed tag for
# the same commit queue rather than race the registry checks.
concurrency:
group: release-${{ github.event.workflow_run.head_sha || github.sha }}
cancel-in-progress: false
jobs:
release:
if: >-
github.event_name != 'workflow_run' ||
(github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'push')
runs-on: ubuntu-latest
steps:
# Pinned to v6: both actions ship a Node 24 runtime, which is
# what GitHub Actions will default to from June 2nd, 2026. v4
# / v5 ran on Node 20 and triggered the deprecation banner.
# On workflow_run the default ref is the CURRENT tip of main, which may
# have moved past the commit CI just passed; check out that exact commit
# so `HEAD~1..HEAD` below is what the release PR added.
- uses: actions/checkout@v6
with:
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
fetch-depth: 2
- name: Find new changelog files
id: diff
run: |
set -euo pipefail
# Three modes:
# 1. push event: diff HEAD~1..HEAD for newly added changelog files.
# 2. workflow_dispatch with bootstrap_github_packages=true: list
# every changelog/**.md file currently in the tree. The
# publish-github-packages.js step is idempotent (skips
# already-published versions) so a re-run is safe.
# 3. workflow_dispatch with republish_paths set: publish exactly
# the named files. This is the recovery path for a release
# whose npm publish failed, and it exists because RE-RUNNING
# the failed run does NOT work: a re-run replays the workflow
# file from its ORIGINAL commit, so a run that predates a fix
# to this file never sees the fix. Every publish script is
# idempotent, so naming an already-published version is a
# no-op rather than an error.
BOOTSTRAP='${{ inputs.bootstrap_github_packages }}'
REPUBLISH='${{ inputs.republish_paths }}'
if [ -n "$REPUBLISH" ]; then
# Validate every path BEFORE publishing anything: a typo that
# silently published nothing would look identical to success.
mapfile -t REQUESTED < <(printf '%s' "$REPUBLISH" | tr ', ' '\n\n' | grep -v '^$')
for f in "${REQUESTED[@]}"; do
if [ ! -f "$f" ]; then
echo "republish_paths: no such changelog file: $f" >&2
exit 1
fi
done
# Sort the requested set by `date:` ASC exactly as the push path
# does, so core still publishes before server and the npm
# `latest` tag lands on the newest version rather than whichever
# was typed last.
mapfile -t NEW < <(
printf '%s\n' "${REQUESTED[@]}" \
| while read -r f; do
ts=$(awk '/^date:/ { print $2; exit }' "$f")
printf '%s\t%s\n' "$ts" "$f"
done \
| sort -k1,1 -k2,2r \
| cut -f2-
)
elif [ "$BOOTSTRAP" = 'true' ]; then
mapfile -t NEW < <(
find changelog -name '*.md' -not -name 'README.md' \
| while read -r f; do
ts=$(awk '/^date:/ { print $2; exit }' "$f")
printf '%s\t%s\n' "$ts" "$f"
done \
| sort -k1,1 -k2,2r \
| cut -f2-
)
else
# Sort by the `date:` timestamp inside each file's
# frontmatter, ASCending. GitHub Releases lists releases by
# created_at DESC, so publishing oldest-first means newest
# entries end up at the top of the Releases page.
#
# Within tied timestamps (multiple packages bumped in one
# PR), sort the filename DESC so the alphabetically-first
# package publishes LAST, gets the latest created_at, and
# ends up at the top of the GH list. The website's
# /changelog page iterates package dirs alphabetically
# too, so this produces matching order on both surfaces.
mapfile -t NEW < <(
git diff --name-only --diff-filter=A HEAD~1 HEAD -- 'changelog/**.md' \
| while read -r f; do
ts=$(awk '/^date:/ { print $2; exit }' "$f")
printf '%s\t%s\n' "$ts" "$f"
done \
| sort -k1,1 -k2,2r \
| cut -f2-
)
fi
if [ ${#NEW[@]} -eq 0 ]; then
echo "No new changelog files in this push; skipping."
echo "count=0" >> "$GITHUB_OUTPUT"
exit 0
fi
printf ' + %s\n' "${NEW[@]}"
printf '%s\n' "${NEW[@]}" > .new-changelog-files.txt
echo "count=${#NEW[@]}" >> "$GITHUB_OUTPUT"
echo "bootstrap=$BOOTSTRAP" >> "$GITHUB_OUTPUT"
# `registry-url` is REQUIRED for trusted publishing, not optional
# decoration: it writes the .npmrc that points npm at the registry
# the OIDC exchange authenticates against. Removing it breaks the
# exchange even though no token is involved any more.
#
# Node 24 bundles npm 11.19.x, which clears trusted publishing's
# npm >= 11.5.1 floor. Do NOT add `npm install -g npm@latest` to
# "make sure npm is new enough": npm `latest` is 12.x, and npm 12
# turns on the install-time security defaults (`allowScripts` off),
# which blocks esbuild's postinstall, which means packages/core/dist
# never builds. The bundled 11.19.x satisfies OIDC without opting
# into that.
# Runs before setup and install so a push with no new changelog file
# (most CI runs on main) costs a checkout and a git diff, nothing more.
- uses: actions/setup-node@v6
if: steps.diff.outputs.count != '0' || inputs.lockstep_only
with:
node-version: '24'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
if: steps.diff.outputs.count != '0' || inputs.lockstep_only
run: npm install --no-audit --no-fund
# No NODE_AUTH_TOKEN: this publishes via npm trusted publishing
# (OIDC). The npm CLI detects the Actions OIDC environment and
# exchanges the job's id-token for a short-lived, workflow-scoped
# credential before it would ever fall back to a token, so
# scripts/publish-npm.js needs no change (its auth comment already
# says it relies on standard npm publish token resolution).
#
# Each of the 8 published packages has a Trusted Publisher
# configured on npmjs.com naming owner `webjsdev`, repo `webjs`,
# and workflow `release.yml`. Renaming this FILE therefore breaks
# every publish until those 8 configurations are updated to match.
- name: Publish to npm
if: steps.diff.outputs.count != '0' && steps.diff.outputs.bootstrap != 'true'
run: |
set -euo pipefail
while IFS= read -r f; do
[ -z "$f" ] && continue
node scripts/publish-npm.js "$f"
done < .new-changelog-files.txt
- name: Publish to GitHub Packages
if: steps.diff.outputs.count != '0'
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
while IFS= read -r f; do
[ -z "$f" ] && continue
node scripts/publish-github-packages.js "$f"
done < .new-changelog-files.txt
# After both registries, in the same date-sorted order, so the newest
# release lands at the top of the Releases page. Idempotent: an existing
# `<pkg>@<version>` release is skipped (scripts/release.sh creates the
# same releases when it is the path that published).
- name: Create GitHub Releases
if: steps.diff.outputs.count != '0' && steps.diff.outputs.bootstrap != 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
while IFS= read -r f; do
[ -z "$f" ] && continue
node scripts/publish-release.js "$f"
done < .new-changelog-files.txt
- name: Lockstep-publish wrappers to match @webjsdev/cli
if: inputs.lockstep_only || (steps.diff.outputs.count != '0' && steps.diff.outputs.bootstrap != 'true')
run: |
set -euo pipefail
# In a normal release run, only proceed if a cli changelog
# landed in this push. The lockstep_only dispatch skips this
# gate (there is no .new-changelog-files.txt to consult).
if [ "${{ inputs.lockstep_only }}" != "true" ]; then
if ! grep -q '^changelog/cli/' .new-changelog-files.txt; then
echo "No new @webjsdev/cli changelog in this push; skipping wrapper lockstep."
exit 0
fi
fi
CLI_VERSION=$(node -p "require('./packages/cli/package.json').version")
echo "Lockstep-publishing create-webjs + webjsdev at @webjsdev/cli@${CLI_VERSION}"
for pkg in create-webjs webjsdev; do
# Set the version + cli dep range in the runner's working
# tree only (never committed). npm publish reads from here.
node -e "
const fs = require('node:fs');
const path = './packages/wrappers/${pkg}/package.json';
const j = JSON.parse(fs.readFileSync(path, 'utf8'));
j.version = '${CLI_VERSION}';
if (j.dependencies && j.dependencies['@webjsdev/cli']) {
j.dependencies['@webjsdev/cli'] = '^${CLI_VERSION}';
}
fs.writeFileSync(path, JSON.stringify(j, null, 2) + '\n');
"
REMOTE=$(npm view "${pkg}@${CLI_VERSION}" version 2>/dev/null || echo "")
if [ "$REMOTE" = "${CLI_VERSION}" ]; then
echo " skip ${pkg}@${CLI_VERSION}: already on registry"
else
echo " publishing ${pkg}@${CLI_VERSION}..."
npm publish --workspace="${pkg}" --access=public --ignore-scripts=false
fi
done