mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 13:12:26 +00:00
fix(ci): count named artifact transfers in job timings (#12253)
* fix(ci): count named artifact transfers in job timings * fix(ci): cover named artifact timings against their workflows --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
1 parent
bf04d616fd
commit
8045010f28
2 files changed
+97
-3
No files matched your search
@@ -8,10 +8,29 @@ const execFileAsync = promisify(execFile);
|
||||
const MAX_BUFFER = 16 * 1024 * 1024;
|
||||
const TIMEOUT_MS = 30_000;
|
||||
const OUTPUT_DIRECTORY = join(".cache", "ci-job-timings");
|
||||
// The jobs API returns display names, without the action reference. Tests
|
||||
// check these exceptions against the CI and Release workflow definitions.
|
||||
const STEP_COSTS = [
|
||||
{ key: "npmCi", pattern: /\bnpm ci\b/iu },
|
||||
{ key: "artifactUpload", pattern: /upload.*artifact/iu },
|
||||
{ key: "artifactDownload", pattern: /download.*artifact/iu },
|
||||
{
|
||||
key: "artifactUpload",
|
||||
pattern: /upload.*artifact/iu,
|
||||
names: new Set([
|
||||
"Upload complete static diagnostics",
|
||||
"Upload complete deep static diagnostics",
|
||||
"Retain available reverse tools diagnostics",
|
||||
"Publish successful timing history",
|
||||
"Retain the exact qualified release package",
|
||||
]),
|
||||
},
|
||||
{
|
||||
key: "artifactDownload",
|
||||
pattern: /download.*artifact/iu,
|
||||
names: new Set([
|
||||
"Download previous timing report",
|
||||
"Download the original qualified package",
|
||||
]),
|
||||
},
|
||||
];
|
||||
|
||||
/** Fetch and summarize one workflow attempt without turning telemetry into a gate. */
|
||||
@@ -221,7 +240,9 @@ function normalizeStep(step) {
|
||||
typeof step.name !== "string"
|
||||
)
|
||||
throw new Error("GitHub jobs API contains a malformed job step");
|
||||
const cost = STEP_COSTS.find(({ pattern }) => pattern.test(step.name));
|
||||
const cost = STEP_COSTS.find(
|
||||
({ pattern, names }) => names?.has(step.name) || pattern.test(step.name),
|
||||
);
|
||||
return {
|
||||
name: step.name,
|
||||
costKey: cost?.key ?? null,
|
||||
|
||||
@@ -3,6 +3,8 @@ import { delimiter, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { expect, it } from "vitest";
|
||||
import { parse } from "yaml";
|
||||
import { z } from "zod";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import {
|
||||
@@ -147,6 +149,77 @@ it("merges paginated jobs, reports elapsed metrics, and preserves raw responses"
|
||||
]);
|
||||
});
|
||||
|
||||
const workflowSteps = z.object({
|
||||
jobs: z.record(
|
||||
z.string(),
|
||||
z.object({
|
||||
steps: z
|
||||
.array(
|
||||
z.object({
|
||||
name: z.string().optional(),
|
||||
uses: z.string().optional(),
|
||||
}),
|
||||
)
|
||||
.optional(),
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
it.each(["ci.yml", "release.yml"])(
|
||||
"counts artifact actions from %s under their jobs API names",
|
||||
async (filename) => {
|
||||
const { jobs } = workflowSteps.parse(
|
||||
parse(
|
||||
await readFile(
|
||||
new URL(`../../../.github/workflows/${filename}`, import.meta.url),
|
||||
"utf8",
|
||||
),
|
||||
),
|
||||
);
|
||||
const steps = Object.values(jobs).flatMap(({ steps }) => steps ?? []);
|
||||
const namesFor = (action: string) =>
|
||||
steps
|
||||
.filter(({ uses }) => uses?.startsWith(`actions/${action}-artifact@`))
|
||||
.map(({ name, uses }) => name ?? `Run ${uses}`);
|
||||
const uploads = namesFor("upload");
|
||||
const downloads = namesFor("download");
|
||||
expect(uploads.length + downloads.length).toBeGreaterThan(0);
|
||||
const fixture = await createFixture([
|
||||
{
|
||||
jobs: [
|
||||
{
|
||||
name: filename,
|
||||
status: "completed",
|
||||
steps: [
|
||||
...uploads,
|
||||
...downloads,
|
||||
"Cache npm package downloads",
|
||||
].map((name) => ({
|
||||
name,
|
||||
started_at: "2026-10-13T00:00:00Z",
|
||||
completed_at: "2026-10-13T00:00:01Z",
|
||||
})),
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
await runReporter(fixture);
|
||||
const report = JSON.parse(
|
||||
await readFile(join(fixture.outputDirectory, "report.json"), "utf8"),
|
||||
);
|
||||
expect(report.stepCosts).toMatchObject({
|
||||
artifactUpload: uploads.map((name) => ({
|
||||
name,
|
||||
duration: { seconds: 1 },
|
||||
})),
|
||||
artifactDownload: downloads.map((name) => ({
|
||||
name,
|
||||
duration: { seconds: 1 },
|
||||
})),
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("marks invalid and out-of-order timestamps unknown instead of emitting negative durations", async () => {
|
||||
const fixture = await createFixture([
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user