tool(app): capture, full-check and preview-publish scripts for the Flutter pipelines
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
#!/bin/sh
|
||||
# Landing gate for app/ changes: analyze, then the full test suite.
|
||||
#
|
||||
# Usage (from app/): sh tool/check_full.sh
|
||||
# Exits 0 only when `flutter analyze` reports no issues and the full suite
|
||||
# prints `All tests passed!`. A piped `tail` cannot hide a failure here: the
|
||||
# verdict comes from the suite's own final line, which is echoed with the
|
||||
# totals. Logs go to build/check/ for the caller's evidence.
|
||||
set -u
|
||||
FLUTTER="${FLUTTER:-/Users/alan/development/flutter/bin/flutter}"
|
||||
mkdir -p build/check
|
||||
"$FLUTTER" analyze > build/check/analyze.log 2>&1
|
||||
if ! grep -q "No issues found" build/check/analyze.log; then
|
||||
grep -E " • " build/check/analyze.log
|
||||
echo "CHECK FAILED: flutter analyze reported issues (build/check/analyze.log)"
|
||||
exit 1
|
||||
fi
|
||||
"$FLUTTER" test > build/check/test.log 2>&1
|
||||
verdict=$(grep -E "All tests passed!|Some tests failed" build/check/test.log | tail -1)
|
||||
if ! echo "$verdict" | grep -q "All tests passed!"; then
|
||||
grep -E "\[E\]" build/check/test.log | head -20
|
||||
echo "CHECK FAILED: $verdict (build/check/test.log)"
|
||||
exit 1
|
||||
fi
|
||||
echo "CHECK PASSED: analyze clean; $verdict"
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
# Publishes the app to the preview served from build/web, keeping a rollback.
|
||||
#
|
||||
# Usage (from app/ on main): sh tool/publish_preview.sh <name>
|
||||
# Builds into build/web-next, then renames build/web to
|
||||
# build/web-before-<name>-<epoch> and build/web-next to build/web, so the
|
||||
# preview server never sees a half-written bundle. Prints the rollback
|
||||
# directory and the new main.dart.js hash. Never restarts any server.
|
||||
set -eu
|
||||
name="${1:?usage: sh tool/publish_preview.sh <name>}"
|
||||
FLUTTER="${FLUTTER:-/Users/alan/development/flutter/bin/flutter}"
|
||||
"$FLUTTER" build web -o build/web-next
|
||||
rollback="build/web-before-${name}-$(date +%s)"
|
||||
if [ -d build/web ]; then mv build/web "$rollback"; fi
|
||||
mv build/web-next build/web
|
||||
echo "ROLLBACK $rollback"
|
||||
echo "JS $(shasum build/web/main.dart.js | cut -c1-8)"
|
||||
@@ -0,0 +1,53 @@
|
||||
// Screenshots routes of the real app bundle at phone and desktop size.
|
||||
//
|
||||
// Usage (from app/):
|
||||
// flutter build web -o build/web
|
||||
// node tool/shoot_real_app.mjs build/web <out-dir> /chat /runs/1 /settings
|
||||
//
|
||||
// The bundle is served by the Runs probe fixture (tool/runs_probe_server.mjs),
|
||||
// which answers the app's real protocol on loopback: no Pipelines server or
|
||||
// operator data is touched. Each route is captured with Chrome DevTools device
|
||||
// emulation at 390x844 (mobile) and 1280x800, as <route>-<width>.png. A
|
||||
// self-contained bundle (a probe entry with its own fixture gateway, such as
|
||||
// tool/pipelines_probe_entry.dart) can be served the same way with route `/`.
|
||||
// SHOOT_WAIT (ms, default 4000) is the settle time per capture.
|
||||
import { spawn } from 'node:child_process';
|
||||
import { mkdtemp, mkdir, writeFile } from 'node:fs/promises';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join, resolve } from 'node:path';
|
||||
import { setTimeout as delay } from 'node:timers/promises';
|
||||
const [build, out, ...routes] = process.argv.slice(2);
|
||||
if (!build || !out || routes.length === 0) {
|
||||
console.error("usage: node tool/shoot_real_app.mjs <build-dir> <out-dir> <route>...");
|
||||
process.exit(64);
|
||||
}
|
||||
const { startFixture } = await import(new URL("./runs_probe_server.mjs", import.meta.url).href);
|
||||
const fixture = await startFixture({ root: resolve(build) });
|
||||
await mkdir(out, { recursive: true });
|
||||
const port = 9300 + Math.floor(Math.random() * 500);
|
||||
const chrome = spawn(process.env.CHROME_PATH ?? '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
||||
['--headless=new', '--disable-gpu', '--hide-scrollbars', `--remote-debugging-port=${port}`,
|
||||
`--user-data-dir=${await mkdtemp(join(tmpdir(), 'shoot-'))}`, 'about:blank'], { stdio: 'ignore' });
|
||||
let target;
|
||||
for (let i = 0; i < 50 && !target; i++) {
|
||||
try { target = (await (await fetch(`http://127.0.0.1:${port}/json`)).json()).find(t => t.type === 'page'); } catch {}
|
||||
if (!target) await delay(200);
|
||||
}
|
||||
const ws = new WebSocket(target.webSocketDebuggerUrl);
|
||||
await new Promise(r => ws.addEventListener('open', r, { once: true }));
|
||||
let seq = 0; const pending = new Map();
|
||||
ws.addEventListener('message', e => { const m = JSON.parse(e.data); if (m.id && pending.has(m.id)) { pending.get(m.id)(m); pending.delete(m.id); } });
|
||||
const send = (method, params = {}) => new Promise(r => { const id = ++seq; pending.set(id, r); ws.send(JSON.stringify({ id, method, params })); });
|
||||
try {
|
||||
for (const route of routes) {
|
||||
for (const [w, h, mobile] of [[390, 844, true], [1280, 800, false]]) {
|
||||
await send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: 1, mobile });
|
||||
await send('Page.navigate', { url: fixture.url + route });
|
||||
await delay(Number(process.env.SHOOT_WAIT ?? 4000));
|
||||
const shot = await send('Page.captureScreenshot', { format: 'png' });
|
||||
const name = `${route.replace(/[^a-z0-9]+/gi, '_').replace(/^_|_$/g, '') || 'root'}-${w}.png`;
|
||||
await writeFile(join(out, name), Buffer.from(shot.result.data, 'base64'));
|
||||
console.log(join(out, name));
|
||||
}
|
||||
}
|
||||
} finally { ws.close(); chrome.kill(); await fixture.close(); }
|
||||
Reference in New Issue
Block a user