-
Notifications
You must be signed in to change notification settings - Fork 1
502 lines (438 loc) · 17.3 KB
/
publish-everywhere.yml
File metadata and controls
502 lines (438 loc) · 17.3 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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
name: Publish to JSR/NPM/GitHub
on:
workflow_dispatch:
inputs:
version:
description: "Version to publish (e.g., 1.2.3)"
required: true
type: string
release:
types: [published]
push:
tags:
- "v*"
# Job execution order:
# 1. prepare-and-build: Build the package (tests should have passed before tagging)
# 2. publish-jsr: Publish to JSR first (fail-fast if OIDC not working)
# 3. publish-npm: Publish to NPM (only if JSR succeeds)
# 4. publish-github: Publish to GitHub Packages (only if JSR and NPM succeed)
# 5. finalize: Create tags/issues based on results
#
# Note: Tests are not run here as they should have already passed in the
# Tests workflow before a release tag is created.
jobs:
prepare-and-build:
name: Prepare and Build
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
should-publish: ${{ steps.check.outputs.should-publish }}
steps:
- uses: actions/checkout@v4
- name: Init submodules with retry
run: |
for i in 1 2 3; do
if git submodule update --init --recursive; then
echo "✅ Submodules initialized"
exit 0
fi
echo "⚠️ Attempt $i failed, retrying in 10s..."
sleep 10
done
echo "❌ Failed to init submodules after 3 attempts"
exit 1
- name: Verify Tests workflow passed
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Checking if Tests workflow passed for this commit..."
COMMIT_SHA="${{ github.sha }}"
# Get the status of the Tests workflow for this commit
RESULT=$(gh run list --workflow=test.yml --commit=$COMMIT_SHA --json conclusion --limit 1 -q '.[0].conclusion' || echo "not_found")
if [ "$RESULT" = "success" ]; then
echo "✅ Tests workflow passed for commit $COMMIT_SHA"
elif [ "$RESULT" = "not_found" ] || [ -z "$RESULT" ]; then
echo "⚠️ No Tests workflow run found for commit $COMMIT_SHA"
echo "This may be okay if tests were run on a parent commit."
echo "Proceeding with caution..."
else
echo "❌ Tests workflow did not pass (status: $RESULT)"
echo "Please ensure tests pass before releasing."
exit 1
fi
- uses: actions/setup-node@v4
with:
node-version: "22"
cache: "npm"
- name: Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: v2.x
- name: Install dependencies
run: npm install
- name: Install Emscripten
uses: mymindstorm/setup-emsdk@v14
with:
version: latest
- name: Determine version
id: version
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
VERSION="${{ github.event.inputs.version }}"
elif [[ "${{ github.event_name }}" == "release" ]]; then
VERSION="${{ github.event.release.tag_name }}"
elif [[ "$GITHUB_REF" == refs/tags/* ]]; then
VERSION="${GITHUB_REF#refs/tags/}"
else
echo "No version found"
exit 1
fi
# Normalize version (remove 'v' prefix if present)
VERSION="${VERSION#v}"
# Validate version format
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?(\+[a-zA-Z0-9.-]+)?$ ]]; then
echo "Invalid version format: $VERSION"
exit 1
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Version: $VERSION"
- name: Check if should publish
id: check
run: |
VERSION="${{ steps.version.outputs.version }}"
SHOULD_PUBLISH="true"
# Check if version already exists on NPM
if npm view taglib-wasm@$VERSION version 2>/dev/null; then
echo "Version $VERSION already exists on NPM"
SHOULD_PUBLISH="false"
fi
echo "should-publish=$SHOULD_PUBLISH" >> $GITHUB_OUTPUT
- name: Sync versions across files
if: steps.check.outputs.should-publish == 'true'
run: |
VERSION="${{ steps.version.outputs.version }}"
# Use the sync-version script to update all version references
node -e "
const fs = require('fs');
const path = require('path');
// Update package.json
const pkgPath = path.join(__dirname, 'package.json');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
pkg.version = '$VERSION';
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n');
// Update deno.json
const denoPath = path.join(__dirname, 'deno.json');
const deno = JSON.parse(fs.readFileSync(denoPath, 'utf8'));
deno.version = '$VERSION';
fs.writeFileSync(denoPath, JSON.stringify(deno, null, 2) + '\n');
console.log('Updated versions to $VERSION');
"
- name: Build project
if: steps.check.outputs.should-publish == 'true'
run: npm run build
- name: Verify build artifacts
if: steps.check.outputs.should-publish == 'true'
run: |
# Check that all required files exist
test -f dist/index.js || (echo "Missing dist/index.js" && exit 1)
test -f dist/index.d.ts || (echo "Missing dist/index.d.ts" && exit 1)
test -f dist/taglib-web.wasm || (echo "Missing dist/taglib-web.wasm" && exit 1)
test -f dist/taglib-wrapper.js || (echo "Missing dist/taglib-wrapper.js" && exit 1)
# Check file sizes are reasonable
WASM_SIZE=$(stat -c%s dist/taglib-web.wasm 2>/dev/null || stat -f%z dist/taglib-web.wasm)
if [ "$WASM_SIZE" -lt 1000 ]; then
echo "WASM file too small: $WASM_SIZE bytes"
exit 1
fi
- name: Upload build artifacts
if: steps.check.outputs.should-publish == 'true'
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: |
dist/
package.json
deno.json
README.md
LICENSE
retention-days: 1
publish-jsr:
name: Publish to JSR
needs: prepare-and-build
if: needs.prepare-and-build.outputs.should-publish == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # Required for OIDC authentication to JSR
outputs:
published: ${{ steps.publish.outputs.published }}
steps:
- uses: actions/checkout@v4
- uses: denoland/setup-deno@v2
with:
deno-version: v2.x
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: .
- name: Publish to JSR with retry
id: publish
uses: nick-invision/retry@v3
with:
timeout_minutes: 5
max_attempts: 3
retry_wait_seconds: 30
command: |
# Use OIDC for authentication (no token needed)
OUTPUT=$(deno publish --allow-slow-types --allow-dirty 2>&1) && {
echo "JSR publish successful"
echo "published=true" >> $GITHUB_OUTPUT
exit 0
}
# Treat "already published" as success
if echo "$OUTPUT" | grep -qi "already published\|already exists"; then
echo "JSR version already published, continuing"
echo "published=true" >> $GITHUB_OUTPUT
exit 0
fi
echo "JSR publish failed: $OUTPUT"
echo "published=false" >> $GITHUB_OUTPUT
exit 1
on_retry_command: |
echo "Retrying JSR publish..."
publish-npm:
name: Publish to NPM
needs: [prepare-and-build, publish-jsr] # Now depends on JSR success
if: needs.prepare-and-build.outputs.should-publish == 'true' && needs.publish-jsr.outputs.published == 'true'
runs-on: ubuntu-latest
outputs:
published: ${{ steps.publish.outputs.published }}
steps:
- uses: actions/setup-node@v4
with:
node-version: "22"
registry-url: "https://registry.npmjs.org"
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: .
- name: Prepare publish directory
run: |
# Create a clean directory with only files to publish
mkdir -p publish-dir
cp -r dist publish-dir/
cp package.json README.md LICENSE publish-dir/
cd publish-dir
echo "Contents of publish directory:"
ls -la
echo "Contents of dist:"
ls -la dist/
- name: Determine NPM tag
id: npm-tag
run: |
VERSION="${{ needs.prepare-and-build.outputs.version }}"
if [[ "$VERSION" == *-* ]]; then
echo "tag=beta" >> $GITHUB_OUTPUT
else
echo "tag=latest" >> $GITHUB_OUTPUT
fi
- name: Publish to NPM with retry
id: publish
uses: nick-invision/retry@v3
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
with:
timeout_minutes: 5
max_attempts: 3
retry_wait_seconds: 30
command: |
cd publish-dir && npm publish --access public --tag ${{ steps.npm-tag.outputs.tag }}
echo "published=true" >> $GITHUB_OUTPUT
on_retry_command: |
echo "Retrying NPM publish..."
- name: Verify NPM publication
run: |
VERSION="${{ needs.prepare-and-build.outputs.version }}"
sleep 10 # Give NPM time to propagate
for i in {1..5}; do
if npm view taglib-wasm@$VERSION version 2>/dev/null; then
echo "Successfully verified version $VERSION on NPM"
exit 0
fi
echo "Attempt $i: Version not found yet, waiting..."
sleep 10
done
echo "Failed to verify NPM publication"
exit 1
publish-github:
name: Publish to GitHub Packages
needs: [
prepare-and-build,
publish-jsr,
publish-npm,
] # Depends on both JSR and NPM
if: needs.prepare-and-build.outputs.should-publish == 'true' && needs.publish-jsr.outputs.published == 'true' && needs.publish-npm.outputs.published == 'true'
runs-on: ubuntu-latest
outputs:
published: ${{ steps.publish.outputs.published }}
steps:
- uses: actions/setup-node@v4
with:
node-version: "22"
registry-url: "https://npm.pkg.github.com"
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: .
- name: Prepare publish directory
run: |
# Create a clean directory with only files to publish
mkdir -p publish-dir
cp -r dist publish-dir/
cp package.json README.md LICENSE publish-dir/
- name: Update package.json for GitHub
run: |
cd publish-dir
node -e "
const fs = require('fs');
const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
// Update package name for GitHub
pkg.name = '@charleswiltgen/taglib-wasm';
// Remove NPM-specific config
delete pkg.publishConfig;
// Add GitHub registry config
pkg.publishConfig = {
registry: 'https://npm.pkg.github.com'
};
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2) + '\n');
console.log('Updated package.json for GitHub Packages');
"
- name: Determine NPM tag
id: npm-tag
run: |
VERSION="${{ needs.prepare-and-build.outputs.version }}"
if [[ "$VERSION" == *-* ]]; then
echo "tag=beta" >> $GITHUB_OUTPUT
else
echo "tag=latest" >> $GITHUB_OUTPUT
fi
- name: Publish to GitHub with retry
id: publish
uses: nick-invision/retry@v3
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
timeout_minutes: 5
max_attempts: 3
retry_wait_seconds: 30
command: |
cd publish-dir && npm publish --tag ${{ steps.npm-tag.outputs.tag }}
echo "published=true" >> $GITHUB_OUTPUT
on_retry_command: |
echo "Retrying GitHub publish..."
finalize:
name: Finalize Release
needs: [prepare-and-build, publish-jsr, publish-npm, publish-github]
if: always() && needs.prepare-and-build.outputs.should-publish == 'true'
runs-on: ubuntu-latest
permissions:
contents: write # Required to create tags
issues: write # Required to create issues
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Check publication status
id: status
run: |
VERSION="${{ needs.prepare-and-build.outputs.version }}"
SUCCESS=true
FAILURES=""
if [ "${{ needs.publish-npm.outputs.published }}" != "true" ]; then
FAILURES="${FAILURES}NPM "
SUCCESS=false
fi
if [ "${{ needs.publish-github.outputs.published }}" != "true" ]; then
FAILURES="${FAILURES}GitHub "
SUCCESS=false
fi
if [ "${{ needs.publish-jsr.outputs.published }}" != "true" ]; then
FAILURES="${FAILURES}JSR "
SUCCESS=false
fi
echo "success=$SUCCESS" >> $GITHUB_OUTPUT
echo "failures=$FAILURES" >> $GITHUB_OUTPUT
if [ "$SUCCESS" = "true" ]; then
echo "✅ All publications successful for version $VERSION"
else
echo "❌ Failed to publish to: $FAILURES"
fi
- name: Rollback NPM
if: steps.status.outputs.success == 'false' && needs.publish-npm.outputs.published == 'true'
run: |
VERSION="${{ needs.prepare-and-build.outputs.version }}"
echo "⚠️ Rollback required for NPM version $VERSION"
echo "To rollback NPM:"
echo "1. npm unpublish taglib-wasm@$VERSION"
echo "2. Wait 24 hours before republishing the same version"
echo ""
echo "Note: NPM has restrictions on unpublishing. You may need to:"
echo "- Deprecate the version instead: npm deprecate taglib-wasm@$VERSION 'Published in error'"
echo "- Publish a patch version with fixes"
- name: Write failure summary
if: steps.status.outputs.success == 'false'
run: |
VERSION="${{ needs.prepare-and-build.outputs.version }}"
FAILURES="${{ steps.status.outputs.failures }}"
NPM_PUBLISHED="${{ needs.publish-npm.outputs.published }}"
GITHUB_PUBLISHED="${{ needs.publish-github.outputs.published }}"
JSR_PUBLISHED="${{ needs.publish-jsr.outputs.published }}"
{
echo "## ❌ Publication Failed for v${VERSION}"
echo ""
echo "Failed to publish to: ${FAILURES}"
echo ""
echo "### Publication Status"
echo "| Registry | Status |"
echo "|----------|--------|"
echo "| JSR | $([ "$JSR_PUBLISHED" = "true" ] && echo "✅ Published" || echo "❌ Failed") |"
echo "| NPM | $([ "$NPM_PUBLISHED" = "true" ] && echo "✅ Published" || echo "❌ Failed") |"
echo "| GitHub Packages | $([ "$GITHUB_PUBLISHED" = "true" ] && echo "✅ Published" || echo "❌ Failed") |"
echo ""
if [ "$NPM_PUBLISHED" = "true" ] || [ "$GITHUB_PUBLISHED" = "true" ] || [ "$JSR_PUBLISHED" = "true" ]; then
echo "### ⚠️ Rollback Required"
echo ""
if [ "$NPM_PUBLISHED" = "true" ]; then
echo "#### NPM Rollback"
echo '```bash'
echo "# Option 1: Deprecate (recommended)"
echo "npm deprecate taglib-wasm@${VERSION} 'Published in error'"
echo ""
echo "# Option 2: Unpublish (requires waiting 24h to republish)"
echo "npm unpublish taglib-wasm@${VERSION}"
echo '```'
echo ""
fi
if [ "$GITHUB_PUBLISHED" = "true" ]; then
echo "#### GitHub Packages Rollback"
echo "Delete the package version from GitHub Packages UI or use:"
echo '```bash'
echo "gh api -X DELETE /user/packages/npm/@charleswiltgen%2Ftaglib-wasm/versions/VERSION_ID"
echo '```'
echo ""
fi
if [ "$JSR_PUBLISHED" = "true" ]; then
echo "#### JSR Rollback"
echo "JSR does not support unpublishing. Consider publishing a patch version."
echo ""
fi
fi
echo "### Next Steps"
echo "1. Review the workflow logs above for specific error details"
echo "2. Fix the underlying issue"
echo "3. If any registries were published, follow rollback procedures above"
echo "4. Re-run the workflow or publish a new patch version"
} >> $GITHUB_STEP_SUMMARY