Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,28 @@ async function runInCI(
if (siteApiEndpoint && repo) {
const comparisonBranch =
config.comparisonBranch ?? process.env.GITHUB_BASE_REF ?? branch;
previousRun = await fetchPreviousRun(
const result = await fetchPreviousRun(
siteApiEndpoint,
repo,
comparisonBranch,
runId ?? undefined,
);
reportContext.comparisonBranch = comparisonBranch;
if (!previousRun) {
if (result.kind === "found") {
previousRun = result.run;
} else if (result.kind === "not-found") {
log.info(
"main",
`No baseline found on branch "${comparisonBranch}". Comparison will be skipped. ` +
`To establish a baseline, run the analyzer on pushes to "${comparisonBranch}" ` +
`(add "push: branches: [${comparisonBranch}]" to your workflow trigger).`,
);
} else {
log.warn(
"main",
`Failed to fetch baseline for branch "${comparisonBranch}" (${result.reason}). ` +
`Comparison will be skipped. This is likely a transient Site API issue — re-run the check to retry.`,
);
}
}
if (previousRun) {
Expand Down
15 changes: 10 additions & 5 deletions src/reporters/site-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,17 @@ export async function postToSiteApi(
}
}

export type PreviousRunResult =
| { kind: "found"; run: PreviousRun }
| { kind: "not-found" }
| { kind: "error"; reason: string };

export async function fetchPreviousRun(
endpoint: string,
repo: string,
branch?: string,
excludeId?: string,
): Promise<PreviousRun | null> {
): Promise<PreviousRunResult> {
const params = new URLSearchParams({ repo });
if (branch) params.set("branch", branch);
if (excludeId) params.set("excludeId", excludeId);
Expand All @@ -294,15 +299,15 @@ export async function fetchPreviousRun(
});
if (response.status === 404) {
console.log("No previous run found");
return null;
return { kind: "not-found" };
}
if (!response.ok) {
console.warn(`Failed to fetch previous run: ${response.status}`);
return null;
return { kind: "error", reason: `HTTP ${response.status}` };
}
return (await response.json()) as PreviousRun;
return { kind: "found", run: (await response.json()) as PreviousRun };
} catch (err) {
console.warn(`Failed to fetch previous run: ${err}`);
return null;
return { kind: "error", reason: `${err}` };
}
}
Loading