-
Notifications
You must be signed in to change notification settings - Fork 2
284 lines (241 loc) 路 8.5 KB
/
Copy pathrelease.yml
File metadata and controls
284 lines (241 loc) 路 8.5 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
name: Release
on:
push:
tags:
- "v*.*.*"
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
permissions: {}
jobs:
package:
name: Verify And Package
runs-on: ubuntu-latest
permissions:
contents: read
env:
HUSKY: 0
outputs:
name: ${{ steps.metadata.outputs.name }}
version: ${{ steps.metadata.outputs.version }}
tarball: ${{ steps.metadata.outputs.tarball }}
sha256: ${{ steps.checksum.outputs.sha256 }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0
persist-credentials: false
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6
with:
version: 11.17.0
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
with:
node-version: 24
cache: pnpm
- name: Install
run: pnpm install --frozen-lockfile
- name: Verify Tag Matches Package Version
id: metadata
shell: bash
run: |
set -euo pipefail
PACKAGE_NAME="$(node -p "require('./package.json').name")"
PACKAGE_VERSION="$(node -p "require('./package.json').version")"
if [[ ! "${PACKAGE_VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Only stable semantic versions can be released"
exit 1
fi
if [ "${GITHUB_REF_NAME}" != "v${PACKAGE_VERSION}" ]; then
echo "::error::Tag ${GITHUB_REF_NAME} does not match package version ${PACKAGE_VERSION}"
exit 1
fi
if ! git merge-base --is-ancestor "${GITHUB_SHA}" "origin/main"; then
echo "::error::Release commit is not on the main branch"
exit 1
fi
{
echo "name=${PACKAGE_NAME}"
echo "version=${PACKAGE_VERSION}"
echo "tarball=${PACKAGE_NAME}-${PACKAGE_VERSION}.tgz"
} >> "${GITHUB_OUTPUT}"
- name: Full Verification
run: pnpm run verify
- name: Create Release Tarball
id: checksum
shell: bash
env:
TARBALL: ${{ steps.metadata.outputs.tarball }}
run: |
set -euo pipefail
pnpm pack --out "${TARBALL}"
test -s "${TARBALL}"
SHA256="$(sha256sum "${TARBALL}")"
echo "sha256=${SHA256%% *}" >> "${GITHUB_OUTPUT}"
- name: Upload Release Tarball
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: npm-package
path: ${{ steps.metadata.outputs.tarball }}
if-no-files-found: error
retention-days: 14
e2e:
name: Playwright E2E
needs: package
runs-on: ubuntu-latest
permissions:
contents: read
env:
HUSKY: 0
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- uses: pnpm/action-setup@0ebf47130e4866e96fce0953f49152a61190b271 # v6
with:
version: 11.17.0
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
with:
node-version: 24
cache: pnpm
- name: Install
run: pnpm install --frozen-lockfile
- name: Download Release Tarball
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: npm-package
- name: Verify And Extract Packaged Build
shell: bash
env:
SHA256: ${{ needs.package.outputs.sha256 }}
TARBALL: ${{ needs.package.outputs.tarball }}
run: |
set -euo pipefail
printf '%s %s\n' "${SHA256}" "${TARBALL}" | sha256sum --check --strict
rm -rf dist dist-browser
tar -xzf "${TARBALL}" --strip-components=1
test -s dist/index.cjs
test -s dist/index.mjs
test -s dist-browser/index.min.js
- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps chromium firefox webkit
- name: E2E
run: pnpm run e2e:all
publish:
name: Publish To Npm
needs: [package, e2e]
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7
with:
node-version: 24
registry-url: "https://registry.npmjs.org"
- name: Download Release Tarball
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: npm-package
- name: Verify Release Tarball
shell: bash
env:
SHA256: ${{ needs.package.outputs.sha256 }}
TARBALL: ${{ needs.package.outputs.tarball }}
run: |
set -euo pipefail
printf '%s %s\n' "${SHA256}" "${TARBALL}" | sha256sum --check --strict
- name: Check Published Version
id: registry
env:
PACKAGE_NAME: ${{ needs.package.outputs.name }}
PACKAGE_VERSION: ${{ needs.package.outputs.version }}
TARBALL: ${{ needs.package.outputs.tarball }}
run: |
node --input-type=module <<'NODE'
import { createHash } from "node:crypto";
import { appendFile, readFile } from "node:fs/promises";
const { GITHUB_OUTPUT, PACKAGE_NAME, PACKAGE_VERSION, TARBALL } =
process.env;
const url =
"https://registry.npmjs.org/" +
`${encodeURIComponent(PACKAGE_NAME)}/` +
encodeURIComponent(PACKAGE_VERSION);
const response = await fetch(url, {
headers: { accept: "application/json" },
});
if (response.status === 404) {
await appendFile(GITHUB_OUTPUT, "exists=false\n");
process.exit(0);
}
if (!response.ok) {
throw new Error(`npm registry returned HTTP ${response.status}`);
}
const metadata = await response.json();
const bytes = await readFile(TARBALL);
const localIntegrity =
"sha512-" + createHash("sha512").update(bytes).digest("base64");
if (metadata?.dist?.integrity !== localIntegrity) {
throw new Error(
`${PACKAGE_NAME}@${PACKAGE_VERSION} already exists with different contents`,
);
}
await appendFile(GITHUB_OUTPUT, "exists=true\n");
console.log(
`${PACKAGE_NAME}@${PACKAGE_VERSION} already exists; skipping publish`,
);
NODE
- name: Publish Release Tarball
if: steps.registry.outputs.exists != 'true'
env:
TARBALL: ${{ needs.package.outputs.tarball }}
run: npm publish "./${TARBALL}" --access public --provenance
github-release:
name: Create GitHub Release
needs: [package, publish]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
fetch-depth: 0
persist-credentials: false
- name: Download Release Tarball
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: npm-package
- name: Verify Release Tarball
shell: bash
env:
SHA256: ${{ needs.package.outputs.sha256 }}
TARBALL: ${{ needs.package.outputs.tarball }}
run: |
set -euo pipefail
printf '%s %s\n' "${SHA256}" "${TARBALL}" | sha256sum --check --strict
- name: Generate Changelog
shell: bash
run: |
set -euo pipefail
TAG="${GITHUB_REF_NAME}"
PREV_TAG="$(git describe --tags --abbrev=0 --match 'v*.*.*' "${TAG}^" 2>/dev/null || true)"
{
echo "## ${TAG}"
echo
if [ -n "${PREV_TAG}" ]; then
echo "Changes since ${PREV_TAG}:"
echo
git log "${PREV_TAG}..${TAG}" --pretty=format:'- %s (%h)'
else
echo "Changes:"
echo
git log "${TAG}" --pretty=format:'- %s (%h)'
fi
echo
} > RELEASE_NOTES.md
- name: Create Or Update GitHub Release
uses: softprops/action-gh-release@3d0d9888cb7fd7b750713d6e236d1fcb99157228 # v3
with:
body_path: RELEASE_NOTES.md
files: ${{ needs.package.outputs.tarball }}
fail_on_unmatched_files: true
overwrite_files: true