-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcontext.ts
More file actions
27 lines (23 loc) · 911 Bytes
/
context.ts
File metadata and controls
27 lines (23 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**
* Read / write the versioned bootstrap context JSON used between CI stages.
*/
import { readFileSync, writeFileSync, mkdirSync } from "fs";
import { dirname, join } from "path";
import type { Context } from "../scenarios/types";
const ARTIFACTS_DIR = join(process.cwd(), "ci-artifacts");
const CONTEXT_FILE = join(ARTIFACTS_DIR, "bootstrap-context.json");
const CONTEXT_VERSION = "1";
export function writeContext(ctx: Context): void {
mkdirSync(dirname(CONTEXT_FILE), { recursive: true });
writeFileSync(CONTEXT_FILE, JSON.stringify({ ...ctx, version: CONTEXT_VERSION }, null, 2) + "\n");
}
export function readContext(): Context {
const raw = readFileSync(CONTEXT_FILE, "utf8");
const ctx = JSON.parse(raw) as Context;
if (ctx.version !== CONTEXT_VERSION) {
throw new Error(
`Context version mismatch: expected ${CONTEXT_VERSION}, got ${ctx.version}`,
);
}
return ctx;
}