Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(release): the publish gate installs the tooling it runs

esengine5ef0d943c354
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 0c89cd7a0..678a054c6 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -110,6 +110,11 @@ jobs:
- name: Check render-command boundary (DrawCommands built only by BatchBuilder)
run: node tools/check-draw-command-boundary.mjs
+ # The release path has no pull request to fail on, so a workflow step that
+ # cannot run is found by pushing a tag. Checked here, where every push is.
+ - name: Check workflows (tooling steps install the workspace)
+ run: node tools/check-workflows.mjs
+
# The device build's codegen, without the device build: it needs no compiler
# and takes a second, but nothing outside a release ran it — so a header that
# moved cost a full Dawn build to find out about, twice.
diff --git a/.github/workflows/release-desktop.yml b/.github/workflows/release-desktop.yml
index f50e9cee9..06c97a1de 100644
--- a/.github/workflows/release-desktop.yml
+++ b/.github/workflows/release-desktop.yml
@@ -399,14 +399,15 @@ jobs:
# screen the first time and nothing here noticed. Check the contents against
# the same table the emitter writes from, under release strictness.
- uses: actions/checkout@v7
- - uses: actions/setup-node@v6
- with:
- node-version: 22
+
+ - uses: ./.github/actions/setup
+
- name: Check the templates carry everything
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
- gh release download "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" -p 'estella-native-*.zip' -D templates
+ gh release download "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" \
+ -p 'estella-native-*.zip' -D templates
node build-tools/cli.js verify-template templates/*.zip
- name: Publish
diff --git a/package.json b/package.json
index 7791a4225..1c4de8bfa 100644
--- a/package.json
+++ b/package.json
@@ -17,7 +17,7 @@
"emsdk:setup": "node build-tools/toolchain/setup-emsdk.js",
"asset-meta": "node tools/asset-meta.js",
"migrate-asset-refs": "node tools/migrate-asset-refs.js",
- "verify": "pnpm --filter ./sdk exec tsc --noEmit && node tools/api-surface.mjs --check && node tools/check-cycles.mjs && node tools/check-layers.mjs",
+ "verify": "pnpm --filter ./sdk exec tsc --noEmit && node tools/api-surface.mjs --check && node tools/check-cycles.mjs && node tools/check-layers.mjs && node tools/check-workflows.mjs",
"prepare": "git config core.hooksPath .githooks || true"
},
"dependencies": {
diff --git a/tools/check-workflows.mjs b/tools/check-workflows.mjs
new file mode 100644
index 000000000..17444f459
--- /dev/null
+++ b/tools/check-workflows.mjs
@@ -0,0 +1,137 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file check-workflows.mjs — a job that runs the repo's tooling installed it first.
+ *
+ * `node build-tools/cli.js` and `pnpm` are not standalone binaries: they resolve
+ * out of the workspace's own `node_modules`. A job that reaches for them without
+ * `./.github/actions/setup` does not misbehave subtly — it dies on
+ * "Cannot find package 'commander'", and only once a tag is pushed, because the
+ * release path has no pull-request run to fail on first.
+ *
+ * That has now happened twice. `publish-templates` wrote the template index that
+ * way, and the fix left a comment saying so; the v0.37.0 publish gate then hand
+ * -rolled `actions/setup-node` (which installs nothing) two hundred lines below
+ * that comment and stranded a complete, correct release as a draft. A comment
+ * cannot fail a build. This can.
+ *
+ * The rule is deliberately narrow, and holds without exception: if a step runs
+ * workspace tooling, the job used the composite setup action, before that step,
+ * with its install. Everything else about a workflow is left alone.
+ */
+import { readdirSync, readFileSync } from 'node:fs';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+
+const WORKFLOWS = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '.github', 'workflows');
+const SETUP = './.github/actions/setup';
+
+// Commands that resolve out of the workspace's node_modules. `npm` is absent on
+// purpose: docs/ installs its own tree with it and owes this repo's nothing.
+const NEEDS_INSTALL = [
+ /\bnode\s+build-tools\//,
+ /\bnode\s+tools\//,
+ /\bpnpm\b/,
+ /\bnpx\b/,
+];
+
+/**
+ * The `run:` scripts of a workflow, as {line, text} where `line` is that of the
+ * script's FIRST line — the `run:` itself when inline, the line below it for a
+ * block scalar. Block scalars are joined so a command is matched wherever it
+ * sits in one, and comments never are.
+ */
+function runScripts(lines) {
+ const out = [];
+ for (let i = 0; i < lines.length; i++) {
+ const m = /^(\s*)(?:-\s+)?run:\s*(.*)$/.exec(lines[i]);
+ if (!m) continue;
+ const indent = m[1].length + (/^\s*-\s+/.test(lines[i]) ? 2 : 0);
+ const rest = m[2].trim();
+ if (rest && !/^[|>][-+]?\d*$/.test(rest)) {
+ out.push({ line: i + 1, text: rest });
+ continue;
+ }
+ const body = [];
+ let j = i + 1;
+ for (; j < lines.length; j++) {
+ if (lines[j].trim() === '') { body.push(''); continue; }
+ const lead = /^\s*/.exec(lines[j])[0].length;
+ if (lead <= indent) break;
+ body.push(lines[j]);
+ }
+ out.push({ line: i + 2, text: body.join('\n') });
+ i = j - 1;
+ }
+ return out;
+}
+
+/** Jobs of a workflow file, as {id, line, lines} — `jobs:` mapping, one level in. */
+function jobs(lines) {
+ const start = lines.findIndex((l) => /^jobs:\s*$/.test(l));
+ if (start < 0) return [];
+ const found = [];
+ for (let i = start + 1; i < lines.length; i++) {
+ const m = /^ {2}([A-Za-z0-9_-]+):\s*$/.exec(lines[i]);
+ if (m) found.push({ id: m[1], line: i + 1, at: i });
+ }
+ return found.map((job, k) => ({
+ ...job,
+ lines: lines.slice(job.at, k + 1 < found.length ? found[k + 1].at : lines.length),
+ }));
+}
+
+/** Line index within a job at which the setup action has run, or -1. */
+function setupAt(jobLines) {
+ for (let i = 0; i < jobLines.length; i++) {
+ if (!new RegExp(`uses:\\s*${SETUP.replace(/[.\\/]/g, '\\$&')}\\s*$`).test(jobLines[i])) continue;
+ // `install: 'false'` sets the toolchain up without a node_modules.
+ const withBlock = jobLines.slice(i + 1, i + 8).join('\n');
+ if (/^\s*install:\s*['"]?false['"]?\s*$/m.test(withBlock)) continue;
+ return i;
+ }
+ return -1;
+}
+
+const violations = [];
+
+for (const file of readdirSync(WORKFLOWS).filter((f) => /\.ya?ml$/.test(f))) {
+ const lines = readFileSync(path.join(WORKFLOWS, file), 'utf8').split('\n');
+ const found = jobs(lines);
+ // A workflow with no jobs is not a workflow — it means the scan above stopped
+ // understanding the file, and a checker that reads nothing passes everything.
+ if (found.length === 0) {
+ console.error(`✗ .github/workflows/${file}: no jobs found — this check cannot read it`);
+ process.exit(1);
+ }
+ for (const job of found) {
+ const installed = setupAt(job.lines);
+ for (const script of runScripts(job.lines)) {
+ const cmd = NEEDS_INSTALL.find((re) => re.test(script.text));
+ if (!cmd) continue;
+ if (installed >= 0 && installed < script.line - 1) continue;
+ const body = script.text.split('\n');
+ const offset = body.findIndex((l) => cmd.test(l));
+ violations.push({
+ file,
+ line: job.line + script.line - 1 + Math.max(offset, 0),
+ job: job.id,
+ what: (body[offset] ?? script.text).trim(),
+ why: installed < 0 ? `job "${job.id}" never runs ${SETUP}` : `${SETUP} runs after this step`,
+ });
+ }
+ }
+}
+
+if (violations.length > 0) {
+ console.error(`\n✗ ${violations.length} workflow step(s) run workspace tooling with no install:\n`);
+ for (const v of violations) {
+ console.error(` ${path.join('.github/workflows', v.file)}:${v.line} ${v.what}`);
+ console.error(` ${v.why}\n`);
+ }
+ console.error(`Add \`- uses: ${SETUP}\` to the job before the step. It is where the`);
+ console.error('toolchain versions live, and it installs the workspace frozen.\n');
+ process.exit(1);
+}
+
+console.log('✓ every workflow step that runs workspace tooling installs it first');