Repository navigation
610 lines (601 loc) · 30.6 KB
/
Copy pathrelease.yml
File metadata and controls
610 lines (601 loc) · 30.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
# Builds, packs and tests the tsc-rs release: the npm packages tsc-rs, @tsc-rs/typescript (the
# drop-in for `typescript`), @tsc-rs/linux-x64, @tsc-rs/linux-arm64, @tsc-rs/darwin-arm64,
# @tsc-rs/darwin-x64, @tsc-rs/win32-x64 and @tsc-rs/win32-arm64, and one standalone archive per
# platform (tsc and the lib files; a .zip with tsc.exe for Windows). Both main packages use the same
# platform packages.
#
# A tag v<version> also publishes the npm packages and creates a GitHub release. A stable version
# (v0.1.0) goes to the dist-tag `latest` and a normal release. A prerelease version (v0.2.0-beta.1)
# goes to `next` and a GitHub prerelease. npm trusted publishing (OIDC) authenticates the
# publish: no npm token. Each of the 8 packages trusts this workflow file and the environment `npm`
# (npm/README.md, "Trusted publishing"). Pull requests that change the release files, and a manual
# run, do everything but the release and the publish.
#
# The tsc is a PGO build of the shipped profile (fat LTO), trained on each platform:
# crates/ts_goport/scripts/build-pgo.sh with the training set of scripts/goport/pgo-train.sh (7
# projects at fixed commits). The job also builds the plain tsc, and fails unless the PGO tsc gives
# the same stdout, stderr, exit code and emitted files as the plain tsc on that set. No BOLT
# (build-release.sh has it): BOLT refuses the static Linux bin (build-bolt.sh), its Mach-O support
# is experimental, macOS has no perf branch sampling for its profile, and BOLT has no PE support.
# Linux is static musl and non-PIE, so it starts on any x86-64 or arm64 Linux, Alpine too
# (npm/README.md, "Linux libc"). Each Linux tsc builds natively on a Blacksmith runner of its arch.
# Linux PGO builds link with rustup's rust-lld and fold identical functions (--icf=all). The Linux
# and macOS tsc ship without their symbol tables (stripped after the checks); the artifact
# unstripped-tsc-<platform> keeps the unstripped tsc for perf and profiles.
# The linux-x64 PGO tsc links lust's memfast.c in place of musl's memcpy, memmove, memcmp, bcmp and
# memchr (crates/ts_goport/scripts/memfast.sh): musl's memcmp and bcmp are byte loops.
# Windows (x86_64-pc-windows-msvc, aarch64-pc-windows-msvc) builds in Git Bash, with the C runtime
# linked in (+crt-static), so tsc.exe needs no Visual C++ redistributable. jemalloc does not build
# there: it uses the system allocator. Each PGO tsc builds natively, so its training runs on its
# own platform. darwin-x64 and win32-arm64 ship without PGO (about 10 to 13% more CPU on a check:
# R121 measured 14 to 15% fewer cycles than plain for PGO and BOLT, 1.3 to 2.6% of it BOLT), so
# each is one fat-LTO build. Blacksmith has no Intel Mac, so darwin-x64 cross-builds on
# Blacksmith's arm64 Mac, as T3 Code's x64 desktop build does, and its check runs the x86-64 tsc
# under Rosetta 2; the verify job runs it on an Intel Mac (macos-15-intel). Blacksmith has no arm64
# Windows runner, so win32-arm64 builds on GitHub's windows-11-arm (4 vCPU).
name: Release
on:
push:
tags: ["v*"]
workflow_dispatch:
pull_request:
paths:
- ".github/workflows/release.yml"
- "npm/**"
- "scripts/goport/npm-pack.sh"
- "scripts/goport/pgo-train.sh"
- "crates/ts_goport/scripts/copy-libs.sh"
- "crates/ts_goport/scripts/build-pgo.sh"
- "crates/ts_goport/scripts/memfast.*"
- "LICENSE"
- "NOTICE.md"
- "licenses/**"
permissions:
contents: read
concurrency:
group: release-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
# The toolchain of crates/ts_goport/scripts/build-release.sh.
RUSTUP_TOOLCHAIN: 1.95.0
jobs:
version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.v.outputs.version }}
release: ${{ steps.v.outputs.release }}
steps:
- id: v
run: |
if [[ $GITHUB_REF_TYPE == tag ]]; then
v=${GITHUB_REF_NAME#v}
[[ $v =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$ ]] || { echo "::error::tag $GITHUB_REF_NAME is not v<semver>"; exit 1; }
# 0.0.x are the npm placeholders (npm/trust-setup.sh); the publish would skip them.
[[ $v != 0.0.* ]] || { echo "::error::0.0.x versions are the npm placeholders"; exit 1; }
echo "release=true" >> "$GITHUB_OUTPUT"
else
v=0.0.0-ci.$GITHUB_RUN_NUMBER
echo "release=false" >> "$GITHUB_OUTPUT"
fi
echo "version=$v" >> "$GITHUB_OUTPUT"
echo "version $v"
build:
name: build (${{ matrix.platform }})
needs: version
strategy:
fail-fast: false
matrix:
include:
- platform: linux-x64
target: x86_64-unknown-linux-musl
runner: blacksmith-16vcpu-ubuntu-2404
- platform: linux-arm64
target: aarch64-unknown-linux-musl
runner: blacksmith-16vcpu-ubuntu-2404-arm
# jemalloc does not cross-build for macOS with zig, so this builds on a Mac.
- platform: darwin-arm64
target: aarch64-apple-darwin
runner: blacksmith-12vcpu-macos-26
# No PGO, cross-built on arm64: GitHub's 4 vCPU macos-15-intel took 76 minutes for the
# three fat-LTO builds of the PGO tsc.
- platform: darwin-x64
target: x86_64-apple-darwin
runner: blacksmith-12vcpu-macos-26
rosetta: true
no-pgo: true
- platform: win32-x64
target: x86_64-pc-windows-msvc
runner: blacksmith-16vcpu-windows-2025
exe: .exe
# No PGO: the PGO tsc took 48 minutes on this 4 vCPU runner.
- platform: win32-arm64
target: aarch64-pc-windows-msvc
runner: windows-11-arm
exe: .exe
linker: rust-lld
no-pgo: true
runs-on: ${{ matrix.runner }}
# The 4 vCPU GitHub-hosted runner (win32-arm64) builds slower.
timeout-minutes: 180
# Git Bash on Windows.
defaults:
run:
shell: bash
steps:
# LF in the working tree, as on the other hosts (README.md, "Develop on Windows").
- if: runner.os == 'Windows'
run: git config --global core.autocrlf false
- uses: actions/checkout@v5
with:
persist-credentials: false
# llvm-tools: the llvm-profdata of this rustc's LLVM (build-pgo.sh checks it).
- run: rustup toolchain install "$RUSTUP_TOOLCHAIN" --profile minimal --target ${{ matrix.target }} --component llvm-tools
- if: runner.os == 'Linux'
run: sudo apt-get update -q && sudo apt-get install -yq musl-tools
# darwin-x64 on an arm64 Mac: the check runs the x86-64 tsc, so Rosetta 2 must be there.
- name: Rosetta
if: matrix.rosetta
run: |
arch -x86_64 /usr/bin/true 2>/dev/null || sudo softwareupdate --install-rosetta --agree-to-license
arch -x86_64 /usr/bin/true
# win32-arm64 links with rust-lld (lld-link), all three builds. On arm64, link.exe aligns each
# section contribution to 4 bytes, also the 1-byte start markers of the LLVM profile sections
# (IMAGE_SCN_ALIGN_1BYTES). The instrumented tsc then wrote 3 zero bytes before the names, and
# llvm-profdata rejected each profile ("symbol name is empty"). lld-link keeps the 1-byte
# alignment, as link.exe does on x64.
- name: Linker
if: matrix.linker == 'rust-lld'
run: |
host=$(rustc -vV | sed -n 's/^host: //p')
lld="$(cygpath -u "$(rustc --print sysroot)")/lib/rustlib/$host/bin/rust-lld.exe"
[[ -x $lld ]] || { echo "::error::no $lld"; exit 1; }
target=${{ matrix.target }}
target=${target^^}
echo "CARGO_TARGET_${target//-/_}_LINKER=$(cygpath -m "$lld")" | tee -a "$GITHUB_ENV"
- uses: actions/setup-node@v5
with:
node-version: 24
- uses: Swatinem/rust-cache@v2
with:
key: release-${{ matrix.target }}
save-if: ${{ github.event_name != 'pull_request' }}
# As build-release.sh: the musl build compiles jemalloc with musl-gcc, links static with no PIE,
# and has bin/tsgo.rs JEMALLOC_CONF built in, so the tsc does not exec itself at start. No
# GOPORT_BUILD_VERSION: the tsc reports the TypeScript version, which typesVersions matching
# reads (npm/README.md, "tsc-rs releases"). Both builds below use this environment.
- name: Build environment
if: runner.os == 'Linux'
run: |
conf=$(sed -n 's/^const JEMALLOC_CONF: &str = "\([^"]*\)";$/\1/p' crates/ts_goport/src/bin/tsgo.rs | head -1)
[[ -n $conf ]] || { echo "::error::no JEMALLOC_CONF in bin/tsgo.rs"; exit 1; }
echo "JEMALLOC_SYS_WITH_MALLOC_CONF=$conf" >> "$GITHUB_ENV"
target=${{ matrix.target }}
echo "CC_${target//-/_}=musl-gcc" >> "$GITHUB_ENV"
# jemalloc stops at start when the kernel page is bigger than its build page. arm64 kernels
# use 4, 16 or 64 KiB pages; 2^16 covers all three.
[[ $target != aarch64-* ]] || echo "JEMALLOC_SYS_WITH_LG_PAGE=16" >> "$GITHUB_ENV"
# linux-x64: lust's memfast.c in place of musl's memcpy, memmove, memcmp, bcmp and memchr
# (memfast.sh), in the PGO build only. The plain tsc keeps musl's, so the PGO check below
# also checks memfast against them.
if [[ $target == x86_64-unknown-linux-musl ]]; then
flags=$(crates/ts_goport/scripts/memfast.sh "$RUNNER_TEMP/memfast-wrap.o")
echo "PGO_RUSTFLAGS=$flags" | tee -a "$GITHUB_ENV"
fi
# The plain tsc: the reference of the PGO check below, or the shipped tsc with no-pgo. PGO_LINK is
# the link mode of both builds (build-pgo.sh): static on Linux, crt-static on Windows.
- name: Build
run: |
case $RUNNER_OS in
Linux) export RUSTFLAGS="-C target-feature=+crt-static -C relocation-model=static" PGO_LINK=static ;;
Windows) export RUSTFLAGS="-C target-feature=+crt-static" PGO_LINK=crt-static ;;
esac
echo "PGO_LINK=${PGO_LINK:-}" >> "$GITHUB_ENV"
cargo build --profile goport --locked -p ts_goport --bin tsgo --features noembed --target ${{ matrix.target }}
mkdir -p "$RUNNER_TEMP/plain" "$RUNNER_TEMP/out"
cp "target/${{ matrix.target }}/goport/tsgo${{ matrix.exe }}" "$RUNNER_TEMP/plain/tsc${{ matrix.exe }}"
[[ -z "${{ matrix.no-pgo }}" ]] || cp "$RUNNER_TEMP/plain/tsc${{ matrix.exe }}" "$RUNNER_TEMP/out/tsc${{ matrix.exe }}"
- name: PGO training set
if: ${{ !matrix.no-pgo }}
run: scripts/goport/pgo-train.sh setup "$RUNNER_TEMP/train"
# The same build with -Cprofile-generate, the training set, then -Cprofile-use. PGO_LINK (from
# the Build step) gives the RUSTFLAGS of the plain build. Separate target dirs (not cached).
# Linux: both builds link with rustup's rust-lld (gcc-ld/ld.lld; GNU ld has no --icf) and fold
# identical functions: about 0.27 MB less, almost all of it cold code, and the same code runs.
# The plain tsc keeps GNU ld, so the check below compares the folded tsc with an unfolded one.
- name: PGO build
if: ${{ !matrix.no-pgo }}
env:
PGO_TARGET: ${{ matrix.target }}
PGO_BINS: tsgo
PGO_CARGO: cargo
CARGO_FEATURES: --features noembed
run: |
if [[ $RUNNER_OS == Linux ]]; then
gccld="$(rustc --print sysroot)/lib/rustlib/$(rustc -vV | sed -n 's/^host: //p')/bin/gcc-ld"
[[ -x $gccld/ld.lld ]] || { echo "::error::no $gccld/ld.lld"; exit 1; }
export PGO_RUSTFLAGS="${PGO_RUSTFLAGS:+$PGO_RUSTFLAGS }-Clink-arg=-fuse-ld=lld -Clink-arg=-B$gccld -Clink-arg=-Wl,--icf=all"
fi
PGO_TRAIN="scripts/goport/pgo-train.sh run $RUNNER_TEMP/train" crates/ts_goport/scripts/build-pgo.sh "$RUNNER_TEMP/pgo"
mkdir -p "$RUNNER_TEMP/out"
cp "$RUNNER_TEMP/pgo/target-use/goport/tsgo${{ matrix.exe }}" "$RUNNER_TEMP/out/tsc${{ matrix.exe }}"
- name: Check the PGO tsc against the plain tsc
if: ${{ !matrix.no-pgo }}
run: scripts/goport/pgo-train.sh compare "$RUNNER_TEMP/train" "$RUNNER_TEMP/plain/tsc${{ matrix.exe }}" "$RUNNER_TEMP/out/tsc${{ matrix.exe }}"
- name: Check the tsc
env:
EXE: ${{ matrix.exe }}
run: |
out="$RUNNER_TEMP/out"
dir="$RUNNER_TEMP/check"
crates/ts_goport/scripts/copy-libs.sh "$dir"
cp "$out/tsc$EXE" "$dir/tsc$EXE"
[[ $("$dir/tsc$EXE" --version) == "Version 7."* ]]
# The tsc prints C:/... paths on Windows.
listed=$dir/lib.es5.d.ts
[[ $RUNNER_OS != Windows ]] || listed=$(cygpath -m "$listed")
cd "$RUNNER_TEMP"
echo 'const x: number = "a";' > a.ts
# Not grep -q: it can end before the tsc does, and the tsc then dies of SIGPIPE (exit 141 with
# pipefail; seen on darwin-x64).
"$dir/tsc$EXE" --listFilesOnly --lib es5 a.ts | grep -x "$listed" > /dev/null
set +e
"$dir/tsc$EXE" --noEmit a.ts > check.txt
rc=$?
set -e
cat check.txt
[[ $rc == 2 ]] && grep -q "error TS2322" check.txt
# A locale: the tsc reads its catalog from loc/ next to it (copy-libs.sh). A missing catalog
# is a clear error (exit 1), not English text and not a panic.
set +e
"$dir/tsc$EXE" --noEmit --locale de a.ts > check-de.txt
rc=$?
mv "$dir/loc/de-DE.json.gz" de-DE.json.gz
"$dir/tsc$EXE" --noEmit --locale de a.ts > check-missing.txt 2>&1
rc_missing=$?
set -e
mv de-DE.json.gz "$dir/loc/de-DE.json.gz"
cat check-de.txt check-missing.txt
[[ $rc == 2 ]]
grep -q 'error TS2322: Der Typ "string"' check-de.txt
[[ $rc_missing == 1 ]]
grep -q "^error: cannot read the de-DE messages" check-missing.txt
if [[ $RUNNER_OS == Linux ]]; then
file "$dir/tsc" | tee /dev/stderr | grep -q "statically linked"
# memfast (linux-x64): the five __wrap_ functions, and none of musl's.
if [[ ${PGO_RUSTFLAGS:-} == *--wrap=* ]]; then
syms=$(nm "$dir/tsc" | grep -E ' [Tt] (__wrap_)?(memcpy|memmove|memcmp|bcmp|memchr)$' | awk '{print $3}' | sort | xargs)
echo "mem functions: $syms"
[[ $syms == "__wrap_bcmp __wrap_memchr __wrap_memcmp __wrap_memcpy __wrap_memmove" ]]
fi
# Static: it starts on musl (Alpine) too.
docker run --rm -v "$dir:/t:ro" alpine:3 /t/tsc --version
fi
# +crt-static: no import of the Visual C++ runtime DLL.
if [[ $RUNNER_OS == Windows ]] && grep -qai 'vcruntime140' "$dir/tsc.exe"; then
echo "::error::tsc.exe imports the Visual C++ runtime (vcruntime140.dll)"
exit 1
fi
# Strip the symbol tables after the checks (about 5 MB on Linux). The code does not change. Not
# a cargo profile strip: a profile change changes -C metadata, and a use build then matches no
# function of the profile (a no-PGO tsc, with no warning). The program headers must not move:
# Linux before 5.18 finds them from the first segment, and musl's static start reads PT_TLS
# there. macOS: strip -x (local symbols) with Apple's strip, which signs a linker-signed arm64
# tsc again. macOS stops an arm64 tsc with a bad signature, so the --version run catches it.
- name: Strip the tsc
if: runner.os != 'Windows'
run: |
out="$RUNNER_TEMP/out" dir="$RUNNER_TEMP/check"
mkdir -p "$RUNNER_TEMP/unstripped"
cp "$out/tsc" "$RUNNER_TEMP/unstripped/tsc"
if [[ $RUNNER_OS == Linux ]]; then
strip --strip-all "$out/tsc"
cmp <(readelf -lW "$RUNNER_TEMP/unstripped/tsc") <(readelf -lW "$out/tsc")
else
/usr/bin/strip -x "$out/tsc"
fi
cp "$out/tsc" "$dir/tsc"
[[ $("$dir/tsc" --version) == "Version 7."* ]]
wc -c "$RUNNER_TEMP/unstripped/tsc" "$out/tsc"
- if: runner.os != 'Windows'
uses: actions/upload-artifact@v4
with:
name: unstripped-tsc-${{ matrix.platform }}
path: ${{ runner.temp }}/unstripped/tsc
if-no-files-found: error
retention-days: 90
- uses: actions/upload-artifact@v4
with:
name: tsc-${{ matrix.platform }}
path: ${{ runner.temp }}/out/tsc${{ matrix.exe }}
if-no-files-found: error
package:
needs: [version, build]
runs-on: blacksmith-8vcpu-ubuntu-2404
timeout-minutes: 30
# The digest of the artifact listing, computed on this runner and passed as a job output. The
# release job checks the artifacts it downloads against it, so the bytes that reach npm are
# bound to this job's output and cannot be swapped while the artifact is in transit.
outputs:
sums: ${{ steps.sums.outputs.sha256 }}
env:
VERSION: ${{ needs.version.outputs.version }}
steps:
- uses: actions/checkout@v5
with:
persist-credentials: false
# main's Go pin, as ci.yml resolves it.
- name: Resolve the Go pin
id: pin
run: |
key=$(jq -r '.batch.upstreamPin.to // empty' docs/typechecker-state/current.json)
python3 scripts/upstream/pin.py show ${key:+"$key"} > "$RUNNER_TEMP/pin.json"
jq -r '"key=\(.key)", "repo=\(.repo)", "commit=\(.commit)", "subdir=\(.subdir // "")"' "$RUNNER_TEMP/pin.json" >> "$GITHUB_OUTPUT"
# npm-pack.sh reads the pin's package input (packages/), its lib files and locale catalogs, its
# LICENSE.txt and NOTICE.txt, and builds the JS API with the repo's own tsc (npm workspaces at the root).
- name: Check out the pinned Go source
uses: actions/checkout@v5
with:
repository: ${{ steps.pin.outputs.repo }}
ref: ${{ steps.pin.outputs.commit }}
path: go-pin
sparse-checkout: |
packages
${{ steps.pin.outputs.subdir }}/internal/bundled/libs
${{ steps.pin.outputs.subdir }}/internal/diagnostics/loc
persist-credentials: false
- uses: actions/setup-node@v5
with:
node-version: 24
- run: npm ci --ignore-scripts --no-audit --no-fund
working-directory: go-pin
- uses: actions/download-artifact@v5
with:
pattern: tsc-*
path: ${{ runner.temp }}/bins
- name: Pack
env:
GOPORT_PIN: ${{ steps.pin.outputs.key }}
NPM_PACK_GO_DIR: ${{ github.workspace }}/go-pin/${{ steps.pin.outputs.subdir }}
run: |
bins="$RUNNER_TEMP/bins"
chmod +x "$bins"/tsc-*/tsc "$bins"/tsc-*/tsc.exe
also=(--also "linux-arm64=$bins/tsc-linux-arm64/tsc" --also "darwin-arm64=$bins/tsc-darwin-arm64/tsc"
--also "darwin-x64=$bins/tsc-darwin-x64/tsc"
--also "win32-x64=$bins/tsc-win32-x64/tsc.exe" --also "win32-arm64=$bins/tsc-win32-arm64/tsc.exe")
scripts/goport/npm-pack.sh --name tsc-rs --package-version "$VERSION" "${also[@]}" \
"$RUNNER_TEMP/pkg" "$bins/tsc-linux-x64/tsc"
# The drop-in for `typescript` (npm/README.md). Its optionalDependencies alias the same
# platform packages, which the release publishes once, so they must be the same bytes.
scripts/goport/npm-pack.sh --name @tsc-rs/typescript --package-version "$VERSION" "${also[@]}" \
"$RUNNER_TEMP/pkg-ts" "$bins/tsc-linux-x64/tsc"
for platform in linux-x64 linux-arm64 darwin-arm64 darwin-x64 win32-x64 win32-arm64; do
cmp "$RUNNER_TEMP/pkg/tsc-rs-$platform-$VERSION.tgz" "$RUNNER_TEMP/pkg-ts/tsc-rs-$platform-$VERSION.tgz"
done
cp "$RUNNER_TEMP/pkg-ts/tsc-rs-typescript-$VERSION.tgz" "$RUNNER_TEMP/pkg/"
# One archive per platform: the platform package's lib dir (tsc, and the lib files and loc/
# catalogs, which a noembed tsc reads next to it), LICENSE and NOTICE.txt. A .tar.gz, and a
# .zip for Windows.
- name: Archives
id: sums
run: |
pkg="$RUNNER_TEMP/pkg" dist="$RUNNER_TEMP/dist"
mkdir -p "$dist"
for platform in linux-x64 linux-arm64 darwin-arm64 darwin-x64 win32-x64 win32-arm64; do
name="tsc-rs-$VERSION-$platform"
mkdir -p "$RUNNER_TEMP/archive/$name"
cp -r "$pkg/tsc-rs-$platform/lib/." "$pkg/tsc-rs-$platform/LICENSE" "$pkg/tsc-rs-$platform/NOTICE.txt" "$RUNNER_TEMP/archive/$name/"
if [[ $platform == win32-* ]]; then
(cd "$RUNNER_TEMP/archive" && python3 -m zipfile -c "$dist/$name.zip" "$name")
else
tar -C "$RUNNER_TEMP/archive" -czf "$dist/$name.tar.gz" "$name"
fi
done
cp "$pkg"/*.tgz "$dist/"
(cd "$dist" && sha256sum -- *.tgz *.tar.gz *.zip > SHA256SUMS)
cat "$dist/SHA256SUMS"
# The digest of the listing, for the release job's cross-channel check (see there).
echo "sha256=$(sha256sum "$dist/SHA256SUMS" | cut -d' ' -f1)" >> "$GITHUB_OUTPUT"
- uses: actions/upload-artifact@v4
with:
name: release
path: ${{ runner.temp }}/dist
if-no-files-found: error
# Installs the npm packages in a fresh project on each platform, as a user would. These are
# GitHub-hosted runners, so the check runs on another host than the build (for darwin-x64 and
# win32-arm64, another VM of the build's runner image). ubuntu-24.04-arm is GitHub's arm64
# standard runner (2 vCPU in a private repo, 4 in a public one).
verify:
name: verify (${{ matrix.platform }})
needs: [version, package]
strategy:
fail-fast: false
matrix:
include:
- platform: linux-x64
runner: ubuntu-latest
- platform: linux-arm64
runner: ubuntu-24.04-arm
- platform: darwin-arm64
runner: macos-latest
- platform: darwin-x64
runner: macos-15-intel
- platform: win32-x64
runner: windows-latest
- platform: win32-arm64
runner: windows-11-arm
runs-on: ${{ matrix.runner }}
timeout-minutes: 15
# Git Bash on Windows.
defaults:
run:
shell: bash
env:
VERSION: ${{ needs.version.outputs.version }}
steps:
- uses: actions/setup-node@v5
with:
node-version: 24
- uses: actions/download-artifact@v5
with:
name: release
path: ${{ runner.temp }}/dist
# The same checks the release job runs before publishing (see there). They run here on PRs so
# a change to this workflow or npm/** exercises them. Linux only, as the release job: they use
# GNU sha256sum and find.
- name: Verify the artifacts
if: runner.os == 'Linux'
env:
SUMS_SHA256: ${{ needs.package.outputs.sums }}
run: |
cd "$RUNNER_TEMP/dist"
echo "$SUMS_SHA256 SHA256SUMS" | sha256sum --check --strict -
sha256sum --check --strict SHA256SUMS
diff <(find . -mindepth 1 -maxdepth 1 -printf '%P\n' | sort) \
<({ sed -E 's/^[0-9a-f]{64} [ *]//' SHA256SUMS; echo SHA256SUMS; } | sort) ||
{ echo "::error::dist must hold exactly the files in SHA256SUMS and SHA256SUMS"; exit 1; }
- name: npm install and check
run: |
dist="$RUNNER_TEMP/dist"
[[ $RUNNER_OS != Windows ]] || dist=$(cygpath -m "$dist")
# Node of the runner's own arch: getExePath.js picks the package of process.arch.
node_platform=$(node -p 'process.platform + "-" + process.arch')
echo "node $node_platform"
[[ $node_platform == "${{ matrix.platform }}" ]]
mkdir proj && cd proj
echo '{"name":"smoke","private":true}' > package.json
# The other platform's package is not on npm yet: --offline skips that optional dependency.
npm install --offline --no-audit --no-fund "$dist/tsc-rs-${{ matrix.platform }}-$VERSION.tgz" "$dist/tsc-rs-$VERSION.tgz"
npx tsc-rs --version
echo 'export const x: number = 1;' > ok.ts
npx tsc-rs --noEmit --strict ok.ts
echo 'const x: number = "a";' > bad.ts
set +e
npx tsc-rs --noEmit bad.ts > check.txt
rc=$?
npx tsc-rs --noEmit --locale de bad.ts > check-de.txt
rc_de=$?
set -e
cat check.txt check-de.txt
[[ $rc == 2 ]] && grep -q "error TS2322" check.txt
# The package's lib/loc holds the locale catalogs.
[[ $rc_de == 2 ]]
grep -q 'error TS2322: Der Typ "string"' check-de.txt
# Emit.
npx tsc-rs --outDir out --declaration ok.ts
cat out/ok.js out/ok.d.ts
grep -q "export const x = 1;" out/ok.js
# The drop-in under the name `typescript`, and its platform package under Go's name, as
# "typescript": "npm:@tsc-rs/typescript@<v>" installs them from npm. The tarballs are copied in:
# a relative file: spec has no drive letter on Windows.
- name: npm install and check (@tsc-rs/typescript as typescript)
run: |
platform=${{ matrix.platform }}
mkdir proj-ts && cd proj-ts
cp "$RUNNER_TEMP/dist/tsc-rs-$platform-$VERSION.tgz" "$RUNNER_TEMP/dist/tsc-rs-typescript-$VERSION.tgz" .
echo '{"name":"smoke-ts","private":true}' > package.json
npm install --offline --no-audit --no-fund "@typescript/typescript-$platform@file:./tsc-rs-$platform-$VERSION.tgz" \
"typescript@file:./tsc-rs-typescript-$VERSION.tgz"
# The tsc and require("typescript").version report the TypeScript version (tscVersion).
tsc_version=$(node -p 'require("./node_modules/typescript/package.json").tscVersion')
npx tsc --version
[[ $(npx tsc --version) == "Version $tsc_version" ]]
node -p 'require("typescript").version'
[[ $(node -p 'require("typescript").version') == "$tsc_version" ]]
node --input-type=module -e 'await import("typescript/sync")'
echo 'const x: number = "a";' > bad.ts
set +e
npx tsc --noEmit bad.ts > check.txt
rc=$?
set -e
cat check.txt
[[ $rc == 2 ]] && grep -q "error TS2322" check.txt
echo 'export const x: number = 1;' > ok.ts
npx tsc --outDir out --declaration ok.ts
grep -q "export const x = 1;" out/ok.js
- name: Archive check
if: runner.os != 'Windows'
run: |
dist="$RUNNER_TEMP/dist"
tar -xzf "$dist/tsc-rs-$VERSION-${{ matrix.platform }}.tar.gz" -C "$RUNNER_TEMP"
"$RUNNER_TEMP/tsc-rs-$VERSION-${{ matrix.platform }}/tsc" --version
- name: Archive check (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$name = "tsc-rs-$env:VERSION-${{ matrix.platform }}"
Expand-Archive "$env:RUNNER_TEMP\dist\$name.zip" $env:RUNNER_TEMP
& "$env:RUNNER_TEMP\$name\tsc.exe" --version
if ($LASTEXITCODE -ne 0) { exit 1 }
release:
if: needs.version.outputs.release == 'true'
needs: [version, verify, package]
# Trusted publishing needs a GitHub-hosted runner. The environment is part of the trust: add
# required reviewers to it in the repo settings to approve each publish.
runs-on: ubuntu-latest
environment: npm
timeout-minutes: 15
permissions:
contents: write
id-token: write
env:
VERSION: ${{ needs.version.outputs.version }}
steps:
- uses: actions/setup-node@v5
with:
node-version: 24
# Trusted publishing needs npm 11.5.1 or later.
- run: npm install -g npm@11 && npm --version
- uses: actions/download-artifact@v5
with:
name: release
path: dist
# The artifact could be swapped while it sits in the artifact store, so check it against the
# digest the package job produced. That digest is a job output, not a file in the artifact, so
# a swap that also rewrites SHA256SUMS cannot satisfy it. Then check each archive against the
# listing, and that dist holds no other file: the GitHub release uploads all of dist/*. All
# three must hold before anything is published.
- name: Verify the artifacts
env:
SUMS_SHA256: ${{ needs.package.outputs.sums }}
run: |
cd dist
echo "$SUMS_SHA256 SHA256SUMS" | sha256sum --check --strict -
sha256sum --check --strict SHA256SUMS
# The names in the listing ("<sha256> <name>", or " *" in binary mode) and the listing.
# sed leaves a line in another form whole, so it matches no file and the diff fails.
diff <(find . -mindepth 1 -maxdepth 1 -printf '%P\n' | sort) \
<({ sed -E 's/^[0-9a-f]{64} [ *]//' SHA256SUMS; echo SHA256SUMS; } | sort) ||
{ echo "::error::dist must hold exactly the files in SHA256SUMS and SHA256SUMS"; exit 1; }
# Platform packages first, then the main packages that depend on them. A version that is
# already on npm is skipped, so a failed run can run again. While the repo is private, npm
# makes no provenance; from a public repo it adds it by itself.
# A version with a prerelease part (a "-") is a prerelease: dist-tag `next`. Else `latest`.
- name: Publish to npm
run: |
tag=latest
[[ $VERSION != *-* ]] || tag=next
echo "dist-tag $tag"
for pkg in @tsc-rs/linux-x64:tsc-rs-linux-x64 @tsc-rs/linux-arm64:tsc-rs-linux-arm64 \
@tsc-rs/darwin-arm64:tsc-rs-darwin-arm64 @tsc-rs/darwin-x64:tsc-rs-darwin-x64 \
@tsc-rs/win32-x64:tsc-rs-win32-x64 @tsc-rs/win32-arm64:tsc-rs-win32-arm64 tsc-rs:tsc-rs \
@tsc-rs/typescript:tsc-rs-typescript; do
name=${pkg%%:*} file=./dist/${pkg#*:}-$VERSION.tgz
[[ -f $file ]] || { echo "::error::missing package $file"; exit 1; }
if npm view "$name@$VERSION" version > /dev/null 2>&1; then
echo "$name@$VERSION is already published"
else
npm publish "$file" --tag "$tag" --access public
fi
done
- name: GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: |
pre=() install="npm install -D tsc-rs"
[[ $VERSION != *-* ]] || pre=(--prerelease) install="npm install -D tsc-rs@next"
dropin="\"typescript\": \"npm:@tsc-rs/typescript@$VERSION\""
gh release create "$GITHUB_REF_NAME" dist/* --repo "$GITHUB_REPOSITORY" "${pre[@]}" \
--title "tsc-rs $VERSION" --generate-notes \
--notes "Install with \`$install\`, use it as the \`typescript\` package with \`$dropin\` in package.json, or download the archive for your platform."