-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathandroid-emulator-screenshots.yml
More file actions
641 lines (567 loc) · 24.1 KB
/
android-emulator-screenshots.yml
File metadata and controls
641 lines (567 loc) · 24.1 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
name: Android Emulator Screenshots
on:
workflow_dispatch:
inputs:
device_profile:
description: "Android device preset (or auto)"
required: true
default: "auto"
type: choice
options:
- auto
- samsung-galaxy-s25-ultra
- samsung-galaxy-s24-ultra
- google-pixel-9-pro-xl
- google-pixel-8-pro
- google-pixel-7-pro
- google-pixel-6-pro
- google-pixel-5
- google-pixel-4
- google-pixel-3
api_level:
description: "Android API level for emulator system image"
required: true
default: "35"
type: string
system_image_abi:
description: "System image ABI (auto, x86_64, or arm64-v8a)"
required: true
default: "auto"
type: choice
options:
- auto
- x86_64
- arm64-v8a
startup_wait_seconds:
description: "Seconds to wait after first app launch"
required: true
default: "10"
type: string
per_page_wait_seconds:
description: "Seconds to wait after each deep link"
required: true
default: "3"
type: string
deep_links:
description: "Deep links separated by comma or newline"
required: false
type: string
default: "eclipsetimer://landing,eclipsetimer://timer,eclipsetimer://notifications,eclipsetimer://locations,eclipsetimer://eclipse/2026-total,eclipsetimer://eclipse/2026-total/preview,eclipsetimer://eclipse/2027-total,eclipsetimer://eclipse/2027-total/preview"
concurrency:
group: android-screenshots-${{ github.ref }}
cancel-in-progress: false
jobs:
screenshots:
name: Capture Android Emulator Screenshots
runs-on: [self-hosted, macOS, eclipse-timer]
timeout-minutes: 90
permissions:
contents: write
env:
BUNDLE_ID: com.lallimaven.eclipsetimer
GOOGLE_MAPS_ANDROID_API_KEY: ${{ secrets.GOOGLE_MAPS_ANDROID_API_KEY }}
SENTRY_DISABLE_AUTO_UPLOAD: "true"
SENTRY_ALLOW_FAILURE: "true"
SENTRY_CLI_EXECUTABLE: "/usr/bin/true"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile --prefer-offline
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "17"
cache: gradle
- name: Setup Android SDK tools
uses: android-actions/setup-android@v3
- name: Install Android SDK packages for build + emulator
env:
API_LEVEL: ${{ github.event.inputs.api_level }}
SYSTEM_IMAGE_ABI: ${{ github.event.inputs.system_image_abi }}
run: |
set -euo pipefail
if [[ ! "$API_LEVEL" =~ ^[0-9]+$ ]]; then
echo "api_level must be an integer."
exit 1
fi
selected_abi="$SYSTEM_IMAGE_ABI"
if [ "$selected_abi" = "auto" ]; then
if [ "$(uname -m)" = "arm64" ]; then
selected_abi="arm64-v8a"
else
selected_abi="x86_64"
fi
fi
sdk_root=""
for candidate in \
"${ANDROID_SDK_ROOT:-}" \
"${ANDROID_HOME:-}" \
"$HOME/Library/Android/sdk" \
"$HOME/Android/Sdk" \
"/usr/local/share/android-sdk" \
"/opt/homebrew/share/android-sdk"
do
if [ -n "$candidate" ] && [ -d "$candidate" ]; then
sdk_root="$candidate"
break
fi
done
if [ ! -d "$sdk_root" ]; then
echo "Android SDK directory not found."
echo "Install Android SDK on the runner or set ANDROID_SDK_ROOT/ANDROID_HOME."
exit 1
fi
echo "ANDROID_SDK_ROOT=$sdk_root" >> "$GITHUB_ENV"
echo "ANDROID_HOME=$sdk_root" >> "$GITHUB_ENV"
echo "SCREENSHOT_SYSTEM_IMAGE_ABI=$selected_abi" >> "$GITHUB_ENV"
echo "$sdk_root/platform-tools" >> "$GITHUB_PATH"
echo "$sdk_root/emulator" >> "$GITHUB_PATH"
if [ -d "$sdk_root/cmdline-tools/latest/bin" ]; then
echo "$sdk_root/cmdline-tools/latest/bin" >> "$GITHUB_PATH"
fi
system_image_package="system-images;android-${API_LEVEL};google_apis;${selected_abi}"
system_image_dir="$sdk_root/system-images/android-${API_LEVEL}/google_apis/${selected_abi}"
missing_packages=()
[ -d "$sdk_root/platform-tools" ] || missing_packages+=("platform-tools")
[ -d "$sdk_root/emulator" ] || missing_packages+=("emulator")
[ -d "$sdk_root/platforms/android-36" ] || missing_packages+=("platforms;android-36")
[ -d "$sdk_root/build-tools/36.0.0" ] || missing_packages+=("build-tools;36.0.0")
[ -d "$sdk_root/ndk/27.1.12297006" ] || missing_packages+=("ndk;27.1.12297006")
[ -d "$system_image_dir" ] || missing_packages+=("$system_image_package")
if [ "${#missing_packages[@]}" -eq 0 ]; then
echo "All required Android SDK packages are already installed in $sdk_root."
exit 0
fi
echo "Installing missing Android SDK packages: ${missing_packages[*]}"
yes | sdkmanager --licenses >/dev/null || true
sdkmanager "${missing_packages[@]}"
- name: Setup EAS CLI
uses: expo/expo-github-action@v8
with:
eas-version: latest
token: ${{ secrets.EXPO_TOKEN }}
packager: pnpm
- name: Validate Google Maps Android key
run: |
if [ -z "$GOOGLE_MAPS_ANDROID_API_KEY" ]; then
echo "Missing GOOGLE_MAPS_ANDROID_API_KEY GitHub secret."
echo "Add it in: Settings -> Secrets and variables -> Actions."
exit 1
fi
- name: Build Android APK
working-directory: apps/mobile
env:
EAS_LOCAL_BUILD_ARTIFACTS_DIR: ${{ github.workspace }}/artifacts/raw
GOOGLE_MAPS_ANDROID_API_KEY: ${{ secrets.GOOGLE_MAPS_ANDROID_API_KEY }}
run: |
set -euo pipefail
sdk_root="${ANDROID_SDK_ROOT:-${ANDROID_HOME:-}}"
if [ -z "$sdk_root" ] || [ ! -d "$sdk_root" ]; then
echo "ANDROID_SDK_ROOT/ANDROID_HOME is not configured."
exit 1
fi
export ANDROID_SDK_ROOT="$sdk_root"
export ANDROID_HOME="$sdk_root"
escaped_sdk_root="${sdk_root// /\\ }"
printf 'sdk.dir=%s\n' "$escaped_sdk_root" > android/local.properties
echo "Using Android SDK at $sdk_root"
pnpm exec eas build --platform android --profile production-apk --local --non-interactive
- name: Resolve Android APK artifact
id: resolve_apk
run: |
set -euo pipefail
artifacts_dir="$GITHUB_WORKSPACE/artifacts/raw"
apk_path="$(find "$artifacts_dir" -type f -name '*.apk' | grep -iv 'wear' | head -n 1 || true)"
if [ -z "$apk_path" ]; then
apk_path="$(find "$artifacts_dir" -type f -name '*.apk' | head -n 1 || true)"
fi
if [ -z "$apk_path" ]; then
echo "Could not find Android APK artifact in $artifacts_dir."
find "$artifacts_dir" -maxdepth 3 -print || true
exit 1
fi
echo "Using APK: $apk_path"
{
echo "apk_path<<EOF"
echo "$apk_path"
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Boot emulator and capture screenshots
id: capture
env:
DEVICE_PROFILE: ${{ github.event.inputs.device_profile }}
API_LEVEL: ${{ github.event.inputs.api_level }}
STARTUP_WAIT_SECONDS: ${{ github.event.inputs.startup_wait_seconds }}
PER_PAGE_WAIT_SECONDS: ${{ github.event.inputs.per_page_wait_seconds }}
APP_PATH: ${{ steps.resolve_apk.outputs.apk_path }}
run: |
set -euo pipefail
if [[ ! "$API_LEVEL" =~ ^[0-9]+$ ]]; then
echo "api_level must be an integer."
exit 1
fi
if [[ ! "$STARTUP_WAIT_SECONDS" =~ ^[0-9]+$ ]]; then
echo "startup_wait_seconds must be an integer."
exit 1
fi
if [[ ! "$PER_PAGE_WAIT_SECONDS" =~ ^[0-9]+$ ]]; then
echo "per_page_wait_seconds must be an integer."
exit 1
fi
if [ ! -f "$APP_PATH" ]; then
echo "APK not found at $APP_PATH."
exit 1
fi
sdk_root="${ANDROID_SDK_ROOT:-${ANDROID_HOME:-}}"
if [ -z "$sdk_root" ] || [ ! -d "$sdk_root" ]; then
echo "ANDROID_SDK_ROOT/ANDROID_HOME is not configured."
exit 1
fi
export ANDROID_SDK_ROOT="$sdk_root"
export ANDROID_HOME="$sdk_root"
export PATH="$sdk_root/platform-tools:$sdk_root/emulator:$PATH"
if [ -d "$sdk_root/cmdline-tools/latest/bin" ]; then
export PATH="$sdk_root/cmdline-tools/latest/bin:$PATH"
fi
running_emulators="$(adb devices | awk '/^emulator-[0-9]+\t(device|offline)$/{print $1}')"
if [ -n "$running_emulators" ]; then
while IFS= read -r serial; do
[ -z "$serial" ] && continue
adb -s "$serial" emu kill || true
done <<< "$running_emulators"
sleep 5
fi
system_image="system-images;android-${API_LEVEL};google_apis;${SCREENSHOT_SYSTEM_IMAGE_ABI}"
device_suffix="$(printf '%s' "${DEVICE_PROFILE:-auto}" | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9]+/-/g; s/^-+//; s/-+$//')"
[ -z "$device_suffix" ] && device_suffix="auto"
avd_name="eclipse-timer-android-${API_LEVEL}-${device_suffix}"
list_device_profiles() {
avdmanager list device | awk '
$1 == "id:" {
id = "";
quoted_parts = split($0, parts, "\"");
if (quoted_parts >= 2) {
id = parts[2];
} else {
id = $2;
}
next;
}
$1 == "Name:" {
name = $0;
sub(/^[[:space:]]*Name:[[:space:]]*/, "", name);
if (id != "") {
printf "%s|%s\n", id, name;
}
}
'
}
select_default_android_profile() {
local profiles
local selected
profiles="$(list_device_profiles)"
selected="$(printf '%s\n' "$profiles" | grep -Eiv 'wear|watch' | grep -Ei '^pixel_|^pixel|[|][[:space:]]*(Pixel|Nexus)' | head -n 1 | cut -d'|' -f1 || true)"
if [ -z "$selected" ]; then
selected="$(printf '%s\n' "$profiles" | grep -Eiv 'wear|watch' | head -n 1 | cut -d'|' -f1 || true)"
fi
printf '%s' "$selected"
}
select_profile_by_patterns() {
local profiles
local selected
local pattern
profiles="$(list_device_profiles)"
for pattern in "$@"; do
selected="$(printf '%s\n' "$profiles" | grep -Ei "$pattern" | head -n 1 | cut -d'|' -f1 || true)"
if [ -n "$selected" ]; then
printf '%s' "$selected"
return 0
fi
done
return 1
}
resolve_android_profile_preset() {
local preset="$1"
case "$preset" in
samsung-galaxy-s25-ultra)
select_profile_by_patterns 's25.*ultra|galaxy.*s25.*ultra' 'pixel[ _-]?9.*pro.*xl|pixel_9_pro_xl' 'pixel[ _-]?8.*pro|pixel_8_pro' || true
;;
samsung-galaxy-s24-ultra)
select_profile_by_patterns 's24.*ultra|galaxy.*s24.*ultra' 'pixel[ _-]?8.*pro|pixel_8_pro' 'pixel[ _-]?7.*pro|pixel_7_pro' || true
;;
google-pixel-9-pro-xl)
select_profile_by_patterns 'pixel[ _-]?9.*pro.*xl|pixel_9_pro_xl' 'pixel[ _-]?8.*pro|pixel_8_pro' || true
;;
google-pixel-8-pro)
select_profile_by_patterns 'pixel[ _-]?8.*pro|pixel_8_pro' 'pixel[ _-]?7.*pro|pixel_7_pro' || true
;;
google-pixel-7-pro)
select_profile_by_patterns 'pixel[ _-]?7.*pro|pixel_7_pro' 'pixel[ _-]?6.*pro|pixel_6_pro' || true
;;
google-pixel-6-pro)
select_profile_by_patterns 'pixel[ _-]?6.*pro|pixel_6_pro' 'pixel[ _-]?5|pixel_5' || true
;;
google-pixel-5)
select_profile_by_patterns 'pixel[ _-]?5|pixel_5' 'pixel[ _-]?4|pixel_4' || true
;;
google-pixel-4)
select_profile_by_patterns 'pixel[ _-]?4|pixel_4' 'pixel[ _-]?3|pixel_3' || true
;;
google-pixel-3)
select_profile_by_patterns 'pixel[ _-]?3|pixel_3' 'pixel[ _-]?4|pixel_4' || true
;;
*)
printf '%s' "$preset"
;;
esac
}
create_avd() {
local profile="$1"
if [ -n "$profile" ]; then
if echo "no" | avdmanager create avd -n "$avd_name" -k "$system_image" --device "$profile" --force; then
return 0
fi
echo "::warning::Unable to use device profile '$profile'. Retrying with default profile."
fi
echo "no" | avdmanager create avd -n "$avd_name" -k "$system_image" --force
}
selected_device_profile="${DEVICE_PROFILE:-auto}"
if [ "$selected_device_profile" = "auto" ]; then
selected_device_profile="$(select_default_android_profile)"
if [ -n "$selected_device_profile" ]; then
echo "Auto-selected Android device profile: $selected_device_profile"
else
echo "::warning::Could not auto-select an Android device profile. Falling back to SDK default profile."
fi
else
resolved_profile="$(resolve_android_profile_preset "$selected_device_profile")"
if [ -n "$resolved_profile" ]; then
selected_device_profile="$resolved_profile"
echo "Requested Android preset '${DEVICE_PROFILE:-auto}' resolved to profile: $selected_device_profile"
else
echo "::warning::Unable to resolve Android preset '${DEVICE_PROFILE:-auto}'. Falling back to auto selection."
selected_device_profile="$(select_default_android_profile)"
fi
fi
if ! avdmanager list avd | grep -Fq "Name: $avd_name"; then
create_avd "$selected_device_profile"
fi
mkdir -p "$GITHUB_WORKSPACE/artifacts"
emulator_log="$GITHUB_WORKSPACE/artifacts/android-emulator.log"
"$sdk_root/emulator/emulator" \
-avd "$avd_name" \
-no-window \
-no-audio \
-no-boot-anim \
-gpu swiftshader_indirect \
-no-snapshot \
-no-snapshot-save \
>"$emulator_log" 2>&1 &
emulator_pid=$!
emulator_serial=""
for _ in {1..120}; do
emulator_serial="$(adb devices | awk '/^emulator-[0-9]+\t(device|offline)$/{print $1; exit}')"
[ -n "$emulator_serial" ] && break
sleep 2
done
if [ -z "$emulator_serial" ]; then
echo "Android emulator did not start."
tail -n 200 "$emulator_log" || true
exit 1
fi
adb -s "$emulator_serial" wait-for-device
boot_completed=""
for _ in {1..180}; do
boot_completed="$(adb -s "$emulator_serial" shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')"
if [ "$boot_completed" = "1" ]; then
break
fi
sleep 2
done
if [ "$boot_completed" != "1" ]; then
echo "Android emulator failed to boot."
tail -n 200 "$emulator_log" || true
exit 1
fi
adb -s "$emulator_serial" shell settings put global window_animation_scale 0 || true
adb -s "$emulator_serial" shell settings put global transition_animation_scale 0 || true
adb -s "$emulator_serial" shell settings put global animator_duration_scale 0 || true
adb -s "$emulator_serial" shell input keyevent 82 || true
adb -s "$emulator_serial" install -r "$APP_PATH"
adb -s "$emulator_serial" shell pm grant "$BUNDLE_ID" android.permission.POST_NOTIFICATIONS || true
adb -s "$emulator_serial" shell pm grant "$BUNDLE_ID" android.permission.ACCESS_FINE_LOCATION || true
adb -s "$emulator_serial" shell pm grant "$BUNDLE_ID" android.permission.ACCESS_COARSE_LOCATION || true
wait_for_app_foreground() {
local package_name="$1"
for _ in {1..30}; do
if adb -s "$emulator_serial" shell dumpsys activity activities 2>/dev/null | grep -E 'mResumedActivity|topResumedActivity|mFocusedApp' | grep -Fq "$package_name"; then
return 0
fi
sleep 1
done
return 1
}
shots_dir="$GITHUB_WORKSPACE/artifacts/screenshots"
mkdir -p "$shots_dir"
printf "index,url,file\n" > "$shots_dir/manifest.csv"
adb -s "$emulator_serial" shell am start -W -n "$BUNDLE_ID/.MainActivity" >/dev/null 2>&1 || true
if ! wait_for_app_foreground "$BUNDLE_ID"; then
echo "::warning::App did not enter the foreground after initial launch."
fi
sleep "$STARTUP_WAIT_SECONDS"
adb -s "$emulator_serial" exec-out screencap -p > "$shots_dir/00-launch.png"
printf "00,launch,00-launch.png\n" >> "$shots_dir/manifest.csv"
DEEP_LINKS_INPUT="$(cat <<'EOF'
${{ github.event.inputs.deep_links }}
EOF
)"
deep_links="$(
printf '%s\n' "$DEEP_LINKS_INPUT" \
| tr -d '\r' \
| tr ',' '\n' \
| sed -E 's#([A-Za-z][A-Za-z0-9+.-]*://)#\n\1#g' \
| sed -E 's/^[[:space:]]+//; s/[[:space:]]+$//' \
| sed '/^[[:space:]]*$/d'
)"
if [ -n "$deep_links" ]; then
index=1
while IFS= read -r url; do
[ -z "$url" ] && continue
slug="$(printf '%s' "$url" | sed -E 's#^[a-zA-Z][a-zA-Z0-9+.-]*://##; s#[^A-Za-z0-9._-]+#-#g; s#-+#-#g; s#^-##; s#-$##')"
if [ -z "$slug" ]; then
slug="screen-$index"
fi
filename="$(printf '%02d' "$index")-$slug.png"
if adb -s "$emulator_serial" shell am start -W -a android.intent.action.VIEW -d "$url" "$BUNDLE_ID" >/dev/null 2>&1 </dev/null; then
if ! wait_for_app_foreground "$BUNDLE_ID"; then
echo "::warning::Deep link opened but app is not foregrounded: $url"
index=$((index + 1))
continue
fi
sleep "$PER_PAGE_WAIT_SECONDS"
adb -s "$emulator_serial" exec-out screencap -p > "$shots_dir/$filename"
printf "%02d,%s,%s\n" "$index" "$url" "$filename" >> "$shots_dir/manifest.csv"
else
echo "::warning::Failed to open deep link: $url"
fi
index=$((index + 1))
done <<< "$deep_links"
fi
{
echo "emulator_serial=$emulator_serial"
echo "emulator_pid=$emulator_pid"
} >> "$GITHUB_OUTPUT"
- name: Shutdown emulator
if: always()
run: |
set -euo pipefail
emulator_serial="${{ steps.capture.outputs.emulator_serial }}"
emulator_pid="${{ steps.capture.outputs.emulator_pid }}"
if [ -n "$emulator_serial" ]; then
adb -s "$emulator_serial" emu kill || true
fi
if [ -n "$emulator_pid" ] && kill -0 "$emulator_pid" >/dev/null 2>&1; then
kill "$emulator_pid" || true
fi
- name: Package screenshots archive
id: package_archive
run: |
set -euo pipefail
screenshots_dir="$GITHUB_WORKSPACE/artifacts/screenshots"
release_dir="$GITHUB_WORKSPACE/artifacts/release"
archive_name="android-emulator-screenshots-${GITHUB_RUN_ID}.zip"
archive_path="$release_dir/$archive_name"
if [ ! -d "$screenshots_dir" ]; then
echo "Screenshots directory not found: $screenshots_dir"
exit 1
fi
mkdir -p "$release_dir"
ditto -c -k --sequesterRsrc --keepParent "$screenshots_dir" "$archive_path"
{
echo "archive_name=$archive_name"
echo "archive_path=$archive_path"
} >> "$GITHUB_OUTPUT"
- name: Upload screenshots artifact
uses: actions/upload-artifact@v4
with:
name: android-emulator-screenshots-${{ github.run_id }}
path: ${{ steps.package_archive.outputs.archive_path }}
if-no-files-found: error
- name: Resolve latest GitHub release
id: latest_release
uses: actions/github-script@v7
with:
script: |
try {
const { data: release } = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo,
});
core.info(`Using latest release: ${release.tag_name} (id: ${release.id})`);
core.setOutput("release_id", String(release.id));
core.setOutput("tag_name", release.tag_name);
} catch (error) {
core.setFailed(`Unable to resolve latest release: ${error.message}`);
}
- name: Attach screenshots archive to latest release
uses: actions/github-script@v7
env:
RELEASE_ID: ${{ steps.latest_release.outputs.release_id }}
RELEASE_TAG_NAME: ${{ steps.latest_release.outputs.tag_name }}
SCREENSHOTS_ARCHIVE_NAME: ${{ steps.package_archive.outputs.archive_name }}
SCREENSHOTS_ARCHIVE_PATH: ${{ steps.package_archive.outputs.archive_path }}
with:
script: |
const fs = require("fs");
const owner = context.repo.owner;
const repo = context.repo.repo;
const releaseId = Number(process.env.RELEASE_ID);
const releaseTag = process.env.RELEASE_TAG_NAME || "unknown";
const archiveName = process.env.SCREENSHOTS_ARCHIVE_NAME || "";
const archivePath = process.env.SCREENSHOTS_ARCHIVE_PATH || "";
if (!Number.isFinite(releaseId) || releaseId <= 0) {
core.setFailed(`Invalid release id: ${process.env.RELEASE_ID}`);
return;
}
if (!archiveName || !archivePath) {
core.setFailed("Screenshot archive metadata is missing.");
return;
}
if (!fs.existsSync(archivePath)) {
core.setFailed(`Screenshots archive not found: ${archivePath}`);
return;
}
const existingAssets = await github.paginate(github.rest.repos.listReleaseAssets, {
owner,
repo,
release_id: releaseId,
per_page: 100,
});
const existingAssetsByName = new Map(existingAssets.map((asset) => [asset.name, asset]));
const previous = existingAssetsByName.get(archiveName);
if (previous) {
await github.rest.repos.deleteReleaseAsset({
owner,
repo,
asset_id: previous.id,
});
core.info(`Deleted existing asset: ${archiveName}`);
}
const data = fs.readFileSync(archivePath);
await github.rest.repos.uploadReleaseAsset({
owner,
repo,
release_id: releaseId,
name: archiveName,
data,
});
core.info(`Uploaded ${archiveName} to release ${releaseTag}`);