Skip to content

Commit 98916c1

Browse files
committed
temp: run the device job's steps that need no key (android)
Dropped before review.
1 parent 21ca70f commit 98916c1

3 files changed

Lines changed: 376 additions & 0 deletions

File tree

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
import { execFileSync } from 'node:child_process';
2+
import { mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
3+
import { join } from 'node:path';
4+
import { isRunning } from '../src/core/exec.ts';
5+
import type {
6+
BuildKey,
7+
DeviceBackend,
8+
HostEntry,
9+
LocalLease,
10+
Platform,
11+
RuntimeProcess,
12+
ScratchPath,
13+
} from '../src/core/types.ts';
14+
import { APP_ID } from '../src/fixture.ts';
15+
import { host, metroPort } from '../src/host.ts';
16+
import { sdkTool } from '../src/platform/android/sdk.ts';
17+
18+
const SKILL = join(import.meta.dirname, '..');
19+
const WORKTREE = join(SKILL, '..', '..', '..');
20+
const STATE = join(SKILL, '.verify', 'ci-device-proof.json');
21+
22+
interface State {
23+
readonly lease: LocalLease;
24+
readonly entry: HostEntry;
25+
readonly processes: readonly RuntimeProcess[];
26+
}
27+
28+
const log = (line: string) => console.log(line);
29+
const seconds = (since: number) => `${Math.round((Date.now() - since) / 1000)}s`;
30+
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));
31+
32+
function backendFor(platform: Platform): DeviceBackend<LocalLease> {
33+
const backend = host.backends.find(b => b.kind === 'local' && b.platform === platform);
34+
if (backend === undefined) throw new Error(`no local ${platform} backend`);
35+
return backend as unknown as DeviceBackend<LocalLease>;
36+
}
37+
38+
const readState = (): State => JSON.parse(readFileSync(STATE, 'utf8')) as State;
39+
40+
async function metroStatus(lease: LocalLease): Promise<string> {
41+
const response = await fetch(`http://127.0.0.1:${metroPort(lease)}/status`, { signal: AbortSignal.timeout(5000) });
42+
return response.text();
43+
}
44+
45+
async function up(platform: Platform): Promise<void> {
46+
const backend = backendFor(platform);
47+
const availability = backend.availability();
48+
log(`local usable=${availability.usable} ${availability.why}`);
49+
if (!availability.usable) process.exit(1);
50+
const into = join(SKILL, '.verify', 'builds', 'proof') as ScratchPath;
51+
mkdirSync(into, { recursive: true });
52+
let started = Date.now();
53+
const app = await host.build(platform, `${platform}-proof0000000` as BuildKey, into, log);
54+
if (app.path === null) throw new Error('the build has no path');
55+
log(`build ${seconds(started)} ${app.source} ${app.path}`);
56+
started = Date.now();
57+
const acquired = await backend.acquire({
58+
platform,
59+
worktree: WORKTREE,
60+
waitSeconds: 0,
61+
app,
62+
progress: log,
63+
retryWith: 'proof',
64+
});
65+
log(`lease ${seconds(started)} ${acquired.deviceName} (${acquired.deviceId})`);
66+
mkdirSync(join(SKILL, '.verify', 'leases'), { recursive: true });
67+
const leaseFile = join(SKILL, '.verify', 'leases', `${platform}.json`);
68+
writeFileSync(leaseFile, JSON.stringify(acquired, null, 2));
69+
started = Date.now();
70+
const lease = await backend.install(acquired, app, log);
71+
writeFileSync(leaseFile, JSON.stringify(lease, null, 2));
72+
log(`install ${seconds(started)}`);
73+
log(`check ${await backend.check(lease)}`);
74+
if (host.runtime === undefined) throw new Error('the host has no runtime');
75+
started = Date.now();
76+
const runtime = await host.runtime(lease, log);
77+
log(`runtime ${seconds(started)} ${runtime.processes.map(p => `${p.what} ${p.pid}`).join(', ')}`);
78+
log(`entry ${JSON.stringify(runtime.entry)}`);
79+
writeFileSync(STATE, JSON.stringify({ lease, entry: runtime.entry, processes: runtime.processes }, null, 2));
80+
log(`metro :${metroPort(lease)} ${(await metroStatus(lease)).trim()}`);
81+
}
82+
83+
async function alive(platform: Platform): Promise<void> {
84+
const state = readState();
85+
const held = await backendFor(platform).check(state.lease);
86+
log(`check ${held}`);
87+
let ok = held === 'held';
88+
for (const ref of state.processes) {
89+
const running = isRunning(ref);
90+
log(`${ref.what.padEnd(7)} pid ${ref.pid} ${running ? 'still running' : 'GONE'}`);
91+
ok &&= running;
92+
}
93+
const status = (await metroStatus(state.lease)).trim();
94+
log(`metro :${metroPort(state.lease)} ${status}`);
95+
ok &&= status.includes('packager-status:running');
96+
if (!ok) {
97+
console.error('the device or the runtime did not outlive the step that started it');
98+
process.exit(1);
99+
}
100+
}
101+
102+
async function launch(platform: Platform, shot: string): Promise<void> {
103+
const { lease, entry } = readState();
104+
if (entry.kind !== 'dev-client') throw new Error('not a dev client entry');
105+
if (platform === 'ios') {
106+
execFileSync('xcrun', ['simctl', 'launch', lease.deviceId, APP_ID, ...entry.launchArguments], { stdio: 'inherit' });
107+
} else {
108+
const adb = sdkTool('adb');
109+
execFileSync(
110+
adb,
111+
[
112+
'-s',
113+
lease.deviceId,
114+
'shell',
115+
`am start -a android.intent.action.VIEW -d '${entry.openLink}' -n ${APP_ID}/${entry.androidActivity}`,
116+
],
117+
{ stdio: 'inherit' },
118+
);
119+
}
120+
for (const n of [1, 2]) {
121+
await sleep(45_000);
122+
const file = shot.replace(/\.png$/, `-${n}.png`);
123+
if (platform === 'ios') execFileSync('xcrun', ['simctl', 'io', lease.deviceId, 'screenshot', file], { stdio: 'inherit' });
124+
else
125+
writeFileSync(
126+
file,
127+
execFileSync(sdkTool('adb'), ['-s', lease.deviceId, 'exec-out', 'screencap', '-p'], {
128+
maxBuffer: 64 * 1024 * 1024,
129+
}),
130+
);
131+
log(`shot ${file} ${statSync(file).size} bytes`);
132+
}
133+
if (platform === 'android') {
134+
const logcat = execFileSync(sdkTool('adb'), ['-s', lease.deviceId, 'logcat', '-d', '-s', 'ReactNativeJS:*'], {
135+
encoding: 'utf8',
136+
maxBuffer: 64 * 1024 * 1024,
137+
});
138+
log('---- ReactNativeJS lines in logcat that name the missing key');
139+
log(logcat.split('\n').filter(line => line.includes('EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY')).slice(0, 3).join('\n'));
140+
}
141+
const metroLog = join(SKILL, '.verify', 'runtime', `metro-${metroPort(lease)}.log`);
142+
log(`---- tail of ${metroLog}`);
143+
log(readFileSync(metroLog, 'utf8').split('\n').slice(-25).join('\n'));
144+
}
145+
146+
async function down(platform: Platform): Promise<void> {
147+
const state = readState();
148+
await backendFor(platform).release(state.lease);
149+
log(`released ${state.lease.deviceName}`);
150+
for (const ref of state.processes) {
151+
if (isRunning(ref)) process.kill(ref.pid, 'SIGTERM');
152+
log(`stopped ${ref.what} ${ref.pid}`);
153+
}
154+
}
155+
156+
const [verb, platformArg, extra] = process.argv.slice(2);
157+
if (platformArg !== 'ios' && platformArg !== 'android') {
158+
console.error('usage: ci-device-proof.ts up|alive|launch|down ios|android [screenshot.png]');
159+
process.exit(2);
160+
}
161+
try {
162+
if (verb === 'up') await up(platformArg);
163+
else if (verb === 'alive') await alive(platformArg);
164+
else if (verb === 'launch') await launch(platformArg, extra ?? 'launch.png');
165+
else if (verb === 'down') await down(platformArg);
166+
else throw new Error(`unknown verb ${verb}`);
167+
} catch (error) {
168+
console.error(error);
169+
process.exit(1);
170+
}
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
name: Verify device specs proof
2+
3+
on:
4+
push:
5+
branches:
6+
- mike/expo-verify-ci-device-specs
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
steps-before-the-key:
13+
name: Steps before the key (${{ matrix.platform }})
14+
runs-on: ${{ matrix.runner }}
15+
timeout-minutes: 45
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
include:
20+
- platform: android
21+
runner: ${{ vars.VERIFY_CI_RUNNER_ANDROID || 'blacksmith-8vcpu-ubuntu-2204' }}
22+
env:
23+
SKILL: .claude/skills/verify-clerk-expo
24+
CLI: .claude/skills/verify-clerk-expo/bin/control-clerk-expo
25+
PLATFORM: ${{ matrix.platform }}
26+
VERIFY_THROWAWAY_HOURS: '2'
27+
steps:
28+
- name: Checkout repo
29+
uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
30+
with:
31+
persist-credentials: false
32+
33+
- uses: pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4
34+
35+
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
36+
with:
37+
node-version: 24.15.0
38+
cache: pnpm
39+
40+
- name: Install monorepo dependencies
41+
run: pnpm install --frozen-lockfile
42+
43+
- name: Set up JDK 21
44+
if: matrix.platform == 'android'
45+
uses: actions/setup-java@cf277c60eb25467037889841efdb72551f06f6c3 # v4
46+
with:
47+
distribution: temurin
48+
java-version: 21
49+
50+
- name: Set up Gradle cache
51+
if: matrix.platform == 'android'
52+
uses: gradle/actions/setup-gradle@4733eaac7c1b0da527e4206b7671e0061de1ce37 # v6.3.0
53+
with:
54+
cache-read-only: false
55+
add-job-summary: never
56+
57+
- name: Enable KVM
58+
if: matrix.platform == 'android'
59+
run: |
60+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
61+
sudo udevadm control --reload-rules
62+
sudo udevadm trigger --name-match=kvm
63+
64+
- name: Install the emulator and its system image
65+
if: matrix.platform == 'android'
66+
run: |
67+
set -euo pipefail
68+
IMAGE="system-images;android-36;google_apis;x86_64"
69+
"$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" --install "$IMAGE" emulator platform-tools < /dev/null > "$RUNNER_TEMP/sdkmanager.log" 2>&1 \
70+
|| { echo "::error::sdkmanager could not install $IMAGE"; tail -20 "$RUNNER_TEMP/sdkmanager.log"; exit 1; }
71+
echo "$ANDROID_HOME/platform-tools" >> "$GITHUB_PATH"
72+
73+
- name: Create the template simulator that the skill clones
74+
if: matrix.platform == 'ios'
75+
run: |
76+
set -euo pipefail
77+
created="$(GITHUB_ENV=/dev/null integration/tests/expo-native/boot-ios-simulators.sh boot 1)"
78+
echo "$created"
79+
udid="${created##*: }"
80+
CLERK_TEST_DEVICES="$udid" integration/tests/expo-native/boot-ios-simulators.sh wait
81+
xcrun simctl shutdown "$udid"
82+
xcrun simctl rename "$udid" "Clerk Verify Template iOS"
83+
84+
- name: Install the verify skill
85+
id: install
86+
run: npm ci --prefix "$SKILL" --no-audit --no-fund
87+
88+
- name: Ask the real CLI what this runner can do, with no key
89+
run: |
90+
set +e -uo pipefail
91+
"$CLI" doctor --platform "$PLATFORM" --backend local
92+
echo "doctor exit=$?"
93+
"$CLI" up --platform "$PLATFORM" --backend local
94+
code=$?
95+
echo "up exit=$code"
96+
[ "$code" -eq 3 ] || { echo "::error::up without a key should stop with exit 3 before it builds"; exit 1; }
97+
98+
- name: Build, lease, install, and start Metro with the skill's own functions
99+
run: node "$SKILL/testing/ci-device-proof.ts" up "$PLATFORM"
100+
101+
- name: Read what the cloned simulator inherited from the template
102+
if: matrix.platform == 'ios'
103+
run: |
104+
set -euo pipefail
105+
udid="$(node -p 'JSON.parse(require("fs").readFileSync(process.argv[1], "utf8")).deviceId' "$SKILL/.verify/leases/ios.json")"
106+
xcrun simctl list devices | grep -E "Clerk Verify Template iOS|verify-ios-|iPhone 17 Pro"
107+
xcrun simctl spawn "$udid" defaults read com.apple.keyboard.preferences
108+
xcrun simctl spawn "$udid" defaults read com.apple.UIKit UIAnimationDragCoefficient
109+
xcrun simctl get_app_container "$udid" com.clerk.exponativebuildfixture app
110+
111+
- name: Read the installed app on the emulator
112+
if: matrix.platform == 'android'
113+
run: |
114+
set -euo pipefail
115+
ls -l /dev/kvm
116+
adb devices
117+
adb -s emulator-5560 shell pm path com.clerk.exponativebuildfixture
118+
adb -s emulator-5560 shell getprop ro.build.version.sdk
119+
adb -s emulator-5560 reverse --list
120+
121+
- name: Compile the XCTest runner before the first spec launches
122+
if: matrix.platform == 'ios'
123+
timeout-minutes: 20
124+
run: |
125+
set -euo pipefail
126+
udid="$(node -p 'JSON.parse(require("fs").readFileSync(process.argv[1], "utf8")).deviceId' "$SKILL/.verify/leases/ios.json")"
127+
AGENT_DEVICE_STATE_DIR="$GITHUB_WORKSPACE/$SKILL/.verify/agent-device" \
128+
"$SKILL/node_modules/.bin/agent-device" prepare ios-runner --platform ios --udid "$udid" --timeout 900000 \
129+
|| echo "::warning::prepare ios-runner failed; the first spec pays for it"
130+
131+
- name: Check that the device and Metro outlived the step that started them
132+
run: node "$SKILL/testing/ci-device-proof.ts" alive "$PLATFORM"
133+
134+
- name: Launch the dev client once with no Clerk key and take two screenshots
135+
continue-on-error: true
136+
timeout-minutes: 5
137+
run: node "$SKILL/testing/ci-device-proof.ts" launch "$PLATFORM" "$RUNNER_TEMP/launch.png"
138+
139+
- name: Release with the skill's own function
140+
if: always() && steps.install.outcome == 'success'
141+
run: node "$SKILL/testing/ci-device-proof.ts" down "$PLATFORM"
142+
143+
- name: Write a stand-in for one sealed run
144+
run: |
145+
set -euo pipefail
146+
run="$SKILL/.verify/runs/r00000000-000000-0000"
147+
mkdir -p "$run/e2e/failures" "$run/e2e-2" "$run/screenshots"
148+
echo '{"run":"r00000000-000000-0000","sealed":true,"tainted":[],"note":"a stand-in written by the proof workflow; no spec ran"}' > "$run/run.json"
149+
echo "Stand-in summary of group 1 on $PLATFORM. No spec ran." > "$run/e2e/summary.md"
150+
echo "Stand-in summary of group 2 on $PLATFORM. No spec ran." > "$run/e2e-2/summary.md"
151+
echo "stand-in" > "$run/e2e/failures/page.html"
152+
echo "stand-in" > "$run/screenshots/stand-in.txt"
153+
cp "$RUNNER_TEMP"/launch-*.png "$run/screenshots/" || true
154+
echo "must not be uploaded" > "$run/app.log"
155+
echo "must not be uploaded" > "$run/e2e/e2e.log"
156+
echo "must not be uploaded" > "$run/states.jsonl"
157+
158+
- name: Check that every run is sealed
159+
id: evidence
160+
if: ${{ !cancelled() && steps.install.outcome == 'success' }}
161+
run: |
162+
node -e '
163+
const fs = require("fs");
164+
const path = require("path");
165+
const runs = path.join(process.env.SKILL, ".verify", "runs");
166+
const ids = fs.existsSync(runs) ? fs.readdirSync(runs) : [];
167+
let upload = ids.length > 0;
168+
for (const id of ids) {
169+
let record = null;
170+
try { record = JSON.parse(fs.readFileSync(path.join(runs, id, "run.json"), "utf8")); } catch {}
171+
if (record === null || record.sealed !== true || record.tainted.length > 0) {
172+
upload = false;
173+
console.log("::warning::Run " + id + " was not sealed, or a file in it holds a secret value. No evidence is uploaded.");
174+
}
175+
}
176+
fs.appendFileSync(process.env.GITHUB_OUTPUT, "upload=" + upload + "\n");
177+
'
178+
179+
- name: Summarize the run
180+
if: ${{ !cancelled() && steps.evidence.outputs.upload == 'true' }}
181+
run: |
182+
for summary in "$SKILL"/.verify/runs/*/e2e/summary.md "$SKILL"/.verify/runs/*/e2e-*/summary.md; do
183+
if [ -f "$summary" ]; then
184+
cat "$summary" >> "$GITHUB_STEP_SUMMARY"
185+
fi
186+
done
187+
188+
- name: Upload the evidence
189+
if: ${{ !cancelled() && steps.evidence.outputs.upload == 'true' }}
190+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
191+
with:
192+
name: verify-device-specs-${{ matrix.platform }}
193+
overwrite: true
194+
include-hidden-files: true
195+
path: |
196+
${{ env.SKILL }}/.verify/runs/*/run.json
197+
${{ env.SKILL }}/.verify/runs/*/video.mp4
198+
${{ env.SKILL }}/.verify/runs/*/screenshots
199+
${{ env.SKILL }}/.verify/runs/*/e2e*/summary.md
200+
${{ env.SKILL }}/.verify/runs/*/e2e*/failures
201+
${{ env.SKILL }}/.verify/runs/*/e2e*/artifacts
202+
retention-days: 3
203+
if-no-files-found: warn

‎.github/workflows/verify-device-specs.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ on:
1515
- 'packages/expo-biometrics/**'
1616
- 'packages/expo-google-signin/**'
1717
workflow_dispatch:
18+
push:
19+
branches:
20+
- mike/expo-verify-ci-device-specs
1821

1922
permissions:
2023
contents: read

0 commit comments

Comments
 (0)