mirror of
https://github.com/tester-army/e2e.git
synced 2026-11-22 18:19:48 +08:00
* feat(cli): show step keys under the summary and view the screen and app log The --step and screen.pause() prompt now lists its keys below the live summary, as --watch does, and the held step row uses a pause glyph. Press s for the screen's accessibility tree or l for the attempt's app log. Both open in a scrolling viewer on the alternate screen. The app log is read from the worker during the hold through a new logs-request and logs-reply message pair. The mode without a terminal keeps its text. * feat(cli): stop the terminal's Duration row while a step is held The list reporter's Duration row counted wall time, so it kept ticking at a --step prompt or a screen.pause(). The scheduler now reports when the first hold opens and the last closes through a run-hold event, and the row excludes that time, live and in the final summary. report.json and the reports built from it keep wall time. * feat(report): add run.durationMs without held time The report only had the run's start and finish timestamps, so a run that waited at a --step prompt or a screen.pause() looked as long as the wait. run.durationMs is the run's duration with held time left out. The terminal's final Duration row prints the same value. Markdown, the GitHub comment, the HTML report, and telemetry read it in place of the timestamp difference. startedAt and finishedAt still record wall time. A simplification review also removed a few flags and options from the step viewer and the hold path, and the docs keep each new fact in one place. * docs: trim the step viewer changeset and docs The changeset is down to two sentences. The docs no longer say where the keys are, since the terminal sample shows it, and the json reporter section matches main again. * fix(cli): print the viewer's text before the prompt is repainted On p, the viewer closed first, so the live window was repainted and then erased again for the printed text. That left a blank frame. The text is now queued before the viewer closes, and the window is repainted once. * fix(cli): number the step prompt by its trace position The app log view numbered its lines by the recorder's step index, which counts nested steps, while the prompt counted held steps only. A line logged inside a nested step could show a different number than the prompt. The worker now sends each held step's position in the trace, so the prompt, the app log view, and the trace page use one number. The viewer's try blocks are removed too. Nothing received their rethrows, and the guarded calls don't throw. * fix(cli): count held time only while every running worker is held With several workers, a screen.pause() in one test took the time other tests spent running out of the run's duration. A run could read shorter than one of its tests. An interval now counts as held only while every running worker is held. The time limit keeps its rule. Also from review: - A routing state an older installed copy made is upgraded in place, so claimProcessOutput() no longer throws. - The viewer holds writes only for terminal streams. - Ctrl-Z closes the viewer and suspends. - A failed screen read can be retried during the same hold. - p is ignored while a read is pending. - The app log view shows plain text, not Markdown code spans. - The viewer's help row starts with q, and its headings use the redacted title and target. * test(cli): cover an older dispatcher installed on the streams The upgrade test seeded a state with no dispatchers. This one installs an older copy's dispatchers first, then checks that writes are held while the viewer is open. The comment on that branch loses its FIXME prefix. It describes what the code does.
130 lines
5.5 KiB
TypeScript
130 lines
5.5 KiB
TypeScript
/**
|
|
* Posts the nightly examples run to Slack as one message
|
|
* (`.github/workflows/examples.yml`, the `summary` job).
|
|
*
|
|
* Reads every `outcome.json` (and the `report.json` beside it, when the tests
|
|
* ran, and `first-pass/second-pass`, when `run-tests.sh` gave the suite a
|
|
* second pass) under the directory given as the first argument, one directory per
|
|
* matrix job, as `actions/download-artifact` lays them out. Lists the run's
|
|
* jobs through the API to link each line to its log and to name a job that
|
|
* ended without writing an outcome.
|
|
*
|
|
* Environment: `SLACK_EXAMPLES_NIGHTLY_WEBHOOK_URL` (an incoming webhook; without it the
|
|
* message is printed and the script exits 1), `GITHUB_TOKEN`,
|
|
* `GITHUB_REPOSITORY`, `GITHUB_RUN_ID`, `GITHUB_RUN_ATTEMPT`,
|
|
* `GITHUB_SERVER_URL`, `GITHUB_SHA`, `PACK_RESULT` (the `pack` job's
|
|
* result), and `PACK_CREDENTIAL` (`missing` when the model key stopped it). `--dry-run` prints the message and posts nothing.
|
|
*/
|
|
|
|
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
import { formatMessage, type Outcome, type ReportCounts, type Row, type SecondPass } from './format.ts';
|
|
|
|
const MATRIX_JOB = /^(web|android|ios) /;
|
|
|
|
type NightlyReport = {
|
|
run: { durationMs?: number; summary: Omit<ReportCounts, 'durationMs'> };
|
|
};
|
|
|
|
/** The counts and duration of one `report-1` file. */
|
|
function readReport(path: string): ReportCounts | undefined {
|
|
if (!existsSync(path)) return undefined;
|
|
const { run }: NightlyReport = JSON.parse(readFileSync(path, 'utf8'));
|
|
const { passed, failed, flaky, skipped, interrupted } = run.summary;
|
|
return {
|
|
passed,
|
|
failed,
|
|
flaky,
|
|
skipped,
|
|
interrupted,
|
|
...(run.durationMs === undefined ? {} : { durationMs: run.durationMs }),
|
|
};
|
|
}
|
|
|
|
/** The second pass `run-tests.sh` recorded, if the suite needed one. */
|
|
function readSecondPass(path: string): SecondPass | undefined {
|
|
if (!existsSync(path)) return undefined;
|
|
const kind = readFileSync(path, 'utf8').trim();
|
|
return kind === 'last-failed' || kind === 'full' ? kind : undefined;
|
|
}
|
|
|
|
/** The run's jobs by name, with their log URLs; undefined when the API cannot be read. */
|
|
async function listJobs(): Promise<Map<string, string> | undefined> {
|
|
const { GITHUB_TOKEN, GITHUB_REPOSITORY, GITHUB_RUN_ID, GITHUB_RUN_ATTEMPT } = process.env;
|
|
if (!GITHUB_TOKEN || !GITHUB_REPOSITORY || !GITHUB_RUN_ID) return undefined;
|
|
const jobs = new Map<string, string>();
|
|
const url = `https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}/attempts/${GITHUB_RUN_ATTEMPT ?? '1'}/jobs?per_page=100`;
|
|
try {
|
|
const response = await fetch(url, {
|
|
headers: { authorization: `Bearer ${GITHUB_TOKEN}`, accept: 'application/vnd.github+json' },
|
|
});
|
|
if (!response.ok) throw new Error(`${response.status} ${response.statusText}`);
|
|
const body = (await response.json()) as { jobs: { name: string; html_url: string }[] };
|
|
for (const job of body.jobs) jobs.set(job.name, job.html_url);
|
|
} catch (error) {
|
|
process.stderr.write(`::warning::could not list the run's jobs: ${String(error)}\n`);
|
|
return undefined;
|
|
}
|
|
return jobs;
|
|
}
|
|
|
|
/** Why the `pack` job stopped the run, if it did. */
|
|
function packBlocked(): 'credential' | 'pack' | undefined {
|
|
const result = process.env.PACK_RESULT;
|
|
if (result === undefined || result === 'success') return undefined;
|
|
return process.env.PACK_CREDENTIAL === 'missing' ? 'credential' : 'pack';
|
|
}
|
|
|
|
const dir = process.argv.slice(2).find((arg) => !arg.startsWith('--'));
|
|
const dryRun = process.argv.includes('--dry-run');
|
|
if (dir === undefined) {
|
|
process.stderr.write('usage: node scripts/examples-nightly/post.ts <outcomes dir> [--dry-run]\n');
|
|
process.exit(2);
|
|
}
|
|
|
|
const jobs = await listJobs();
|
|
const rows: Row[] = [];
|
|
for (const entry of existsSync(dir) ? readdirSync(dir) : []) {
|
|
const outcomePath = join(dir, entry, 'outcome.json');
|
|
if (!existsSync(outcomePath)) continue;
|
|
const outcome = JSON.parse(readFileSync(outcomePath, 'utf8')) as Outcome;
|
|
const report = readReport(join(dir, entry, 'report.json'));
|
|
const secondPass = readSecondPass(join(dir, entry, 'first-pass', 'second-pass'));
|
|
const jobUrl = jobs?.get(outcome.job);
|
|
rows.push({
|
|
outcome,
|
|
...(report === undefined ? {} : { report }),
|
|
...(secondPass === undefined ? {} : { secondPass }),
|
|
...(jobUrl === undefined ? {} : { jobUrl }),
|
|
});
|
|
}
|
|
const reported = new Set(rows.map((row) => row.outcome.job));
|
|
const missing = [...(jobs?.keys() ?? [])].filter((name) => MATRIX_JOB.test(name) && !reported.has(name));
|
|
|
|
const blocked = packBlocked();
|
|
const server = process.env.GITHUB_SERVER_URL ?? 'https://github.com';
|
|
const message = formatMessage(rows, {
|
|
runUrl: `${server}/${process.env.GITHUB_REPOSITORY ?? ''}/actions/runs/${process.env.GITHUB_RUN_ID ?? ''}`,
|
|
sha: process.env.GITHUB_SHA ?? 'unknown',
|
|
...(blocked === undefined ? {} : { blocked }),
|
|
missing,
|
|
jobsUnknown: jobs === undefined,
|
|
});
|
|
process.stdout.write(`${message}\n`);
|
|
|
|
const webhook = process.env.SLACK_EXAMPLES_NIGHTLY_WEBHOOK_URL;
|
|
if (dryRun) process.exit(0);
|
|
if (!webhook) {
|
|
process.stderr.write('::error::SLACK_EXAMPLES_NIGHTLY_WEBHOOK_URL is not set for this repository, so the summary was not posted.\n');
|
|
process.exit(1);
|
|
}
|
|
const response = await fetch(webhook, {
|
|
method: 'POST',
|
|
headers: { 'content-type': 'application/json' },
|
|
body: JSON.stringify({ text: message }),
|
|
});
|
|
if (!response.ok) {
|
|
process.stderr.write(`::error::Slack refused the summary: ${response.status} ${await response.text()}\n`);
|
|
process.exit(1);
|
|
}
|