Repository navigation
319 lines (302 loc) · 12.9 KB
/
Copy pathrelease.yml
File metadata and controls
319 lines (302 loc) · 12.9 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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
name: Release
# Publishes @diffbot/pi to npm (trusted publishing, with provenance) and
# creates the matching GitHub Release. This file follows the shared npm release
# workflow standard (diffbot-dev-docs: docs/conventions/npm-release-workflow.md);
# keep it in sync with the other npm TypeScript repos.
#
# Jobs: verify (version / tag / CHANGELOG) -> gates -> publish (npm)
# -> github-release; move-next is a separate manual action.
#
# - Pushing a version tag (v1.2.3, v1.2.3-rc.0) is the only thing that publishes.
# - workflow_dispatch (action "dry-run", the default) runs every gate plus
# `npm publish --dry-run` and publishes nothing, even on a tag ref.
# - workflow_dispatch with action "move-next" only re-points the npm `next`
# dist-tag at an already-published version (see the move-next job).
#
# npm auth: trusted publishing (OIDC) only, bound to this file name. No token is
# passed to npm, so a misconfigured trusted publisher fails the publish instead of
# silently using a token.
#
# Versions: any version containing "-" (1.2.0-rc.0) publishes under the "next"
# dist-tag ("latest" is untouched) and its GitHub Release is a prerelease. A final
# version publishes as "latest" and then also moves "next". Release notes come
# from the "## [1.2.0-rc.0]" CHANGELOG section if there is one, otherwise from the
# base version's "## [1.2.0]" section.
#
# Repo-specific: npm + package-lock.json (`npm ci`), not pnpm. The package ships
# TypeScript sources (extensions/, skills/), so there is no build step; the repo
# has no lint or test scripts, so the gates are `npm run typecheck` and `npm pack`.
on:
push:
tags: ["v*"]
workflow_dispatch:
inputs:
action:
description: >-
dry-run: run the release gates and a publish dry run (publishes nothing).
move-next: ONLY point the npm `next` dist-tag at an already-published
version; no build, no publish, no GitHub Release.
type: choice
options: [dry-run, move-next]
default: dry-run
version:
description: >-
move-next only: the already-published version `next` should point at
(e.g. 1.2.3 or 1.2.4-rc.0). Empty = the current `latest`.
type: string
required: false
default: ""
permissions:
contents: read
# Re-pushing a tag (or re-dispatching) queues behind an in-flight run for the same
# ref. A publish must never be cancelled halfway.
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
jobs:
verify:
name: Verify version
# A move-next dispatch runs only the move-next job below.
if: github.event_name != 'workflow_dispatch' || inputs.action != 'move-next'
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
# Fail fast if the tag doesn't match package.json, so npm and the GitHub
# Release can never report different versions. (No VERSION constant in this
# repo's sources.)
- name: Check tag matches package version
id: version
run: |
set -euo pipefail
pkg=$(node -p 'require("./package.json").version')
if [ "${GITHUB_REF_TYPE}" = "tag" ]; then
tag=${GITHUB_REF_NAME#v}
if [ "$pkg" != "$tag" ]; then
echo "::error::Tag v${tag} does not match package.json version ${pkg}. Bump package.json, then re-tag."
exit 1
fi
fi
echo "version=${pkg}" >> "$GITHUB_OUTPUT"
echo "Versions agree: ${pkg}"
# Checked before publishing so a tag without release notes fails before
# anything reaches npm.
- name: Check CHANGELOG.md has a section for this version
env:
VERSION: ${{ steps.version.outputs.version }}
run: |
set -euo pipefail
# A prerelease (1.2.0-rc.0) may reuse its base version's section (1.2.0).
if grep -qF "## [${VERSION}]" CHANGELOG.md; then
echo "Found '## [${VERSION}]'."
elif [ "${VERSION%%-*}" != "${VERSION}" ] && grep -qF "## [${VERSION%%-*}]" CHANGELOG.md; then
echo "Prerelease ${VERSION}: using the '## [${VERSION%%-*}]' section."
else
echo "::error::CHANGELOG.md has no '## [${VERSION}]' section."
exit 1
fi
gates:
name: Gates (typecheck, pack)
needs: verify
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: actions/setup-node@v7
with:
node-version: 22
cache: npm
- run: npm ci
# The repo's only gate (no lint or test scripts; same as ci.yml).
- run: npm run typecheck
# Pack the tarball and list it, so the `files` field is proven to ship
# extensions/, skills/, README and LICENSE.
- name: npm pack
run: |
npm pack --pack-destination "$RUNNER_TEMP"
tar -tzf "$RUNNER_TEMP"/*.tgz
publish:
name: Publish to npm
needs: [verify, gates]
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
id-token: write # npm trusted publishing (OIDC) and provenance
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: actions/setup-node@v7
with:
node-version: 22
registry-url: https://registry.npmjs.org
# Trusted publishing needs npm >= 11.5.1 and `npm dist-tag` over OIDC needs
# >= 11.21.0; Node 22 bundles npm 10. Pinned to a minimum, not `latest`.
- name: Update npm
run: |
npm install -g npm@^11.21.0
npm --version
# No build and no lifecycle scripts: the package ships its sources as-is, so
# nothing needs installing before `npm publish`.
- name: Publish
env:
VERSION: ${{ needs.verify.outputs.version }}
run: |
set -euo pipefail
name=$(node -p 'require("./package.json").name')
# The dist-tag comes from the version, not the tag name: a prerelease
# (1.2.0-rc.0) goes to "next", never "latest".
case "$VERSION" in *-*) dist_tag=next ;; *) dist_tag=latest ;; esac
# Only a tag push publishes. A manual dispatch (even on a tag ref) is a dry run.
# npm >= 11.21 errors on `npm publish --dry-run` if the version is already
# on the registry, so already-published versions are packed only.
if [ "${GITHUB_EVENT_NAME}" != "push" ] || [ "${GITHUB_REF_TYPE}" != "tag" ]; then
echo "Not a tag push: dry run only."
if npm view "${name}@${VERSION}" version >/dev/null 2>&1; then
echo "${name}@${VERSION} is already on npm; packing only."
npm pack --pack-destination "${RUNNER_TEMP}"
tar -tzf "${RUNNER_TEMP}"/*.tgz
else
npm publish --dry-run --access public --tag "$dist_tag"
fi
exit 0
fi
# Lets a failed run be re-run after the npm step already succeeded.
if npm view "${name}@${VERSION}" version >/dev/null 2>&1; then
echo "${name}@${VERSION} is already on npm; skipping publish."
exit 0
fi
# Trusted publishing (OIDC) only; no token is exported.
echo "Publishing ${name}@${VERSION} with dist-tag ${dist_tag} via npm trusted publishing."
npm publish --access public --provenance --tag "$dist_tag"
# A final release also moves `next`, so `next` is never behind `latest`.
# Uses npm trusted publishing (OIDC) for `npm dist-tag`, which needs npm
# >= 11.21.0 / 12.2.0 and "Allow npm dist-tag" enabled on this package's
# trusted publisher at npmjs.com (off by default). The version is already
# published at this point, so a failure only warns and never fails the run.
- name: Point next at final release
if: github.event_name == 'push' && github.ref_type == 'tag'
run: |
set -uo pipefail
name=$(node -p 'require("./package.json").name')
version=$(node -p 'require("./package.json").version')
case "$version" in
*-*) echo "Prerelease ${version}: next was set by publish."; exit 0 ;;
esac
if npm dist-tag add "${name}@${version}" next; then
echo "next -> ${name}@${version}"
else
echo "::warning::Could not point next at ${name}@${version}. Enable 'Allow npm dist-tag' on the trusted publisher for ${name} at npmjs.com, or run: npm dist-tag add ${name}@${version} next"
fi
github-release:
name: Publish GitHub Release
needs: [verify, publish]
runs-on: ubuntu-latest
timeout-minutes: 5
# Only for real tag pushes; a dispatch runs just the gates + publish dry run.
if: github.event_name == 'push' && github.ref_type == 'tag'
permissions:
contents: write
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- name: Extract release notes from CHANGELOG.md
env:
VERSION: ${{ needs.verify.outputs.version }}
run: |
set -euo pipefail
# Everything after "## [VERSION]" up to the next "## " heading. A prerelease
# without its own section uses its base version's section.
hdr_version="${VERSION}"
if ! grep -qF "## [${VERSION}]" CHANGELOG.md; then
hdr_version="${VERSION%%-*}"
fi
awk -v hdr="## [${hdr_version}]" '
index($0, hdr) == 1 { found = 1; next }
found && /^## / { exit }
found { print }
' CHANGELOG.md > "${RUNNER_TEMP}/notes.md"
if ! grep -q '[^[:space:]]' "${RUNNER_TEMP}/notes.md"; then
echo "::error::CHANGELOG.md section for ${VERSION} is empty."
exit 1
fi
wc -l "${RUNNER_TEMP}/notes.md"
- name: Publish release
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.verify.outputs.version }}
run: |
set -euo pipefail
tag="${GITHUB_REF_NAME}"
repo="${GITHUB_REPOSITORY}"
if gh release view "$tag" --repo "$repo" >/dev/null 2>&1; then
echo "Release $tag already exists; leaving its notes as they are."
exit 0
fi
# Any version containing "-" (1.2.0-rc.0) is a GitHub prerelease.
prerelease=()
case "$VERSION" in *-*) prerelease=(--prerelease) ;; esac
gh release create "$tag" \
--repo "$repo" \
--title "$tag" \
--verify-tag \
--notes-file "${RUNNER_TEMP}/notes.md" \
"${prerelease[@]}"
# Manual only (action: move-next). Points `next` at a version that is already
# on npm, e.g. after a final release whose "Point next at final release" step
# warned, or to repair a `next` that fell behind `latest`. It never builds,
# publishes or touches GitHub Releases. It lives in release.yml because the
# package's npm trusted publisher is bound to this workflow file; `npm
# dist-tag` over OIDC needs npm >= 11.21.0 / 12.2.0 and "Allow npm dist-tag"
# enabled on that trusted publisher.
move-next:
name: Move npm next dist-tag
if: github.event_name == 'workflow_dispatch' && inputs.action == 'move-next'
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
id-token: write # npm trusted publishing (OIDC) for `npm dist-tag`
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: actions/setup-node@v7
with:
node-version: 22
registry-url: https://registry.npmjs.org
- name: Update npm
run: |
npm install -g npm@^11.21.0
npm --version
- name: Point next at an existing version
env:
INPUT_VERSION: ${{ inputs.version }}
run: |
set -euo pipefail
name=$(node -p 'require("./package.json").name')
echo "Before: $(npm view "$name" dist-tags --json | tr -d '\n ')"
version="${INPUT_VERSION}"
if [ -z "$version" ]; then
version=$(npm view "$name" dist-tags.latest)
echo "No version given; using the current latest: ${version}"
fi
if ! printf '%s' "$version" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$'; then
echo "::error::'${version}' is not a version like 1.2.3 or 1.2.3-rc.0."
exit 1
fi
if ! npm view "${name}@${version}" version >/dev/null 2>&1; then
echo "::error::${name}@${version} is not on npm; move-next only retags published versions."
exit 1
fi
# Trusted publishing (OIDC) only; no token is exported.
npm dist-tag add "${name}@${version}" next
echo "After: $(npm view "$name" dist-tags --json | tr -d '\n ')"