diff --git a/app/features/changelog/core/entries.server.ts b/app/features/changelog/core/entries.server.ts index 07563d868..e15b8ad52 100644 --- a/app/features/changelog/core/entries.server.ts +++ b/app/features/changelog/core/entries.server.ts @@ -55,6 +55,16 @@ export function allEntries(): ChangelogGraphicEntry[] { .map(parseEntryFile); } +/** + * Sha of the commit the entries are read from, letting a caller check it is + * talking to a server running the same checkout it is. + */ +export function headSha(): string { + return execFileSync("git", ["rev-parse", "HEAD"], { + encoding: "utf8", + }).trim(); +} + function parseEntryFile(fileName: string): ChangelogGraphicEntry { const rawMarkdown = fs.readFileSync( path.join(RESOLVED_CHANGELOG_DIR, fileName), diff --git a/app/features/changelog/loaders/changelog-image.server.ts b/app/features/changelog/loaders/changelog-image.server.ts index 5e7627087..95e14956b 100644 --- a/app/features/changelog/loaders/changelog-image.server.ts +++ b/app/features/changelog/loaders/changelog-image.server.ts @@ -6,6 +6,7 @@ export const loader = ({ request }: LoaderFunctionArgs) => { const { since } = changelogSearchParams.parse(request); return { + headSha: Entries.headSha(), entries: since ? Entries.entriesSince(since) : Entries.allEntries(), }; }; diff --git a/app/features/changelog/routes/changelog-image.tsx b/app/features/changelog/routes/changelog-image.tsx index 7ef510fe3..e62bb36f0 100644 --- a/app/features/changelog/routes/changelog-image.tsx +++ b/app/features/changelog/routes/changelog-image.tsx @@ -20,7 +20,10 @@ export default function ChangelogImagePage() { only show the entries added after that commit. -
+
diff --git a/scripts/generate-changelog-image.ts b/scripts/generate-changelog-image.ts index 3736c79ef..db828f377 100644 --- a/scripts/generate-changelog-image.ts +++ b/scripts/generate-changelog-image.ts @@ -66,6 +66,8 @@ async function main() { throw new Error(`No changelog canvas found at ${CHANGELOG_IMAGE_PAGE_URL}`); } + await assertSameCheckout(page); + const entries = await parseEntries(page); if (entries.length === 0) { throw new Error( @@ -118,6 +120,27 @@ async function main() { } } +/** + * The screenshotted page is whatever dev server holds the port, which can be another + * checkout of the repo whose entries are not the ones being shipped. + */ +async function assertSameCheckout(page: Page) { + const marker = page.locator("[data-changelog-head]"); + const pageHead = + (await marker.count()) > 0 + ? await marker.getAttribute("data-changelog-head") + : null; + const localHead = ( + await execFileAsync("git", ["rev-parse", "HEAD"]) + ).stdout.trim(); + + if (pageHead !== localHead) { + throw new Error( + `The server at ${CHANGELOG_IMAGE_PAGE_URL} is a different checkout of the repo: its HEAD is ${pageHead ?? "unknown"}, this one is at ${localHead}. Start a dev server from this folder and run again.`, + ); + } +} + async function parseEntries(page: Page): Promise { const json = await page .locator("[data-changelog-entries]")