Skip to content

Commit af1a784

Browse files
committed
worker: key the cached document by build id so every deploy computes afresh
1 parent 07777af commit af1a784

7 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎schemas/compatibility.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@
140140
"items": {
141141
"$ref": "#/definitions/advisory"
142142
}
143+
},
144+
"build": {
145+
"type": "string",
146+
"description": "The deployment (commit) that computed this document."
143147
}
144148
},
145149
"definitions": {

‎shared/compute.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export function collectOverrides(entries: OverrideEntry[]): Overrides {
4646

4747
export function buildDocument(input: {
4848
schema?: string;
49+
build?: string;
4950
generatedAt: string;
5051
toolchains: Record<ToolchainKey, ToolchainVersion[]>;
5152
packages: Array<{ spec: TrackedPackageSpec; document: PackageDocument }>;
@@ -86,6 +87,7 @@ export function buildDocument(input: {
8687
return {
8788
...(input.schema ? { $schema: input.schema } : {}),
8889
schemaVersion: 1,
90+
...(input.build ? { build: input.build } : {}),
8991
generatedAt: input.generatedAt,
9092
toolchains: input.toolchains,
9193
packages,

‎shared/types.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ export interface Advisory {
7575
export interface CompatibilityDocument {
7676
$schema?: string;
7777
schemaVersion: 1;
78+
/** The deployment that computed this document. */
79+
build?: string;
7880
generatedAt: string;
7981
toolchains: Record<ToolchainKey, ToolchainVersion[]>;
8082
packages: Record<string, PackageCompatibility>;

‎tsconfig.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
"esModuleInterop": true,
1313
"isolatedModules": true
1414
},
15-
"include": ["worker", "shared", "test", "worker-configuration.d.ts"]
15+
"include": ["worker", "shared", "test", "worker-configuration.d.ts", "worker/build.d.ts"]
1616
}

‎vite.config.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import { defineConfig } from "vite";
55

66
// One dev server for everything: Vite serves the Vue app and the Cloudflare
77
// plugin runs the Worker (API, KV, cron) in workerd alongside it.
8+
// Baked into the Worker so each deployment computes a fresh document instead
9+
// of serving what the previous build cached in KV.
10+
const buildId = (process.env.GITHUB_SHA ?? "").slice(0, 7) || `local-${Date.now().toString(36)}`;
11+
812
export default defineConfig({
913
plugins: [vue(), tailwindcss(), cloudflare()],
14+
define: { __BUILD_ID__: JSON.stringify(buildId) },
1015
server: { port: 8787 },
1116
});

‎worker/build.d.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/** Injected by vite.config.ts: the commit being built, or a local timestamp. */
2+
declare const __BUILD_ID__: string;

‎worker/index.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ const SCHEMAS: Record<string, unknown> = {
2929
"verified.json": verifiedSchema,
3030
};
3131

32-
const KV_KEY = "document:v1";
32+
// Keyed by build so a deployment never serves a document computed by an older build.
33+
const KV_KEY = `document:v1:${__BUILD_ID__}`;
3334
/** Served copies older than this are refreshed in the background. */
3435
const STALE_AFTER_MS = 60 * 60 * 1000;
3536
const KV_TTL_SECONDS = 7 * 24 * 60 * 60;
@@ -120,6 +121,7 @@ async function refresh(env: Env): Promise<CompatibilityDocument> {
120121

121122
const document = buildDocument({
122123
schema: "https://compatibility.nativescript.org/v1/schemas/compatibility.json",
124+
build: __BUILD_ID__,
123125
generatedAt: new Date().toISOString(),
124126
toolchains,
125127
packages,

0 commit comments

Comments
 (0)