Repository navigation
212 lines (193 loc) · 9.08 KB
/
Copy pathtest-android.yml
File metadata and controls
212 lines (193 loc) · 9.08 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
name: Test - Android (emulator)
# The tester's tests and the default library's, built for x86_64 Android (API 29) under -mm=gc, rc,
# none and own with a Windows package's compiler and Android libraries, and run on an x86_64 Android
# emulator (tslang/test/android/run_tests.mjs). The package ships Android's libraries only for
# Windows, so Windows builds the programs and Linux, which has KVM, runs the emulator.
#
# create-release.yml calls it with the package it has just built (package: artifact). A pull request
# that changes the runner, and a manual run, test the latest published release's package, with that
# release's tester tests.
on:
workflow_call:
inputs:
package:
description: "artifact: this run's tslang-windows-asset; release: the latest published release's Windows package"
type: string
default: release
defaultlib_sha:
description: the TypeScriptCompilerDefaultLib commit the package's default library was built from (default its main)
type: string
default: ''
pull_request:
branches: [ main ]
paths:
- 'tslang/test/android/**'
- 'tslang/test/suites.mjs'
- '.github/workflows/test-android.yml'
workflow_dispatch:
jobs:
build:
name: Build Android tests (x86_64)
runs-on: windows-2025-vs2026
timeout-minutes: 60
env:
TOOL_PATH: ${{ github.workspace }}\__tslang
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 24
- name: Clone Default Library
shell: pwsh
env:
DEFAULTLIB_SHA: ${{ inputs.defaultlib_sha }}
run: |
git clone https://github.com/ASDAlexander77/TypeScriptCompilerDefaultLib.git
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
if ($env:DEFAULTLIB_SHA) {
git -C TypeScriptCompilerDefaultLib checkout --detach $env:DEFAULTLIB_SHA
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
- name: Download the package (this run's)
if: inputs.package == 'artifact'
uses: actions/download-artifact@v4
with:
name: tslang-windows-asset
- name: Download the package (the latest release's)
if: inputs.package != 'artifact'
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: |
# every release is a pre-release, and GitHub's "latest" leaves those out: take the newest
$tag = gh release list --repo ${{ github.repository }} --exclude-drafts --limit 1 --json tagName --jq '.[0].tagName'
if ($LASTEXITCODE -ne 0 -or -not $tag) { Write-Error "no published release"; exit 1 }
Write-Host "release: $tag"
gh release download $tag --repo ${{ github.repository }} --pattern '*-windows-x64.zip'
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
# that release's compiler with that release's tests: a test added since checks a fix it
# does not have. The runner and its skips stay this commit's - they are what is tested.
git fetch --depth=1 origin tag $tag
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
git checkout $tag -- tslang/test/tester/tests tslang/test/tester/CMakeLists.txt
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
- name: Unpack the package
shell: pwsh
run: |
$zip = Get-ChildItem -Filter '*-windows-x64.zip' | Select-Object -First 1
Write-Host "package: $($zip.Name)"
Expand-Archive -Path $zip.FullName -DestinationPath $env:TOOL_PATH
Remove-Item $zip.FullName
New-Item -ItemType Directory -Force -Path TypeScriptCompilerDefaultLib\__build | Out-Null
Move-Item -Path (Join-Path $env:TOOL_PATH 'defaultlib') -Destination TypeScriptCompilerDefaultLib\__build\defaultlib -ErrorAction Stop
& (Join-Path $env:TOOL_PATH 'tslang.exe') --version
- name: Build the tests for x86_64 Android
shell: pwsh
working-directory: ${{ github.workspace }}/tslang/test/android
run: |
$ndk = if ($env:ANDROID_NDK_LATEST_HOME) { $env:ANDROID_NDK_LATEST_HOME } else { $env:ANDROID_NDK_HOME }
if (-not $ndk) { Write-Error "no Android NDK on this runner (ANDROID_NDK_LATEST_HOME / ANDROID_NDK_HOME)"; exit 1 }
node run_tests.mjs --build "--tslang=$(Join-Path $env:TOOL_PATH 'tslang.exe')" `
"--default-lib-repo=${{ github.workspace }}\TypeScriptCompilerDefaultLib" `
"--android-lib=$(Join-Path $env:TOOL_PATH 'android\x86_64\lib')" "--android-ndk-path=$ndk" -j4
$code = $LASTEXITCODE
if ($code -ne 0) { Get-Content out\results.txt -ErrorAction SilentlyContinue }
tar -czf android-tests.tgz -C out .
exit $code
- name: Upload the tests
uses: actions/upload-artifact@v4
with:
name: android-tests
path: tslang/test/android/android-tests.tgz
retention-days: 1
run:
name: Run Android tests (x86_64 emulator, API 29)
needs: build
runs-on: ubuntu-24.04
timeout-minutes: 90
# one place for avdmanager to make the AVD and the emulator to find it: left to themselves the
# runner's command-line tools made it where the emulator does not look ("Unknown AVD name")
env:
ANDROID_USER_HOME: ${{ github.workspace }}/__android
ANDROID_AVD_HOME: ${{ github.workspace }}/__android/avd
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 24
- name: Download the tests
uses: actions/download-artifact@v4
with:
name: android-tests
path: tslang/test/android
- name: Unpack the tests
working-directory: ${{ github.workspace }}/tslang/test/android
shell: bash
run: mkdir -p out && tar -xzf android-tests.tgz -C out && rm android-tests.tgz && du -sh out
# the emulator needs KVM, which the runner has but does not open to its user
- name: Enable KVM
shell: bash
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
# With the runner's Android SDK, not a marketplace action: the repository allows GitHub's
# own actions only.
- name: Install the emulator and an API 29 x86_64 system image
shell: bash
run: |
set -e
sdk=${ANDROID_HOME:-$ANDROID_SDK_ROOT}
sdkmanager=$sdk/cmdline-tools/latest/bin/sdkmanager
yes | $sdkmanager --licenses > /dev/null || true
$sdkmanager --install "emulator" "platform-tools" "system-images;android-29;default;x86_64" > /dev/null
mkdir -p "$ANDROID_AVD_HOME"
echo no | $sdk/cmdline-tools/latest/bin/avdmanager create avd --force -n tslang_api29_x86_64 -k "system-images;android-29;default;x86_64"
$sdk/emulator/emulator -list-avds | grep -x tslang_api29_x86_64 || { echo "the emulator does not see the AVD:"; ls -R "$ANDROID_USER_HOME"; exit 1; }
echo "$sdk/emulator" >> "$GITHUB_PATH"
echo "$sdk/platform-tools" >> "$GITHUB_PATH"
# Every wait has a limit, and the emulator ending is noticed: `adb wait-for-device` alone
# waited for an emulator that had already exited until the job's own limit.
- name: Start the emulator
shell: bash
run: |
# bash runs with -e -o pipefail: the polls below fail until a device is up
set +e +o pipefail
ls -l /dev/kvm
emulator -accel-check
adb start-server > /dev/null 2>&1
nohup emulator -avd tslang_api29_x86_64 -no-window -no-audio -no-boot-anim -no-snapshot \
-gpu swiftshader_indirect -memory 4096 -cores 4 -accel on < /dev/null > emulator.log 2>&1 &
pid=$!
for i in $(seq 1 120); do
if ! kill -0 $pid 2>/dev/null; then
wait $pid; echo "the emulator exited (code $?) before it booted:"; cat emulator.log; exit 1
fi
booted=$(timeout 10 adb shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')
[ "$booted" = 1 ] && { echo "booted after about $((i * 5)) s"; adb devices; exit 0; }
sleep 5
done
echo "the emulator did not boot in 10 minutes:"; adb devices; tail -100 emulator.log; exit 1
- name: Run the tests on the emulator
working-directory: ${{ github.workspace }}/tslang/test/android
shell: bash
run: |
code=0
node run_tests.mjs --run --adb=adb || code=$?
if [ $code -ne 0 ]; then cat out/results.txt; fi
adb emu kill || true
exit $code
- name: Keep the results
if: always()
uses: actions/upload-artifact@v4
with:
name: android-test-results
path: |
tslang/test/android/out/results.txt
emulator.log
retention-days: 7
if-no-files-found: ignore