-
-
Notifications
You must be signed in to change notification settings - Fork 2
509 lines (473 loc) · 18.7 KB
/
ci.yml
File metadata and controls
509 lines (473 loc) · 18.7 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
503
504
505
506
507
508
509
name: Build
on:
push:
branches: [main, release/**]
pull_request:
workflow_call:
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
# packages:write is needed for publish-nightly to push to GHCR
permissions:
contents: read
packages: write
env:
# Commit timestamp used for deterministic nightly version strings.
# Defined at workflow level so build-binary and publish-nightly always agree.
COMMIT_TIMESTAMP: ${{ github.event.head_commit.timestamp }}
jobs:
changes:
name: Detect Changes
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
skill: ${{ steps.filter.outputs.skill == 'true' || startsWith(github.ref, 'refs/heads/release/') }}
code: ${{ steps.filter.outputs.code == 'true' || startsWith(github.ref, 'refs/heads/release/') }}
build-targets: ${{ steps.targets.outputs.matrix }}
nightly-version: ${{ steps.nightly.outputs.version }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: filter
with:
filters: |
skill:
- 'src/**'
- 'docs/**'
- 'plugins/**'
- 'script/generate-skill.ts'
code:
- 'src/**'
- 'test/**'
- 'script/**'
- 'patches/**'
- 'docs/**'
- 'plugins/**'
- 'package.json'
- 'bun.lock'
- '.github/workflows/ci.yml'
- name: Compute build matrix
id: targets
run: |
{
echo 'matrix<<MATRIX_EOF'
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
# PRs only need linux-x64 for smoke test and e2e — skip macOS/Windows
echo '{"include":[
{"target":"linux-x64", "os":"ubuntu-latest", "can-test":true}
]}'
else
# main, release/**, workflow_call: full cross-platform matrix
echo '{"include":[
{"target":"darwin-arm64", "os":"macos-latest", "can-test":true},
{"target":"linux-x64", "os":"ubuntu-latest", "can-test":true},
{"target":"windows-x64", "os":"windows-latest","can-test":true},
{"target":"darwin-x64", "os":"macos-latest", "can-test":false},
{"target":"linux-arm64", "os":"ubuntu-latest", "can-test":false}
]}'
fi
echo 'MATRIX_EOF'
} >> "$GITHUB_OUTPUT"
- name: Compute nightly version
id: nightly
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
TS=$(date -d "$COMMIT_TIMESTAMP" +%s)
CURRENT=$(jq -r .version package.json)
VERSION=$(echo "$CURRENT" | sed "s/-dev\.[0-9]*$/-dev.${TS}/")
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "Nightly version: ${VERSION}"
check-skill:
name: Check SKILL.md
needs: [changes]
if: needs.changes.outputs.skill == 'true'
runs-on: ubuntu-latest
steps:
- name: Get auth token
id: token
# Fork PRs don't have access to secrets, so this step is skipped
if: github.event.pull_request.head.repo.full_name == github.repository || github.event_name != 'pull_request'
uses: actions/create-github-app-token@v2.2.1
with:
app-id: ${{ vars.SENTRY_RELEASE_BOT_CLIENT_ID }}
private-key: ${{ secrets.SENTRY_RELEASE_BOT_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
token: ${{ steps.token.outputs.token || github.token }}
ref: ${{ github.head_ref || github.ref_name }}
- uses: oven-sh/setup-bun@v2
- uses: actions/cache@v4
id: cache
with:
path: node_modules
key: node-modules-${{ hashFiles('bun.lock', 'patches/**') }}
- if: steps.cache.outputs.cache-hit != 'true'
run: bun install --frozen-lockfile
- name: Check SKILL.md
id: check
run: bun run check:skill
continue-on-error: true
- name: Auto-commit regenerated SKILL.md
if: steps.check.outcome == 'failure' && steps.token.outcome == 'success'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add plugins/sentry-cli/skills/sentry-cli/SKILL.md
git commit -m "chore: regenerate SKILL.md"
git push
- name: Fail for fork PRs with stale SKILL.md
if: steps.check.outcome == 'failure' && steps.token.outcome != 'success'
run: |
echo "::error::SKILL.md is out of date. Run 'bun run generate:skill' locally and commit the result."
exit 1
lint:
name: Lint & Typecheck
needs: [changes]
if: needs.changes.outputs.code == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- uses: actions/cache@v4
id: cache
with:
path: node_modules
key: node-modules-${{ hashFiles('bun.lock', 'patches/**') }}
- if: steps.cache.outputs.cache-hit != 'true'
run: bun install --frozen-lockfile
- run: bun run lint
- run: bun run typecheck
- run: bun run check:deps
test-unit:
name: Unit Tests
needs: [changes]
if: needs.changes.outputs.code == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
actions: read
pull-requests: write
statuses: write
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- uses: actions/cache@v4
id: cache
with:
path: node_modules
key: node-modules-${{ hashFiles('bun.lock', 'patches/**') }}
- if: steps.cache.outputs.cache-hit != 'true'
run: bun install --frozen-lockfile
- name: Unit Tests
run: bun run test:unit
- name: Isolated Tests
run: bun run test:isolated --coverage --coverage-reporter=lcov --coverage-dir=coverage-isolated
- name: Merge Coverage Reports
run: bun run script/merge-lcov.ts coverage/lcov.info coverage-isolated/lcov.info > coverage/merged.lcov
- name: Coverage Report
uses: getsentry/codecov-action@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
files: ./coverage/merged.lcov
build-binary:
name: Build Binary (${{ matrix.target }})
needs: [changes, lint, test-unit]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.changes.outputs.build-targets) }}
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- uses: actions/cache@v4
id: cache
with:
path: node_modules
key: node-modules-${{ matrix.os }}-${{ hashFiles('bun.lock', 'patches/**') }}
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
shell: bash
run: |
# Retry logic for Windows Bun patch bug (ENOTEMPTY errors)
for i in 1 2 3; do
if bun install --frozen-lockfile; then
exit 0
fi
echo "Attempt $i failed, clearing Bun cache and retrying..."
bun pm cache rm 2>/dev/null || true
done
echo "All install attempts failed"
exit 1
- name: Set nightly version
# Inject the nightly version (computed once in the changes job) into
# package.json before the build so it gets baked into the binary.
if: needs.changes.outputs.nightly-version != ''
shell: bash
run: |
jq --arg v "${{ needs.changes.outputs.nightly-version }}" '.version = $v' package.json > package.json.tmp
mv package.json.tmp package.json
- name: Build
env:
SENTRY_CLIENT_ID: ${{ vars.SENTRY_CLIENT_ID }}
# Set on main/release branches so build.ts runs binpunch + creates .gz
RELEASE_BUILD: ${{ github.event_name != 'pull_request' && '1' || '' }}
run: bun run build --target ${{ matrix.target }}
- name: Smoke test
if: matrix.can-test
shell: bash
run: |
if [[ "${{ matrix.target }}" == "windows-x64" ]]; then
./dist-bin/sentry-windows-x64.exe --help
else
./dist-bin/sentry-${{ matrix.target }} --help
fi
- name: Upload binary artifact
uses: actions/upload-artifact@v4
with:
name: sentry-${{ matrix.target }}
path: |
dist-bin/sentry-*
!dist-bin/*.gz
- name: Upload compressed artifact
if: github.event_name != 'pull_request'
uses: actions/upload-artifact@v4
with:
name: sentry-${{ matrix.target }}-gz
path: dist-bin/*.gz
publish-nightly:
name: Publish Nightly to GHCR
# Only run on pushes to main, not on PRs or release branches
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
needs: [changes, build-binary]
runs-on: ubuntu-latest
steps:
- name: Download compressed artifacts
uses: actions/download-artifact@v4
with:
pattern: sentry-*-gz
path: artifacts
merge-multiple: true
- name: Download uncompressed artifacts (for patch generation)
uses: actions/download-artifact@v4
with:
pattern: sentry-*
path: binaries
merge-multiple: true
- name: Install ORAS CLI
run: |
VERSION=1.2.3
EXPECTED_SHA256="b4efc97a91f471f323f193ea4b4d63d8ff443ca3aab514151a30751330852827"
TARBALL="oras_${VERSION}_linux_amd64.tar.gz"
curl -sfLo "$TARBALL" "https://github.com/oras-project/oras/releases/download/v${VERSION}/${TARBALL}"
echo "${EXPECTED_SHA256} ${TARBALL}" | sha256sum -c -
tar -xz -C /usr/local/bin oras < "$TARBALL"
rm "$TARBALL"
- name: Install zig-bsdiff
run: |
VERSION=0.1.19
EXPECTED_SHA256="9f1ac75a133ee09883ad2096a86d57791513de5fc6f262dfadee8dcee94a71b9"
TARBALL="zig-bsdiff-linux-x64.tar.gz"
curl -sfLo "$TARBALL" "https://github.com/blackboardsh/zig-bsdiff/releases/download/v${VERSION}/${TARBALL}"
echo "${EXPECTED_SHA256} ${TARBALL}" | sha256sum -c -
tar -xz -C /usr/local/bin < "$TARBALL"
rm "$TARBALL"
- name: Log in to GHCR
run: echo "${{ secrets.GITHUB_TOKEN }}" | oras login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push to GHCR
# Push from inside the artifacts directory so ORAS records bare
# filenames (e.g. "sentry-linux-x64.gz") as layer titles, not
# "artifacts/sentry-linux-x64.gz". The CLI matches layers by
# filename in findLayerByFilename().
working-directory: artifacts
run: |
VERSION="${{ needs.changes.outputs.nightly-version }}"
oras push ghcr.io/getsentry/cli:nightly \
--artifact-type application/vnd.sentry.cli.nightly \
--annotation "org.opencontainers.image.source=https://github.com/getsentry/cli" \
--annotation "version=${VERSION}" \
*.gz
- name: Tag versioned nightly
# Create an immutable versioned tag via zero-copy oras tag.
# This enables patch chain resolution to find specific nightly versions.
run: |
VERSION="${{ needs.changes.outputs.nightly-version }}"
oras tag ghcr.io/getsentry/cli:nightly "nightly-${VERSION}"
- name: Generate and push delta patches
# Download the previous nightly's binaries, generate TRDIFF10 patches,
# and push a :patch-<version> manifest with SHA-256 annotations.
# Failure here is non-fatal — delta upgrades are optional.
continue-on-error: true
run: |
VERSION="${{ needs.changes.outputs.nightly-version }}"
REPO="ghcr.io/getsentry/cli"
# Find the previous nightly by listing versioned tags and picking
# the one immediately before ours in version-sorted order.
TAGS=$(oras repo tags "${REPO}" 2>/dev/null | grep '^nightly-' | sort -V || echo "")
PREV_TAG=""
for tag in $TAGS; do
if [ "$tag" = "nightly-${VERSION}" ]; then
break
fi
PREV_TAG="$tag"
done
if [ -z "$PREV_TAG" ]; then
echo "No previous versioned nightly found, skipping patches"
exit 0
fi
PREV_VERSION="${PREV_TAG#nightly-}"
echo "Generating patches: ${PREV_VERSION} → ${VERSION}"
# Download previous nightly binaries
mkdir -p prev-binaries
PREV_MANIFEST_JSON=$(oras manifest fetch "${REPO}:${PREV_TAG}")
# Extract .gz layer digests and download + decompress each
echo "$PREV_MANIFEST_JSON" | jq -r '.layers[] | select(.annotations["org.opencontainers.image.title"] | endswith(".gz")) | .annotations["org.opencontainers.image.title"] + " " + .digest' | while read -r filename digest; do
basename="${filename%.gz}"
echo " Downloading previous ${basename}..."
oras blob fetch "${REPO}@${digest}" --output "prev-binaries/${filename}"
gunzip -f "prev-binaries/${filename}"
done
# Generate patches and compute SHA-256 hashes of NEW binaries
mkdir -p patches
ANNOTATIONS=""
PATCH_FILES=""
for new_binary in binaries/sentry-*; do
basename=$(basename "$new_binary")
# Skip .gz files
case "$basename" in *.gz) continue ;; esac
old_binary="prev-binaries/${basename}"
if [ ! -f "$old_binary" ]; then
echo " No previous binary for ${basename}, skipping"
continue
fi
patch_file="patches/${basename}.patch"
echo " Generating patch for ${basename}..."
bsdiff "$old_binary" "$new_binary" "$patch_file" --use-zstd
# Compute SHA-256 of the NEW (target) binary for verification
sha256=$(sha256sum "$new_binary" | cut -d' ' -f1)
ANNOTATIONS="${ANNOTATIONS} --annotation sha256-${basename}=${sha256}"
PATCH_FILES="${PATCH_FILES} ${basename}.patch"
done
if [ -z "$PATCH_FILES" ]; then
echo "No patches generated"
exit 0
fi
# Push patch manifest with from-version and SHA-256 annotations
cd patches
eval oras push "${REPO}:patch-${VERSION}" \
--artifact-type application/vnd.sentry.cli.patch \
--annotation "from-version=${PREV_VERSION}" \
${ANNOTATIONS} \
${PATCH_FILES}
echo "Pushed patch manifest: patch-${VERSION} (from ${PREV_VERSION})"
test-e2e:
name: E2E Tests
needs: [build-binary]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- uses: actions/cache@v4
id: cache
with:
path: node_modules
key: node-modules-${{ hashFiles('bun.lock', 'patches/**') }}
- if: steps.cache.outputs.cache-hit != 'true'
run: bun install --frozen-lockfile
- name: Download Linux binary
uses: actions/download-artifact@v4
with:
name: sentry-linux-x64
path: dist-bin
- name: Make binary executable
run: chmod +x dist-bin/sentry-linux-x64
- name: E2E Tests
env:
SENTRY_CLI_BINARY: ${{ github.workspace }}/dist-bin/sentry-linux-x64
run: bun run test:e2e
build-npm:
name: Build npm Package (Node ${{ matrix.node }})
needs: [lint, test-unit]
runs-on: ubuntu-latest
environment: ${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/')) && 'production' || '' }}
strategy:
fail-fast: false
matrix:
node: ["22", "24"]
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- uses: actions/cache@v4
id: cache
with:
path: node_modules
key: node-modules-${{ hashFiles('bun.lock', 'patches/**') }}
- if: steps.cache.outputs.cache-hit != 'true'
run: bun install --frozen-lockfile
- name: Bundle
env:
SENTRY_CLIENT_ID: ${{ vars.SENTRY_CLIENT_ID }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
run: bun run bundle
- name: Smoke test (Node.js)
run: node dist/bin.cjs --help
- run: npm pack
- name: Upload artifact
if: matrix.node == '22'
uses: actions/upload-artifact@v4
with:
name: npm-package
path: "*.tgz"
build-docs:
name: Build Docs
needs: [lint]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2
- name: Build Docs
working-directory: docs
run: |
bun install --frozen-lockfile
bun run build
- name: Package Docs
run: |
cp .nojekyll docs/dist/
cd docs/dist && zip -r ../../gh-pages.zip .
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: gh-pages
path: gh-pages.zip
ci-status:
name: CI Status
if: always()
needs: [changes, check-skill, build-binary, build-npm, build-docs, test-e2e, publish-nightly]
runs-on: ubuntu-latest
permissions: {}
steps:
- name: Check CI status
run: |
# Check for explicit failures or cancellations in all jobs
# publish-nightly is skipped on PRs (if: github.ref == 'refs/heads/main') — that's expected
results="${{ needs.check-skill.result }} ${{ needs.build-binary.result }} ${{ needs.build-npm.result }} ${{ needs.build-docs.result }} ${{ needs.test-e2e.result }} ${{ needs.publish-nightly.result }}"
for result in $results; do
if [[ "$result" == "failure" || "$result" == "cancelled" ]]; then
echo "::error::CI failed"
exit 1
fi
done
# Detect upstream failures: if changes were detected but jobs were skipped,
# it means an upstream job failed (skipped jobs cascade to dependents)
if [[ "${{ needs.changes.outputs.code }}" == "true" && "${{ needs.test-e2e.result }}" == "skipped" ]]; then
echo "::error::CI failed - upstream job failed causing test-e2e to be skipped"
exit 1
fi
if [[ "${{ needs.changes.outputs.skill }}" == "true" && "${{ needs.check-skill.result }}" == "skipped" ]]; then
echo "::error::CI failed - upstream job failed causing check-skill to be skipped"
exit 1
fi
echo "CI passed"