Support verified engine-only BGS publication

This commit is contained in:
coyotte508 2026-11-14 01:26:57 +00:00
commit e3ff913935
2 changed files with 76 additions and 1 deletions

View file

@ -62,6 +62,11 @@ Further playtesting remains welcome. The Festival marker interpretation is noted
`pnpm publish:bgs` builds the bundles, packages only the self-contained engine and its manifest, checks complete 1–5-player games from the extracted package, and uploads the engine/viewer to BGS. The script reads the admin token from `~/.bgs` without logging it, preserves the existing game/request identity, requires an already public version, and verifies the public/listed flags and CDN bytes. Metadata snapshots and package artifacts stay in ignored `.local/release/`. `pnpm publish:bgs` builds the bundles, packages only the self-contained engine and its manifest, checks complete 1–5-player games from the extracted package, and uploads the engine/viewer to BGS. The script reads the admin token from `~/.bgs` without logging it, preserves the existing game/request identity, requires an already public version, and verifies the public/listed flags and CDN bytes. Metadata snapshots and package artifacts stay in ignored `.local/release/`.
For an engine-only update that must preserve the deployed viewer and live metadata,
run `BGS_ENGINE_ONLY=1 pnpm publish:bgs`. This still builds and tests the extracted
engine tarball, but uploads only the engine and verifies its installer-generated
achievement manifest, public/listed status, and unchanged viewer/setup metadata.
The hosted bundle has no local preview controls or runtime asset dependencies. Global BGS locale and color-blind preferences are handled by the viewer; expansion switches remain internal. Four playable tutorial chapters are registered. The hosted bundle has no local preview controls or runtime asset dependencies. Global BGS locale and color-blind preferences are handled by the viewer; expansion switches remain internal. Four playable tutorial chapters are registered.
Enable “Show everyone’s VP” at game creation to reveal accumulated VP tokens to all players and spectators. It is off by default; uncompleted Achievement cards remain private. For a separate local preview with visible VP, add `&showVP=true` to the URL. Enable “Show everyone’s VP” at game creation to reveal accumulated VP tokens to all players and spectators. It is off by default; uncompleted Achievement cards remain private. For a separate local preview with visible VP, add `&showVP=true` to the URL.

View file

@ -3,11 +3,24 @@ import { readFile, writeFile, mkdir } from "node:fs/promises";
import { homedir } from "node:os"; import { homedir } from "node:os";
import { createHash } from "node:crypto"; import { createHash } from "node:crypto";
import assert from "node:assert/strict"; import assert from "node:assert/strict";
import { isDeepStrictEqual } from "node:util";
import { publishCmsRules } from "./publish-cms.mjs"; import { publishCmsRules } from "./publish-cms.mjs";
import { releaseMetadata } from "./release-metadata.mjs"; import { releaseMetadata } from "./release-metadata.mjs";
import { supportedLocales } from "../viewer/i18n.js"; import { supportedLocales } from "../viewer/i18n.js";
import { packageEngine } from "./package-engine.mjs"; import { packageEngine } from "./package-engine.mjs";
if (process.env.BGS_ENGINE_ONLY && process.env.BGS_ENGINE_ONLY !== "1")
throw Error("BGS_ENGINE_ONLY must be 1 or unset");
const engineOnly = process.env.BGS_ENGINE_ONLY === "1";
const expectedManifest = engineOnly
? (await import("../dist/engine.js")).achievementDefinitions()
: null;
if (engineOnly) {
const { achievementManifestSchema } = await import(
"@boardgamers/protocol/achievements"
);
achievementManifestSchema.parse(expectedManifest);
}
const defaults = JSON.parse(await readFile("bgs/game.json", "utf8")); const defaults = JSON.parse(await readFile("bgs/game.json", "utf8"));
assert.equal(defaults.public, true); assert.equal(defaults.public, true);
const { tarball, version } = await packageEngine(); const { tarball, version } = await packageEngine();
@ -44,13 +57,15 @@ const versions = await api("/versions");
const existing = versions.some((v) => v.version === 1) ? await api("/1") : null; const existing = versions.some((v) => v.version === 1) ? await api("/1") : null;
if (!existing?.public) if (!existing?.public)
throw Error("The release publisher requires an already public version."); throw Error("The release publisher requires an already public version.");
const existingMeta = await api("/meta");
if (engineOnly) assert.equal(existing.engine.entryPoint, "dist/engine.js");
await mkdir(".local/release", { recursive: true }); await mkdir(".local/release", { recursive: true });
await writeFile( await writeFile(
`.local/release/before-${Date.now()}.json`, `.local/release/before-${Date.now()}.json`,
JSON.stringify( JSON.stringify(
{ {
version: existing, version: existing,
metadata: await api("/meta"), metadata: existingMeta,
}, },
null, null,
2, 2,
@ -58,6 +73,61 @@ await writeFile(
); );
if (!existing) await api("/1", "PUT", defaults); if (!existing) await api("/1", "PUT", defaults);
const engine = await api("/1/engine", "POST", await readFile(tarball), true); const engine = await api("/1/engine", "POST", await readFile(tarball), true);
// Badge-only releases must not overwrite independently managed live metadata or
// replace a viewer that does not need the engine change.
if (engineOnly) {
const expected = expectedManifest;
let published;
for (let attempt = 0; attempt < 60; attempt++) {
published = await api("/1");
if (
isDeepStrictEqual(published.engine?.package, engine.engine.package) &&
isDeepStrictEqual(published.achievementManifest, expected)
)
break;
await new Promise((resolve) => setTimeout(resolve, 2000));
}
assert.equal(published.engine.package.version, version);
assert.deepEqual(published.engine.package, engine.engine.package);
const downloaded = await fetch(published.engine.package.url);
assert.ok(downloaded.ok);
assert.deepEqual(
Buffer.from(await downloaded.arrayBuffer()),
await readFile(tarball),
);
assert.deepEqual(published.achievementManifest, expected);
assert.equal(published.public, true);
assert.deepEqual(published.viewer, existing.viewer);
// Engine upload owns only engine metadata and the installer-generated manifest.
for (const key of Object.keys(defaults)) {
if (key !== "engine") assert.deepEqual(published[key], existing[key], key);
}
const meta = await api("/meta");
assert.ok(!meta.unlisted);
for (const key of new Set([
...Object.keys(existingMeta),
...Object.keys(meta),
])) {
if (!["updatedAt", "bots", "replay"].includes(key))
assert.deepEqual(meta[key], existingMeta[key], `metadata.${key}`);
}
await writeFile(
".local/release/published.json",
JSON.stringify(published, null, 2),
);
console.log(
JSON.stringify({
engineOnly: true,
public: published.public,
listed: !meta.unlisted,
engine: published.engine.package,
achievementRevision: expected.revision,
achievementCount: expected.achievements.length,
viewer: published.viewer.url,
}),
);
process.exit(0);
}
const bytes = await readFile("dist/viewer.js"); const bytes = await readFile("dist/viewer.js");
const hash = (buffer) => createHash("sha256").update(buffer).digest("hex"); const hash = (buffer) => createHash("sha256").update(buffer).digest("hex");
const uploaded = await api( const uploaded = await api(