mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-09-30 23:27:55 -05:00
Error changelog script if wrong dev server
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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(),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -20,7 +20,10 @@ export default function ChangelogImagePage() {
|
||||
only show the entries added after that commit.
|
||||
</div>
|
||||
</div>
|
||||
<div data-changelog-entries={JSON.stringify(data.entries)}>
|
||||
<div
|
||||
data-changelog-entries={JSON.stringify(data.entries)}
|
||||
data-changelog-head={data.headSha}
|
||||
>
|
||||
<ChangelogGraphic date={new Date()} entries={data.entries} />
|
||||
</div>
|
||||
</Main>
|
||||
|
||||
@@ -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<ChangelogEntry[]> {
|
||||
const json = await page
|
||||
.locator("[data-changelog-entries]")
|
||||
|
||||
Reference in New Issue
Block a user