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
24 changes: 24 additions & 0 deletions packages/ui/tests/dist-fresh.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { describe, expect, it } from "bun:test";
import { distStale } from "../../../scripts/dist-fresh";

// The land gate decides whether to rebuild `dist` before it tests the site. A dist built before the
// rebase holds old code even when the PR's own diff touches no package file (#591).
const none = { exists: true, changedAfter: false };

describe("distStale", () => {
it("is stale when it does not exist", () => {
expect(distStale({ land: false, exists: false, changedAfter: false })).toBe(true);
});

it("a dev run keeps a dist newer than every changed file", () => {
expect(distStale({ land: false, ...none })).toBe(false);
});

it("a dev run rebuilds when a changed file is newer than the dist", () => {
expect(distStale({ land: false, ...none, changedAfter: true })).toBe(true);
});

it("the land gate always rebuilds: the rebase brings in sources the diff does not list", () => {
expect(distStale({ land: true, ...none })).toBe(true);
});
});
9 changes: 9 additions & 0 deletions scripts/dist-fresh.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Whether a build output (`packages/ui/dist`, `site/dist`) has to be rebuilt before the site is tested.
* A dev run trusts file times: the output is stale when it is missing or a changed file is newer.
* The land gate never does: it runs right after a rebase, which brings in sources that are not in the
* PR's diff (so no changed file is "newer"), while the output may predate the rebase by hours (#591).
*/
export function distStale(o: { land: boolean; exists: boolean; changedAfter: boolean }): boolean {
return o.land || !o.exists || o.changedAfter;
}
14 changes: 11 additions & 3 deletions scripts/test-changed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import { spawnSync } from "node:child_process";
import { existsSync, readFileSync, statSync } from "node:fs";
import { join } from "node:path";
import { distStale } from "./dist-fresh.ts";
import { lockReachesRuntime, ROOT, select } from "./route-impact.ts";
import { affected, buildGraph, isSharedComponent, landBudget } from "./test-graph.ts";

Expand Down Expand Up @@ -203,11 +204,18 @@ if (siteRun) {
const siteDist = mtime(join(ROOT, "site/dist/index.html"));
const newer = (re: RegExp, than: number) =>
changed.some((f) => re.test(f) && mtime(join(ROOT, f)) > than);
const pkgStale = !pkgDist || newer(/^packages\/ui\/(src|scripts|package\.json)/, pkgDist);
const pkgStale = distStale({
land,
exists: pkgDist > 0,
changedAfter: newer(/^packages\/ui\/(src|scripts|package\.json)/, pkgDist),
});
const siteStale =
!siteDist ||
pkgStale ||
newer(/^site\/(src|public|astro\.config\.mjs|package\.json)/, siteDist);
distStale({
land,
exists: siteDist > 0,
changedAfter: newer(/^site\/(src|public|astro\.config\.mjs|package\.json)/, siteDist),
});
// A build is ~75 s (package 17 s + site 58 s), more than the whole 60 s dev budget: only the land gate
// builds. A dev run uses `site/dist` when it is fresh, and says so when it cannot.
if ((pkgStale || siteStale) && !land) {
Expand Down