Repository navigation
700 lines (625 loc) · 32.6 KB
/
Copy pathrelease.yml
File metadata and controls
700 lines (625 loc) · 32.6 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
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
# Builds the tsrs binaries and the WebAssembly module, publishes the npm packages, then creates the GitHub release,
# using docs/releases/<crate version>.md for its notes. Use cargo-release-oxc to bump Cargo and the private root package.json together;
# Cargo and npm use the same TypeScript-aligned version. The conformance and fourslash gates run here on the BOLT-optimized
# GNU binaries (.github/scripts/bolt.sh). The macOS and Windows binaries get the smoke tests below; Windows also
# trains on the conformance suite. The broader WebAssembly differential gate
# (tools/wasm/gate.sh) remains available locally.
#
# Setup before the first release:
# - npm trusted publishers for `tsrs`, `@tsrs/wasm` and every platform package: GitHub Actions,
# repository oxc-project/tsrs, workflow release.yml, no environment, with direct publishing allowed.
# - Cargo and root package.json versions bumped together with `cargo release-oxc update --release crates --version <version>`.
# Provenance (`pnpm publish --provenance`) is only possible from a public repository; it is enabled automatically
# when the repository is public and skipped while it is private.
name: Release
on:
push:
branches: [main]
paths: [Cargo.toml, package.json]
workflow_dispatch:
inputs:
dry_run:
description: "Build, test and pack, but run `pnpm publish --dry-run`"
type: boolean
default: true
# One release per ref at a time; never cancel a publish half-way.
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
jobs:
version:
if: github.repository == 'oxc-project/tsrs'
runs-on: ubuntu-latest
outputs:
release: ${{ github.event_name == 'workflow_dispatch' || steps.check.outputs.changed == 'true' }}
version: ${{ steps.v.outputs.version }}
crate_version: ${{ steps.v.outputs.crate_version }}
dist_tag: ${{ steps.v.outputs.dist_tag }}
ts_commit: ${{ steps.v.outputs.ts_commit }}
ts_nightly: ${{ steps.v.outputs.ts_nightly }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false
- name: Set up Node
uses: oxc-project/setup-node@f46a72f95efdc55273fcd042d61c84e723b2892c # v1.4.1
with:
registry-url: ""
- name: Check coordinated version changes
if: github.event_name == 'push'
id: versions
env:
BEFORE_SHA: ${{ github.event.before }}
run: node tools/release/version-changed.mjs --before "$BEFORE_SHA"
- name: Check for an unpublished npm version
if: github.event_name == 'push' && steps.versions.outputs.changed == 'true'
id: check
run: |
node --input-type=module <<'JS'
import fs from "node:fs";
import { execFileSync } from "node:child_process";
const version = execFileSync("node", ["npm/build.mjs", "--print-version"], { encoding: "utf8" }).trim();
const response = await fetch(`https://registry.npmjs.org/tsrs/${encodeURIComponent(version)}`, {
signal: AbortSignal.timeout(30000),
});
if (!response.ok && response.status !== 404) throw new Error(`npm registry returned HTTP ${response.status}`);
fs.appendFileSync(process.env.GITHUB_OUTPUT, `changed=${response.status === 404}\n`);
JS
- name: Validate release version and notes
if: github.event_name == 'workflow_dispatch' || steps.check.outputs.changed == 'true'
id: v
env:
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run }}
run: |
if [ "$DRY_RUN" != true ] && [ "$GITHUB_REF" != refs/heads/main ]; then
echo "::error::Real releases must run from main."
exit 1
fi
version=$(node npm/build.mjs --print-version)
crate_version=$(node npm/build.mjs --print-crate-version)
root_version=$(node -p 'require("./package.json").version')
[ "$root_version" = "$crate_version" ] || { echo "::error::package.json version $root_version does not match Cargo version $crate_version"; exit 1; }
node --input-type=module <<'JS'
import fs from "node:fs";
import { distTag, readVersions, validateReleaseVersion } from "./tools/release/version.mjs";
const release = readVersions(process.cwd());
validateReleaseVersion(release.version, release.typescriptVersion);
fs.appendFileSync(process.env.GITHUB_OUTPUT, `dist_tag=${distTag(release.version)}\n`);
JS
test -s "docs/releases/$crate_version.md" || { echo "::error::Missing release notes for $crate_version"; exit 1; }
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "crate_version=$crate_version" >> "$GITHUB_OUTPUT"
echo "ts_commit=$(node npm/build.mjs --print-typescript-commit)" >> "$GITHUB_OUTPUT"
echo "ts_nightly=$(node npm/build.mjs --print-typescript-nightly)" >> "$GITHUB_OUTPUT"
# The binaries stamp Cargo.toml's `nightly` npm package version. Its gitHead must equal the pinned commit
# or be a later commit with no tsc/ changes; otherwise tsbuildinfo could claim another tsgo's version.
- name: Check the TypeScript package against the pinned commit
if: github.event_name == 'workflow_dispatch' || steps.check.outputs.changed == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
nightly=$(node npm/build.mjs --print-typescript-nightly)
commit=$(node npm/build.mjs --print-typescript-commit)
head=$(npm view "typescript@$nightly" gitHead)
if [ "$head" != "$commit" ]; then
compare=$(gh api "repos/microsoft/TypeScript/compare/$commit...$head" \
--jq '"\(.behind_by) \([.files[].filename | select(startswith("tsc/"))] | length)"')
[ "$compare" = "0 0" ] || {
echo "::error::typescript@$nightly was built from $head, which is not $commit plus changes outside tsc/ ($compare)"
exit 1
}
fi
# Release binaries are PGO builds with the `release` profile (fat LTO, one codegen unit; Cargo.toml): an instrumented
# ThinLTO build of tsrs + tsrs-test + fourslash_server, the training workload (.github/scripts/pgo-train.sh: the conformance and Go fourslash suites
# and two open-source bench projects), then the final build with the merged profile. Numbers: notes/perf-pgo.md.
# On Linux the final build is then optimized with BOLT (.github/scripts/bolt.sh; notes/perf-build-level.md), and
# the conformance and fourslash gates run on BOLT-optimized binaries before the binary is staged.
build:
name: build ${{ matrix.target }}
needs: version
if: needs.version.outputs.release == 'true'
env:
# TypeScript's version in the binary (Cargo.toml [workspace.metadata.typescript] matching npm package).
TSRS_TS_VERSION: ${{ needs.version.outputs.ts_nightly }}
TSRS_CARGO_FEATURES: tsrs_cli/noembed
# PGO requires matching profile settings. BOLT needs symbols until its final strip.
CARGO_PROFILE_RELEASE_STRIP: ${{ contains(matrix.target, 'linux') && 'none' || 'symbols' }}
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}
timeout-minutes: 150
strategy:
fail-fast: false
matrix:
include:
- { target: aarch64-apple-darwin, os: macos-latest, experimental: false, run: true }
# Train PGO and smoke-test the installed package natively on Intel macOS.
- { target: x86_64-apple-darwin, os: macos-26-intel, experimental: false, run: true }
# Built on 22.04 so the binary needs at most glibc 2.35.
- { target: x86_64-unknown-linux-gnu, os: ubuntu-22.04, experimental: false, run: true }
- { target: aarch64-unknown-linux-gnu, os: ubuntu-22.04-arm, experimental: false, run: true }
steps:
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2
# Training needs conformance fixtures and the Go fourslash source at the pinned commit.
- name: Check out TypeScript source and testdata
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: microsoft/TypeScript
ref: ${{ needs.version.outputs.ts_commit }}
path: ts-ref
fetch-depth: 1
sparse-checkout: tsc
persist-credentials: false
- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: ts-ref/tsc/go.mod
cache: false
# The bench projects of the training workload install with their pinned package managers via pnpm (bench/bench.mjs prepare).
# No .npmrc: the default registry-url writes one with `_authToken=${NODE_AUTH_TOKEN}`, and yarn 1 (webpack's
# install in the PGO training run) refuses to run while that variable is unset. Only `publish` needs the registry.
- uses: oxc-project/setup-node@f46a72f95efdc55273fcd042d61c84e723b2892c # v1.4.1
with:
registry-url: ""
- uses: oxc-project/setup-rust@3d6fb132fbe7cdcb66bf8ec193911c2945369d12 # v1.0.17
with:
restore-cache: false
components: llvm-tools
- run: rustup target add ${{ matrix.target }}
# The instrumented build and training state live outside target/, so the final build cannot reuse them.
# CFLAGS: cc passes -Cprofile-generate/-use on to clang (macOS) but not to gcc (Linux). Apple clang's profile
# format does not match rustc's LLVM (the instrumented mimalloc crashed in __llvm_profile_instrument_target
# with rustc 1.99), so the C code (mimalloc) is built without PGO, as on Linux.
- name: Instrumented build
shell: bash
env:
# Override rustc's LTO, not Cargo's profile: Cargo hashes profile settings into the symbols PGO matches.
RUSTFLAGS: -Cprofile-generate=${{ runner.temp }}/pgo/raw -Clto=thin
CFLAGS: ${{ runner.os == 'macOS' && '-fno-profile-generate' || '' }}
CARGO_TARGET_DIR: ${{ runner.temp }}/pgo/target
# tsrs-test embeds libraries, Go supplies the task server's VFS, and the CLI uses disk libraries.
# Build together so their compiler symbols match for PGO.
run: cargo build --release --locked -p tsrs_cli -p tsrs_testrunner -p tsrs_fourslash_server --bins --features "$TSRS_CARGO_FEATURES" --target ${{ matrix.target }}
- name: Training run
shell: bash
env:
TSRS_LIB_PATH: ${{ github.workspace }}/crates/tsrs_vfs/libs
run: .github/scripts/pgo-train.sh "$RUNNER_TEMP/pgo/target/${{ matrix.target }}/release" "$RUNNER_TEMP/pgo/raw" "$RUNNER_TEMP/pgo/bench"
- name: Merge profiles
id: profile
shell: bash
run: |
profdata="$(rustc --print sysroot)/lib/rustlib/$(rustc -vV | sed -n 's/^host: //p')/bin/llvm-profdata"
"$profdata" merge -o "$RUNNER_TEMP/pgo/merged.profdata" "$RUNNER_TEMP"/pgo/raw/*.profraw
"$profdata" show "$RUNNER_TEMP/pgo/merged.profdata" | tail -5
# The profile's hash is part of its path, and so of RUSTFLAGS: cargo rebuilds dependencies whenever the
# profile changes.
sum=$(shasum -a 256 "$RUNNER_TEMP/pgo/merged.profdata" | cut -c1-16)
mv "$RUNNER_TEMP/pgo/merged.profdata" "$RUNNER_TEMP/pgo/$sum.profdata"
echo "path=$RUNNER_TEMP/pgo/$sum.profdata" >> "$GITHUB_OUTPUT"
# Linux: --emit-relocs keeps the relocations BOLT needs to move code (the code itself is unchanged), and the
# test runners are built too so that the BOLT step can run the gates on BOLT-optimized binaries.
- name: cargo build
shell: bash
env:
RUSTFLAGS: -Cprofile-use=${{ steps.profile.outputs.path }}${{ runner.os == 'Linux' && ' -Clink-arg=-Wl,--emit-relocs' || '' }}
CFLAGS: ${{ runner.os == 'macOS' && '-fno-profile-use' || '' }}
run: |
targets=(-p tsrs_cli)
[ "$RUNNER_OS" = Linux ] && targets+=(-p tsrs_testrunner -p tsrs_fourslash_server --bins)
cargo build --release --locked "${targets[@]}" --features "$TSRS_CARGO_FEATURES" --target ${{ matrix.target }}
# BOLT from the LLVM release that matches rustc's LLVM. The tarball's tools need glibc 2.34 (22.04 has 2.35).
- name: Read BOLT version
if: runner.os == 'Linux'
id: llvm
shell: bash
run: |
llvm=$(rustc -vV | sed -n 's/^LLVM version: //p')
test -n "$llvm"
echo "version=$llvm" >> "$GITHUB_OUTPUT"
- name: Cache BOLT
if: runner.os == 'Linux'
id: bolt-cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: |
${{ runner.temp }}/llvm/bin/llvm-bolt
${{ runner.temp }}/llvm/bin/merge-fdata
${{ runner.temp }}/llvm/lib/libbolt_rt_instr.a
key: release-bolt-v1-${{ matrix.os }}-${{ runner.arch }}-${{ steps.llvm.outputs.version }}
- name: Install BOLT
if: runner.os == 'Linux' && steps.bolt-cache.outputs.cache-hit != 'true'
shell: bash
env:
LLVM_VERSION: ${{ steps.llvm.outputs.version }}
run: |
arch=X64; [ "$(uname -m)" = aarch64 ] && arch=ARM64
name="LLVM-$LLVM_VERSION-Linux-$arch"
mkdir -p "$RUNNER_TEMP/llvm"
curl -fsSL "https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VERSION/$name.tar.zst" |
zstd -d --long=30 |
tar -x -C "$RUNNER_TEMP/llvm" --strip-components=1 --wildcards \
"$name/bin/llvm-bolt" "$name/bin/merge-fdata" "$name/lib/libbolt_rt_instr.a"
- name: Configure BOLT
if: runner.os == 'Linux'
shell: bash
run: |
test -x "$RUNNER_TEMP/llvm/bin/llvm-bolt"
test -x "$RUNNER_TEMP/llvm/bin/merge-fdata"
test -s "$RUNNER_TEMP/llvm/lib/libbolt_rt_instr.a"
echo "$RUNNER_TEMP/llvm/bin" >> "$GITHUB_PATH"
- name: BOLT and gates on the BOLT-optimized binaries
if: runner.os == 'Linux'
shell: bash
env:
TSRS_LIB_PATH: ${{ github.workspace }}/crates/tsrs_vfs/libs
run: .github/scripts/bolt.sh "target/${{ matrix.target }}/release" "$RUNNER_TEMP/bolt" "$RUNNER_TEMP/pgo/bench"
- name: Stage binary
shell: bash
env:
TSRS_LIB_PATH: ${{ github.workspace }}/crates/tsrs_vfs/libs
run: |
exe=tsrs; [ "${{ matrix.target }}" = x86_64-pc-windows-msvc ] && exe=tsrs.exe
mkdir -p "out/${{ matrix.target }}"
cp "target/${{ matrix.target }}/release/$exe" "out/${{ matrix.target }}/$exe"
if [ "${{ matrix.run }}" = true ]; then
"out/${{ matrix.target }}/$exe" --version | tee version.txt
grep -q "^Version $TSRS_TS_VERSION (" version.txt || { echo "::error::the binary is not stamped with TypeScript $TSRS_TS_VERSION"; exit 1; }
printf 'const x: number = "no";\n' > bad.ts
set +e; "out/${{ matrix.target }}/$exe" bad.ts; status=$?; set -e
[ "$status" = 2 ] || { echo "expected exit 2 for a type error, got $status"; exit 1; }
fi
- name: Installed-package smoke (CLI, SDK LSP and Node API)
shell: bash
run: |
node npm/build.mjs --artifacts out --pack
node npm/sdk/smoke-consumer.mjs --noembed
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: bin-${{ matrix.target }}
path: out/
if-no-files-found: error
# The Windows profile trains compiler code through tsrs-test and the native CLI. The Unix
# Fourslash bridge and benchmark installers are not used on Windows.
build-windows:
name: build ${{ matrix.target }}
needs: version
if: needs.version.outputs.release == 'true'
runs-on: ${{ matrix.os }}
timeout-minutes: 180
strategy:
fail-fast: false
matrix:
include:
- { target: x86_64-pc-windows-msvc, os: windows-latest }
- { target: aarch64-pc-windows-msvc, os: windows-11-arm }
env:
TSRS_TS_VERSION: ${{ needs.version.outputs.ts_nightly }}
CARGO_PROFILE_RELEASE_STRIP: symbols
steps:
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2
- name: Check out TypeScript testdata
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
repository: microsoft/TypeScript
ref: ${{ needs.version.outputs.ts_commit }}
path: ts-ref
fetch-depth: 1
sparse-checkout: tsc/testdata
persist-credentials: false
- uses: oxc-project/setup-node@f46a72f95efdc55273fcd042d61c84e723b2892c # v1.4.1
with:
registry-url: ""
- uses: oxc-project/setup-rust@3d6fb132fbe7cdcb66bf8ec193911c2945369d12 # v1.0.17
with:
restore-cache: false
components: llvm-tools
- run: rustup target add ${{ matrix.target }}
- name: Select linker for Windows ARM64 profiles
if: matrix.target == 'aarch64-pc-windows-msvc'
shell: pwsh
run: |
# link.exe pads LLVM's one-byte profile section markers on ARM64, corrupting profiles.
$hostTriple = (rustc -vV | Select-String '^host: ').ToString().Substring(6)
$linker = Join-Path (rustc --print sysroot) "lib/rustlib/$hostTriple/bin/rust-lld.exe"
if (-not (Test-Path $linker)) { throw "missing rust-lld at $linker" }
"CARGO_TARGET_AARCH64_PC_WINDOWS_MSVC_LINKER=$linker" >> $env:GITHUB_ENV
- name: Instrumented build
shell: pwsh
run: |
$raw = Join-Path $env:RUNNER_TEMP "pgo/raw"
New-Item -ItemType Directory -Force $raw | Out-Null
$env:CARGO_TARGET_DIR = Join-Path $env:RUNNER_TEMP "pgo/target"
# Override rustc's LTO while keeping Cargo's release profile identical to the final build.
$env:CARGO_ENCODED_RUSTFLAGS = @("-Cprofile-generate=$raw", "-Clto=thin") -join [char]31
cargo build --release --locked -p tsrs_cli -p tsrs_testrunner --bins --features tsrs_cli/noembed --target ${{ matrix.target }}
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
- name: Training run
shell: pwsh
run: |
$bin = Join-Path $env:RUNNER_TEMP "pgo/target/${{ matrix.target }}/release"
$raw = Join-Path $env:RUNNER_TEMP "pgo/raw"
& ./.github/scripts/pgo-train-windows.ps1 -BinDir $bin -RawDir $raw
- name: Upload Windows conformance results
if: ${{ !cancelled() }}
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: windows-conformance-results-${{ matrix.target }}
path: ${{ runner.temp }}/pgo/test-results/
if-no-files-found: ignore
- name: Merge profiles
id: profile
shell: pwsh
run: |
$hostTriple = (rustc -vV | Select-String '^host: ').ToString().Substring(6)
$profdata = Join-Path (rustc --print sysroot) "lib/rustlib/$hostTriple/bin/llvm-profdata.exe"
if (-not (Test-Path $profdata)) { throw "missing llvm-profdata at $profdata" }
$raw = Join-Path $env:RUNNER_TEMP "pgo/raw"
$profiles = @(Get-ChildItem $raw -Filter "*.profraw" | Where-Object Length -gt 0 | ForEach-Object FullName)
if ($profiles.Count -eq 0) { throw "no nonempty profiles" }
$merged = Join-Path $env:RUNNER_TEMP "pgo/merged.profdata"
& $profdata merge -o $merged @profiles
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
& $profdata show $merged | Select-Object -Last 5
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
$sum = (Get-FileHash $merged -Algorithm SHA256).Hash.Substring(0, 16).ToLowerInvariant()
$profile = Join-Path $env:RUNNER_TEMP "pgo/$sum.profdata"
Move-Item $merged $profile
[System.IO.File]::AppendAllText($env:GITHUB_OUTPUT, "path=$profile`n")
- name: Final PGO build
shell: pwsh
env:
PROFILE_PATH: ${{ steps.profile.outputs.path }}
run: |
$env:CARGO_ENCODED_RUSTFLAGS = "-Cprofile-use=$env:PROFILE_PATH"
cargo build --release --locked -p tsrs_cli --features tsrs_cli/noembed --target ${{ matrix.target }}
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
- name: Stage and smoke binary
shell: pwsh
run: |
$target = "${{ matrix.target }}"
$out = Join-Path $env:GITHUB_WORKSPACE "out/$target"
New-Item -ItemType Directory -Force $out | Out-Null
$exe = Join-Path $out "tsrs.exe"
Copy-Item "target/$target/release/tsrs.exe" $exe
$env:TSRS_LIB_PATH = Join-Path $env:GITHUB_WORKSPACE "crates/tsrs_vfs/libs"
$version = & $exe --version
if ($LASTEXITCODE -ne 0 -or -not $version.StartsWith("Version $env:TSRS_TS_VERSION (")) {
throw "unexpected version: $version"
}
Set-Content -Path (Join-Path $env:RUNNER_TEMP "bad.ts") -Value 'const x: number = "no";'
& $exe --noEmit --ignoreConfig (Join-Path $env:RUNNER_TEMP "bad.ts")
if ($LASTEXITCODE -ne 2) { throw "expected exit 2 for a type error, got $LASTEXITCODE" }
exit 0
- name: Installed-package smoke (CLI and SDK LSP)
shell: pwsh
run: |
node npm/build.mjs --artifacts out --pack
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
node npm/sdk/smoke-consumer.mjs --noembed --cli-only
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: bin-${{ matrix.target }}
path: out/
if-no-files-found: error
check:
needs: version
if: needs.version.outputs.release == 'true'
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2
- uses: oxc-project/setup-rust@3d6fb132fbe7cdcb66bf8ec193911c2945369d12 # v1.0.17
with:
restore-cache: false
- run: cargo check --locked
# Musl uses static dist builds without PGO/BOLT.
build-musl:
needs: version
if: needs.version.outputs.release == 'true'
env:
# TypeScript's version in the binary (Cargo.toml [workspace.metadata.typescript] matching npm package).
TSRS_TS_VERSION: ${{ needs.version.outputs.ts_nightly }}
TSRS_CARGO_FEATURES: tsrs_cli/noembed
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- { target: x86_64-unknown-linux-musl, os: ubuntu-latest }
- { target: aarch64-unknown-linux-musl, os: ubuntu-26.04-arm }
steps:
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2
- uses: oxc-project/setup-rust@3d6fb132fbe7cdcb66bf8ec193911c2945369d12 # v1.0.17
with:
restore-cache: false
- uses: taiki-e/install-action@a4d3f3f761dcd95cce1b72cb61cb6d1963438177 # v2.87.30
with:
tool: cargo-zigbuild@0.24.0
fallback: none
- uses: goto-bus-stop/setup-zig@abea47f85e598557f500fa1fd2ab7464fcb39406 # v2.2.1
with:
version: 0.13.0
- name: Build and stage musl binary
env:
TSRS_LIB_PATH: ${{ github.workspace }}/crates/tsrs_vfs/libs
run: |
rustup target add ${{ matrix.target }}
cargo zigbuild --release --locked -p tsrs_cli --features "$TSRS_CARGO_FEATURES" --target ${{ matrix.target }}
mkdir -p "out/${{ matrix.target }}"
cp "target/${{ matrix.target }}/release/tsrs" "out/${{ matrix.target }}/tsrs"
"out/${{ matrix.target }}/tsrs" --version | tee version.txt
grep -q "^Version $TSRS_TS_VERSION (" version.txt || { echo "::error::the binary is not stamped with TypeScript $TSRS_TS_VERSION"; exit 1; }
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: bin-${{ matrix.target }}
path: out/
if-no-files-found: error
# `@tsrs/wasm` (npm/tsrs-wasm, notes/wasm-build.md): the module, the
# package's tests (they compare against a native release build), the package packed by npm/build.mjs, and that
# tarball installed and run before it is handed to the publish job.
wasm:
needs: version
if: needs.version.outputs.release == 'true'
env:
# TypeScript's version in the binary (Cargo.toml [workspace.metadata.typescript] matching npm package).
TSRS_TS_VERSION: ${{ needs.version.outputs.ts_nightly }}
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2
- uses: oxc-project/setup-rust@3d6fb132fbe7cdcb66bf8ec193911c2945369d12 # v1.0.17
with:
restore-cache: false
- run: rustup target add wasm32-wasip1
- uses: oxc-project/setup-node@f46a72f95efdc55273fcd042d61c84e723b2892c # v1.4.1
# The module sizes in notes/wasm-build.md come from binaryen version 133.
- name: Install binaryen 133
run: |
curl -sSLf -o "$RUNNER_TEMP/binaryen.tgz" https://github.com/WebAssembly/binaryen/releases/download/version_133/binaryen-version_133-x86_64-linux.tar.gz
echo "2dc9c7813f5375db93d96ead4b78222fcc3e2677bbb832297af4797782a37489 $RUNNER_TEMP/binaryen.tgz" | sha256sum -c -
tar xzf "$RUNNER_TEMP/binaryen.tgz" -C "$RUNNER_TEMP"
echo "$RUNNER_TEMP/binaryen-version_133/bin" >> "$GITHUB_PATH"
- name: Build the module
run: tools/wasm/build.sh
- name: Build native tsrs (pnpm test compares against it)
run: cargo build --release --locked -p tsrs_cli
- name: pnpm test (npm/tsrs-wasm)
run: pnpm --dir npm/tsrs-wasm test
- name: Pack
run: node npm/build.mjs --wasm npm/tsrs-wasm/tsrs.wasm --out wasm-dist --pack
- name: Installed-package smoke
env:
VERSION: ${{ needs.version.outputs.version }}
run: |
tarball=$(node -p 'require("./wasm-dist/packages.json").packages[0].tarball')
smoke="$RUNNER_TEMP/wasm-smoke"
mkdir -p "$smoke" && cd "$smoke"
printf '{"private":true}\n' > package.json
pnpm add --offline "$tarball"
pnpm exec tsrs-wasm --version | tee version.txt
grep -qF "(tsrs $VERSION," version.txt || { echo "::error::tsrs-wasm --version does not name $VERSION"; exit 1; }
grep -q "^Version $TSRS_TS_VERSION (" version.txt || { echo "::error::tsrs-wasm is not stamped with TypeScript $TSRS_TS_VERSION"; exit 1; }
printf 'const x: number = "no";\n' > bad.ts
set +e; pnpm exec tsrs-wasm bad.ts; status=$?; set -e
[ "$status" = 2 ] || { echo "expected exit 2 for a type error, got $status"; exit 1; }
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: npm-wasm
path: |
wasm-dist/*.tgz
wasm-dist/packages.json
if-no-files-found: error
publish:
needs: [version, check, build, build-windows, build-musl, wasm]
runs-on: ubuntu-latest
timeout-minutes: 90
permissions:
contents: read
id-token: write # npm trusted publishing and provenance
steps:
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2
- uses: oxc-project/setup-node@f46a72f95efdc55273fcd042d61c84e723b2892c # v1.4.1
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: bin-*
path: artifacts
merge-multiple: true
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: npm-wasm
path: wasm-dist
- name: Require the release platforms and the WebAssembly package
run: |
for t in aarch64-apple-darwin x86_64-apple-darwin x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu \
x86_64-unknown-linux-musl aarch64-unknown-linux-musl; do
test -f "artifacts/$t/tsrs" || { echo "::error::missing binary for $t"; exit 1; }
done
for t in x86_64-pc-windows-msvc aarch64-pc-windows-msvc; do
test -f "artifacts/$t/tsrs.exe" || { echo "::error::missing binary for $t"; exit 1; }
done
ls -lR artifacts wasm-dist
- name: Assemble and pack
run: |
node npm/build.mjs --artifacts artifacts --pack
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: npm-packages
path: npm/dist/*.tgz
- name: Publish (@tsrs platform packages, tsrs, then @tsrs/wasm)
env:
DRY_RUN: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run }}
VERSION: ${{ needs.version.outputs.version }}
DIST_TAG: ${{ needs.version.outputs.dist_tag }}
PRIVATE_REPO: ${{ github.event.repository.private }}
run: |
flags=(--access public --tag "$DIST_TAG" --no-git-checks)
[ "$PRIVATE_REPO" = false ] && flags+=(--provenance)
[ "$DRY_RUN" = true ] && flags+=(--dry-run)
# pnpm authenticates with this job's GitHub Actions OIDC identity and publishes directly.
# The WebAssembly manifest comes from the wasm job, whose absolute paths are not this runner's: its tarball
# is looked up next to the manifest. Both manifests must carry the version the skip check below asks for.
# The list is written first so that a failure here fails the step (the default shell has no pipefail).
node -e '
const path = require("path");
for (const dir of ["npm/dist", "wasm-dist"]) {
const m = require(path.resolve(dir, "packages.json"));
if (m.version !== process.env.VERSION) throw new Error(dir + "/packages.json: version " + m.version + ", expected " + process.env.VERSION);
for (const p of m.packages) console.log(p.name + " " + path.resolve(dir, path.basename(p.tarball)));
}' > "$RUNNER_TEMP/publish.txt"
cat "$RUNNER_TEMP/publish.txt"
while read -r name tarball; do
# Re-running a partially published release skips what is already on the registry.
if [ "$DRY_RUN" != true ] && pnpm view "$name@$VERSION" version > /dev/null 2>&1; then
echo "$name@$VERSION already published"
continue
fi
if [ "$DRY_RUN" != true ] && [ "$name" = tsrs ]; then
# npm publish can finish before package metadata and tarballs are available.
node .github/scripts/wait-for-npm-packages.mjs npm/dist/tsrs/package.json
fi
if pnpm publish "$tarball" "${flags[@]}" > "$RUNNER_TEMP/publish.log" 2>&1; then
cat "$RUNNER_TEMP/publish.log"
else
status=$?
cat "$RUNNER_TEMP/publish.log"
# Staged versions can be absent from `pnpm view` while npm already rejects republishing them.
# The availability checks still require their metadata, tarballs and release tags to become visible.
if [ "$DRY_RUN" != true ] && grep -Eq 'publish over (previously staged|the previously published) version' "$RUNNER_TEMP/publish.log"; then
echo "$name@$VERSION already published or staged"
continue
fi
exit "$status"
fi
done < "$RUNNER_TEMP/publish.txt"
- name: Verify every published package and release tag
if: github.event_name != 'workflow_dispatch' || !inputs.dry_run
run: node .github/scripts/wait-for-npm-packages.mjs --release npm/dist/packages.json wasm-dist/packages.json
github-release:
needs: [version, publish]
if: github.event_name != 'workflow_dispatch' || !inputs.dry_run
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: write
steps:
- uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2
- name: Publish GitHub release
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.version.outputs.crate_version }}
DIST_TAG: ${{ needs.version.outputs.dist_tag }}
run: |
flags=(--latest)
if [ "$DIST_TAG" = next ]; then flags=(--prerelease --latest=false); fi
gh release create "v$VERSION" --repo "$GITHUB_REPOSITORY" --target "$GITHUB_SHA" \
--title "$VERSION" --notes-file "docs/releases/$VERSION.md" "${flags[@]}"
playground:
needs: github-release
permissions:
contents: read
id-token: write
uses: ./.github/workflows/void-deploy.yml