Skip to content

Commit feed213

Browse files
authored
Merge pull request #3 from interscript/feat/code-only-worker-maps-artifact
deploy: fetch pinned map artifact into Workers Assets
2 parents ddada94 + 8a27e32 commit feed213

7 files changed

Lines changed: 77 additions & 13 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ jobs:
1010
if: github.ref == 'refs/heads/main'
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v4
14-
- uses: actions/setup-node@v4
13+
- uses: actions/checkout@v7
14+
- uses: actions/setup-node@v7
1515
with: { node-version: "22" }
1616
- run: npm install
1717
# Staging only: the workers.dev preview URL, never the production
1818
# route. Production flips exclusively via a v* tag.
19-
- run: npx wrangler deploy --config wrangler.staging.jsonc
19+
- run: npm run deploy:staging
2020
env:
2121
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
2222
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
@@ -26,11 +26,11 @@ jobs:
2626
runs-on: ubuntu-latest
2727
environment: production
2828
steps:
29-
- uses: actions/checkout@v4
30-
- uses: actions/setup-node@v4
29+
- uses: actions/checkout@v7
30+
- uses: actions/setup-node@v7
3131
with: { node-version: "22" }
3232
- run: npm install
33-
- run: npx wrangler deploy
33+
- run: npm run deploy
3434
env:
3535
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
3636
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules/
22
.wrangler/
3+
maps/
4+
.tmp-interscript-maps-ir-*

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
"private": true,
44
"type": "module",
55
"scripts": {
6-
"deploy": "wrangler deploy",
7-
"dev": "wrangler dev"
6+
"deploy": "npm run fetch:maps && wrangler deploy",
7+
"dev": "wrangler dev",
8+
"fetch:maps": "node scripts/fetch-maps-artifact.mjs 2.5.0 maps",
9+
"deploy:staging": "npm run fetch:maps && wrangler deploy --config wrangler.staging.jsonc"
810
},
911
"dependencies": {
10-
"@interscript/api-worker": "git+https://github.com/interscript/api.git#21697f8"
12+
"@interscript/api-worker": "^1.0.0"
1113
},
1214
"devDependencies": {
1315
"wrangler": "^4.0.0"
1416
}
15-
}
17+
}

scripts/fetch-maps-artifact.mjs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env node
2+
import { createHash } from "node:crypto";
3+
import { createWriteStream, mkdirSync, rmSync } from "node:fs";
4+
import { readFile, writeFile } from "node:fs/promises";
5+
import { resolve } from "node:path";
6+
import { pipeline } from "node:stream/promises";
7+
import { spawnSync } from "node:child_process";
8+
9+
const version = process.argv[2] ?? process.env.INTERSCRIPT_MAPS_VERSION;
10+
const outDir = resolve(
11+
process.argv[3] ?? process.env.INTERSCRIPT_MAPS_DIR ?? "maps",
12+
);
13+
if (!version) {
14+
console.error("usage: fetch-maps-artifact.mjs <version> [out-dir]");
15+
process.exit(2);
16+
}
17+
18+
const base = `https://github.com/interscript/maps/releases/download/v${version}`;
19+
const tarball = `interscript-maps-ir-${version}.tar.gz`;
20+
const tmp = resolve(`.tmp-${tarball}`);
21+
const checksumFile = `${tmp}.sha256`;
22+
23+
async function download(url, path) {
24+
const res = await fetch(url);
25+
if (!res.ok || !res.body) throw new Error(`${url}: HTTP ${res.status}`);
26+
await pipeline(res.body, createWriteStream(path));
27+
}
28+
29+
await download(`${base}/${tarball}`, tmp);
30+
await download(`${base}/${tarball}.sha256`, checksumFile);
31+
32+
const expected = (await readFile(checksumFile, "utf8")).trim().split(/\s+/)[0];
33+
const actual = createHash("sha256")
34+
.update(await readFile(tmp))
35+
.digest("hex");
36+
if (actual !== expected) {
37+
throw new Error(
38+
`${tarball}: sha256 mismatch; expected ${expected}, got ${actual}`,
39+
);
40+
}
41+
42+
rmSync(outDir, { recursive: true, force: true });
43+
mkdirSync(outDir, { recursive: true });
44+
const result = spawnSync("tar", ["-xzf", tmp, "-C", outDir], {
45+
stdio: "inherit",
46+
});
47+
if (result.status !== 0) process.exit(result.status ?? 1);
48+
49+
const manifest = JSON.parse(
50+
await readFile(resolve(outDir, "manifest.json"), "utf8"),
51+
);
52+
if (manifest.schema !== "interscript.maps.ir.v1")
53+
throw new Error(`unexpected artifact schema ${manifest.schema}`);
54+
if (manifest.count !== 289)
55+
throw new Error(`expected 289 maps, got ${manifest.count}`);
56+
57+
await writeFile(resolve(outDir, ".artifact-version"), `${version}\n`);
58+
console.log(
59+
`fetched ${manifest.count} compiled maps (${version}) into ${outDir}`,
60+
);

wrangler.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// (first call warms ~seconds; cached afterward) — set in the dashboard
1818
// or via "limits": { "cpu_ms": 30000 } if your plan supports it.
1919
"assets": {
20-
"directory": "./node_modules/@interscript/api-worker/maps",
20+
"directory": "./maps/maps",
2121
"binding": "ASSETS"
2222
},
2323
"vars": {

wrangler.staging.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// Staging never claims production routes: workers.dev preview URL only.
88
"workers_dev": true,
99
"assets": {
10-
"directory": "./node_modules/@interscript/api-worker/maps",
10+
"directory": "./maps/maps",
1111
"binding": "ASSETS"
1212
},
1313
"vars": {

0 commit comments

Comments
 (0)