From 1d210c35b08649231a3b73b8ff3f31e4eeb0d14e Mon Sep 17 00:00:00 2001 From: Klaus Kneupner Date: Thu, 12 Nov 2026 07:21:59 +0100 Subject: [PATCH 1/9] fix(attributes): keep backslashes that escape nothing A value stored before list elements were escaped may hold a bare `\`, such as `[C:\temp]`. The decoder dropped it; now only `\,` and `\\` lose their backslash, so old values read unchanged and new ones still round-trip. --- Sources/VGraph/Domain/Attributes/Attribute.swift | 4 ++++ Tests/VGraphTests/AttributeTests.swift | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/Sources/VGraph/Domain/Attributes/Attribute.swift b/Sources/VGraph/Domain/Attributes/Attribute.swift index c6c05fd..4953512 100644 --- a/Sources/VGraph/Domain/Attributes/Attribute.swift +++ b/Sources/VGraph/Domain/Attributes/Attribute.swift @@ -131,6 +131,9 @@ private func splitElements(_ body: String) -> [String] { var escaped = false for ch in body { if escaped { + // Values stored before escaping existed may hold a bare `\`; only the + // two characters the encoder escapes lose theirs. + if ch != "\\" && ch != "," { current.append("\\") } current.append(ch) escaped = false } else if ch == "\\" { @@ -142,6 +145,7 @@ private func splitElements(_ body: String) -> [String] { current.append(ch) } } + if escaped { current.append("\\") } elements.append(current) return elements.map { $0.trimmingCharacters(in: " \t\n\r") }.filter { !$0.isEmpty } } diff --git a/Tests/VGraphTests/AttributeTests.swift b/Tests/VGraphTests/AttributeTests.swift index b544b6a..907bb8b 100644 --- a/Tests/VGraphTests/AttributeTests.swift +++ b/Tests/VGraphTests/AttributeTests.swift @@ -192,6 +192,11 @@ struct AttributeTests { #expect(try Attributes.Node.wrappedText.value(fromString: stored.stringValue) == lines) } + @Test("A backslash that escapes nothing is read as written, as values stored before escaping were") + func strayBackslashesSurvive() throws(VError) { + #expect(try [String].fromString("[C:\\temp,x\\]") == ["C:\\temp", "x\\"]) + } + @Test("A problem message that contains a comma stays one message") func messagesKeepTheirCommas() throws(VError) { let problems = TypedAttributeDefinition<[MessageWithSeverity]>( From 72f0f4bc4773e1068e1bd94f9f71a5a985c17e8d Mon Sep 17 00:00:00 2001 From: Klaus Kneupner Date: Thu, 12 Nov 2026 07:22:17 +0100 Subject: [PATCH 2/9] test: wait for the Obsidian settings entries instead of 300 ms The check polls until the tab is indexed and rendered, so a slow render no longer fails it, while a tab without definitions still does. --- .../Tests-Browser/obsidian/smoke.spec.js | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/VGraphWasm/Tests-Browser/obsidian/smoke.spec.js b/VGraphWasm/Tests-Browser/obsidian/smoke.spec.js index 11c795a..089962f 100644 --- a/VGraphWasm/Tests-Browser/obsidian/smoke.spec.js +++ b/VGraphWasm/Tests-Browser/obsidian/smoke.spec.js @@ -183,21 +183,25 @@ test('the same blocks render in the dark theme, in dark colours', async () => { // Obsidian 1.13+ indexes `settingItems` for its settings search and renders the // tab from the same definitions; a tab that only implements display() has neither. test('the settings tab is declared, so settings search can find it', async () => { - const tab = await page.evaluate(async () => { + const entries = ['Syntax guide', 'Notations gallery', 'Sponsor on GitHub']; + await page.evaluate(() => { app.setting.open(); app.setting.openTabById('vithanco'); - await new Promise((r) => setTimeout(r, 300)); + }); + const read = () => page.evaluate(() => { const t = app.setting.pluginTabs.find((p) => p.id === 'vithanco'); const names = (items) => items.flatMap((i) => [i.name, ...names(i.items ?? [])]).filter(Boolean); - const result = { + return { indexed: names(t?.settingItems ?? []), - rendered: [...t.containerEl.querySelectorAll('.setting-item-name')].map((e) => e.textContent), + rendered: [...(t?.containerEl.querySelectorAll('.setting-item-name') ?? [])].map((e) => e.textContent), }; - app.setting.close(); - return result; }); - expect(tab.indexed).toEqual(expect.arrayContaining(['Syntax guide', 'Notations gallery', 'Sponsor on GitHub'])); - expect(tab.rendered).toEqual(expect.arrayContaining(['Syntax guide', 'Notations gallery', 'Sponsor on GitHub'])); + try { + await expect.poll(async () => (await read()).indexed).toEqual(expect.arrayContaining(entries)); + await expect.poll(async () => (await read()).rendered).toEqual(expect.arrayContaining(entries)); + } finally { + await page.evaluate(() => app.setting.close()); + } }); test('no uncaught errors in the window', async () => { From 4f98829f6705b3189f6c45b796696c29c1364ad2 Mon Sep 17 00:00:00 2001 From: Klaus Kneupner Date: Thu, 12 Nov 2026 07:22:17 +0100 Subject: [PATCH 3/9] release: publish only from a committed, pushed VGraph, and name it Both plugins ship the engine, but publish-plugins never checked the VGraph checkout it came from. It now refuses uncommitted changes or a HEAD that is not on origin/main, and both releases name the commit. It also commits the Obsidian plugin's vendor/Package glue with the wasm, since the directory builds that repo alone, and holds main.js to 5 MB. --- justfile | 28 +++++++++++++++----- scripts/publish-plugins.test.sh | 46 +++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 7 deletions(-) diff --git a/justfile b/justfile index 4ecac52..ff83b08 100644 --- a/justfile +++ b/justfile @@ -537,6 +537,18 @@ publish-plugins: _require-maintainer (_require-plugin "obsidian-vithanco") (_req # this the recipe discovers problems halfway through — and since Obsidian is # published first, a late failure leaves one plugin released and the other not. FAIL=0 + # Both plugins ship the engine, so a release must come from a VGraph commit + # that main holds, and say which one. + if [ -n "$(git status --porcelain)" ]; then + echo "Preflight: VGraph has uncommitted changes — the engine would ship from code no commit holds." >&2 + FAIL=1 + fi + git fetch -q origin main 2>/dev/null || true + if ! git merge-base --is-ancestor HEAD origin/main 2>/dev/null; then + echo "Preflight: VGraph $(git rev-parse --short HEAD) is not on origin/main — push and merge it first." >&2 + FAIL=1 + fi + ENGINE="VGraph $(git rev-parse --short=12 HEAD)" for spec in "obsidian-vithanco:main.js" "vscode-vithanco:vithanco-${OBS_V}.vsix"; do DIR=${spec%%:*}; ASSET=${spec#*:} BRANCH=$(git -C "$DIR" branch --show-current) @@ -561,11 +573,11 @@ publish-plugins: _require-maintainer (_require-plugin "obsidian-vithanco") (_req # just website/Package: that is what shipped as a 115 MB main.js in 1.0.9. ./scripts/check-wasm-optimized.sh website/Package/VGraphWasm.wasm \ obsidian-vithanco/VGraphWasm.wasm vscode-vithanco/VGraphWasm.wasm || FAIL=1 - # main.js carries the engine as base64 (~4/3), so this also catches a bundle - # built before the engine was replaced. + # main.js carries the engine gzipped, so this also catches a bundle built + # before the engine was replaced. Obsidian Sync's Standard plan skips files over 5 MB. MAIN_BYTES=$(wc -c < obsidian-vithanco/main.js) - if [ "$MAIN_BYTES" -gt 30000000 ]; then - echo "Preflight: obsidian-vithanco/main.js is $MAIN_BYTES bytes — built from a debug engine. Rebuild it." >&2 + if [ "$MAIN_BYTES" -gt 5000000 ]; then + echo "Preflight: obsidian-vithanco/main.js is $MAIN_BYTES bytes, over 5 MB — a debug engine, or an old bundle. Rebuild it." >&2 FAIL=1 fi if [ "$FAIL" -ne 0 ]; then @@ -579,12 +591,14 @@ publish-plugins: _require-maintainer (_require-plugin "obsidian-vithanco") (_req # Obsidian ( cd obsidian-vithanco # main.js is gitignored in this repo — it ships as a GitHub release asset (below), not a commit. - git add manifest.json package.json versions.json styles.css VGraphWasm.wasm + # vendor/Package is the engine's glue for that wasm: Obsidian's directory + # builds this repo alone, and new wasm with old glue would not run. + git add manifest.json package.json versions.json styles.css VGraphWasm.wasm vendor/Package # The bump may already be committed; then there is nothing to add. git diff --cached --quiet || git commit -m "chore: release $OBS_V" git tag "$OBS_V" git push origin HEAD "$OBS_V" - gh release create "$OBS_V" --title "$OBS_V" --notes "Release $OBS_V" main.js manifest.json styles.css ) + gh release create "$OBS_V" --title "$OBS_V" --notes "Release $OBS_V, engine $ENGINE" main.js manifest.json styles.css ) # VS Code ( cd vscode-vithanco VSIX="vithanco-${VSC_V}.vsix" @@ -596,7 +610,7 @@ publish-plugins: _require-maintainer (_require-plugin "obsidian-vithanco") (_req git diff --cached --quiet || git commit -m "chore: release $VSC_V" git tag "$VSC_V" git push origin HEAD "$VSC_V" - gh release create "$VSC_V" --title "$VSC_V" --notes "Release $VSC_V" "$VSIX" ) + gh release create "$VSC_V" --title "$VSC_V" --notes "Release $VSC_V, engine $ENGINE" "$VSIX" ) echo "" echo "✓ Plugins pushed + tagged + GitHub releases created at v$OBS_V." echo "" diff --git a/scripts/publish-plugins.test.sh b/scripts/publish-plugins.test.sh index 551eb92..21663bb 100755 --- a/scripts/publish-plugins.test.sh +++ b/scripts/publish-plugins.test.sh @@ -43,10 +43,25 @@ given_plugins_at() { # version, in a fresh directory WORK with pushed plugin rep echo 'bundle' > "$WORK/obsidian-vithanco/main.js" echo 'package' > "$WORK/vscode-vithanco/vithanco-$1.vsix" echo '*.vsix' >> "$WORK/vscode-vithanco/.gitignore" + mkdir -p "$WORK/obsidian-vithanco/vendor/Package" + echo 'glue' > "$WORK/obsidian-vithanco/vendor/Package/index.js" for p in obsidian-vithanco vscode-vithanco; do git -C "$WORK/$p" add . && git -C "$WORK/$p" commit -qm "bump merged" git -C "$WORK/$p" push -q origin main done + # WORK stands in for VGraph itself: committed, and pushed to its main. + printf '%s\n' '*.git/' obsidian-vithanco/ vscode-vithanco/ out gh.log > "$WORK/.gitignore" + git init -q --bare -b main "$WORK/vgraph.git" + git -C "$WORK" init -q -b main + git -C "$WORK" remote add origin "$WORK/vgraph.git" + git -C "$WORK" add . && git -C "$WORK" commit -qm "engine" + git -C "$WORK" push -q origin main +} +nothing_released() { # why + for p in obsidian-vithanco vscode-vithanco; do + git -C "$WORK/$p.git" rev-parse -q --verify refs/tags/1.2.3 >/dev/null && fail "$1: $p was tagged" + done + grep -q '^release create' "$GH_LOG" && fail "$1: created a release" } publish() { just --justfile "$REPO_ROOT/justfile" --working-directory "$WORK" publish-plugins >"$WORK/out" 2>&1; } @@ -76,5 +91,36 @@ for p in obsidian-vithanco vscode-vithanco; do done grep -q '^release create' "$GH_LOG" && fail "created a release" +# Given VGraph with uncommitted changes, when publishing, then nothing is +# released: the engine would ship from code that no commit holds. +given_plugins_at 1.2.3 +echo 'change' > "$WORK/engine.swift" +publish && fail "published from an uncommitted VGraph" +grep -q 'uncommitted' "$WORK/out" || fail "does not say VGraph is uncommitted: $(cat "$WORK/out")" +nothing_released "uncommitted VGraph" + +# Given a VGraph commit that is not on origin/main, when publishing, then nothing is released. +given_plugins_at 1.2.3 +git -C "$WORK" commit -qm "local only" --allow-empty +publish && fail "published from a VGraph commit that is not on origin/main" +grep -q 'origin/main' "$WORK/out" || fail "does not name origin/main: $(cat "$WORK/out")" +nothing_released "unpushed VGraph" + +# Given a clean, pushed VGraph, when publishing, then both releases name the engine's commit. +given_plugins_at 1.2.3 +ENGINE=$(git -C "$WORK" rev-parse --short=12 HEAD) +publish || fail "publishing from a clean VGraph failed: $(cat "$WORK/out")" +[ "$(grep '^release create' "$GH_LOG" | grep -c "$ENGINE")" = 2 ] \ + || fail "the releases do not name VGraph $ENGINE: $(cat "$GH_LOG")" + +# Given a rebuild that refreshed the Obsidian plugin's vendored engine glue, when +# publishing, then the glue is committed under the tag next to the wasm: the +# directory builds the repo alone, and new wasm with old glue would not run. +given_plugins_at 1.2.3 +echo 'new glue' > "$WORK/obsidian-vithanco/vendor/Package/index.js" +publish || fail "publishing refreshed glue failed: $(cat "$WORK/out")" +[ "$(git -C "$WORK/obsidian-vithanco" show 1.2.3:vendor/Package/index.js)" = "new glue" ] \ + || fail "the refreshed glue was not committed under the tag" + [ "$FAILED" -eq 0 ] && echo "✓ publish-plugins" exit "$FAILED" From da11da97b405f92a7c00e26030540bfbef92eae9 Mon Sep 17 00:00:00 2001 From: Klaus Kneupner Date: Thu, 12 Nov 2026 07:22:17 +0100 Subject: [PATCH 4/9] release: build the optimized engine in plugins-release Each plugin's release.sh copies website/Package in, so a fresh checkout failed, and a stale or debug copy could ship. --- justfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/justfile b/justfile index ff83b08..01f81de 100644 --- a/justfile +++ b/justfile @@ -443,6 +443,10 @@ plugins-release bump='patch' plugin='': patch|minor|major) ARG="--{{bump}}" ;; *) ARG="{{bump}}" ;; esac + # Each plugin's release.sh copies website/Package in, and fails on a fresh + # checkout without it; a stale or debug copy would ship instead. + ./build-wasm.sh --release --skip-smoke + ./scripts/check-wasm-optimized.sh website/Package/VGraphWasm.wasm ./release-plugins.sh "$ARG" {{plugin}} # Internal: fail with a helpful hint if a plugin repo isn't cloned. From c0ae4d40f0d75ffee95fc4b4e9300f277b597c76 Mon Sep 17 00:00:00 2001 From: Klaus Kneupner Date: Thu, 12 Nov 2026 07:22:17 +0100 Subject: [PATCH 5/9] docs(adr): absorb 0035 into 0036 What still held from 0035, and its rejected alternatives, now live in 0036, which also records the new release rules. --- ...ag-started-from-the-maintainers-machine.md | 36 --------------- ...eleases-stay-on-the-maintainers-machine.md | 46 +++++++++++++++---- 2 files changed, 38 insertions(+), 44 deletions(-) delete mode 100644 docs/adr/0035-a-release-is-a-tag-started-from-the-maintainers-machine.md diff --git a/docs/adr/0035-a-release-is-a-tag-started-from-the-maintainers-machine.md b/docs/adr/0035-a-release-is-a-tag-started-from-the-maintainers-machine.md deleted file mode 100644 index 7838cdf..0000000 --- a/docs/adr/0035-a-release-is-a-tag-started-from-the-maintainers-machine.md +++ /dev/null @@ -1,36 +0,0 @@ -# 35. A release is a tag started from the maintainer's machine - -Date: 2026-11-06 - -## Status - -Superseded by [0036](./0036-releases-stay-on-the-maintainers-machine.md) before -any release used it. - -## Context - -The plugins live in their own repositories and did not rebuild when the engine -changed. GitHub offers no way for one repository's workflow to start another's -without a token that can write to the other repository, and VGraph keeps no such -secret in CI: it is public, and releases stay on the maintainer's machine. - -## Decision - -A VGraph release is a `v*` tag pushed by `just release-engine`. The same recipe -uses the maintainer's own `gh` login to start each plugin's workflow. That workflow -builds the engine from the tag, builds the plugin, and opens a bump PR. Publishing -stays with `just publish-plugins`. - -Plugin CI runs the engine build from the ref it checks out (`scripts/ci-engine.sh`, -inside the container named by that ref's `.swift-version`), so a Swift bump in VGraph -needs no change in the plugin repositories. - -## Consequences - -A tag pushed by hand starts nothing. Scheduled polling would catch one, but GitHub -disables schedules after 60 days without activity, which quiet plugin repositories -can reach. - -An engine build costs minutes on each new VGraph ref, and is cached by commit. Plugin -PRs build against the latest tag rather than `main`, so they keep the same cache -between releases. diff --git a/docs/adr/0036-releases-stay-on-the-maintainers-machine.md b/docs/adr/0036-releases-stay-on-the-maintainers-machine.md index 33eeaad..89ce765 100644 --- a/docs/adr/0036-releases-stay-on-the-maintainers-machine.md +++ b/docs/adr/0036-releases-stay-on-the-maintainers-machine.md @@ -1,17 +1,20 @@ # 36. Releases stay on the maintainer's machine -Date: 2026-11-08 +Date: 2026-11-08 (revised 2026-11-12) ## Status -Accepted. Supersedes [0035](./0035-a-release-is-a-tag-started-from-the-maintainers-machine.md). +Accepted. Absorbs 0035, which had a VGraph tag start each plugin's build on +GitHub and was replaced before any release used it. ## Context -0035 had a VGraph tag start each plugin's build on GitHub and open a bump PR there. -That left the release half on GitHub and half local, and finishing it on GitHub -would have needed either publish credentials in public repositories or OIDC -trust granted to them. Neither is wanted. +The plugins live in their own repositories and do not rebuild when the engine +changes. GitHub offers no way for one repository's workflow to start another's +without a token that can write to the other repository, and VGraph keeps no such +secret in CI: it is public. Finishing a release on GitHub would also need either +publish credentials in public repositories or OIDC trust granted to them. Neither +is wanted. ## Decision @@ -20,9 +23,19 @@ maintainer's own credentials: `just plugins-release`, `just release`, then `just publish-all` or the `publish-*` recipes it runs. No repository holds a publish or cross-repository credential. +`just plugins-release` builds the optimized engine itself before bumping, since +each plugin's `release.sh` copies `website/Package` in and a fresh checkout has +none. + +`publish-plugins` refuses a VGraph checkout with uncommitted changes or a HEAD +that is not on `origin/main`, and both releases name the VGraph commit. The +engine ships inside both plugins, so a release must say which source it came from. + GitHub only checks. VGraph's CI builds the optimized engine on every change, and -each plugin's CI builds against VGraph's `main`, so an engine change that breaks a -plugin shows before a release rather than during one. +each plugin's CI builds against VGraph's `main` from the ref it checks out +(`scripts/ci-engine.sh`, inside the container named by that ref's +`.swift-version`), so an engine change that breaks a plugin shows before a release +rather than during one, and a Swift bump in VGraph needs no change in the plugins. ## Consequences @@ -31,3 +44,20 @@ through a PR like any other change, because `main` takes no direct pushes. `publish-plugins` refuses a plugin checkout that is not on `main`: it tags and pushes whatever is checked out. + +The Obsidian plugin commits its copy of the engine, the wasm and its `vendor/Package` +glue, because Obsidian's directory builds that repository on its own. +`publish-plugins` commits both under the release tag so they cannot disagree. + +An engine build costs minutes on each new VGraph ref in plugin CI, and is cached +by commit. + +## Alternatives considered + +- **A `v*` tag pushed by `just release-engine` starts each plugin's workflow** + through the maintainer's `gh` login; the workflow builds the engine from the + tag, builds the plugin and opens a bump PR (0035). Rejected because it left the + release half on GitHub and half local, and a tag pushed by hand started nothing. +- **Scheduled polling in each plugin for new VGraph tags.** Rejected because + GitHub disables schedules after 60 days without activity, which quiet plugin + repositories can reach. From 738ba87028db33ee04c9ed0efd5a429effb7d73b Mon Sep 17 00:00:00 2001 From: Klaus Kneupner Date: Thu, 12 Nov 2026 07:31:03 +0100 Subject: [PATCH 6/9] release: name the commit that built the engine, and check it publish-plugins named HEAD, but website/Package and the plugins are untracked, so an engine change merged after `plugins-release` would ship the older engine under the newer commit. plugins-release now records the commit and the wasm hash in website/Package/VGRAPH_BUILD; publish-plugins names that commit and refuses a dirty build, a build not on origin/main, engine sources changed since, or a plugin wasm that is not the recorded one. A failed fetch of origin/main now fails the preflight instead of falling back to a cached ref. --- ...eleases-stay-on-the-maintainers-machine.md | 15 +++-- justfile | 43 +++++++++++-- scripts/publish-plugins.test.sh | 61 +++++++++++++++++-- 3 files changed, 105 insertions(+), 14 deletions(-) diff --git a/docs/adr/0036-releases-stay-on-the-maintainers-machine.md b/docs/adr/0036-releases-stay-on-the-maintainers-machine.md index 89ce765..f6b4650 100644 --- a/docs/adr/0036-releases-stay-on-the-maintainers-machine.md +++ b/docs/adr/0036-releases-stay-on-the-maintainers-machine.md @@ -25,11 +25,16 @@ publish or cross-repository credential. `just plugins-release` builds the optimized engine itself before bumping, since each plugin's `release.sh` copies `website/Package` in and a fresh checkout has -none. - -`publish-plugins` refuses a VGraph checkout with uncommitted changes or a HEAD -that is not on `origin/main`, and both releases name the VGraph commit. The -engine ships inside both plugins, so a release must say which source it came from. +none. It records the commit it built from and the wasm's hash in +`website/Package/VGRAPH_BUILD`, because that folder is not tracked. + +The engine ships inside both plugins, so a release must say which source it came +from. `publish-plugins` names the recorded commit in both releases, and refuses +when it cannot fetch `origin/main`, when VGraph has uncommitted changes, when the +build was made from uncommitted changes or from a commit not on `origin/main`, +when the engine sources changed between that commit and HEAD, or when either +plugin's wasm is not the recorded one. A version-bump commit after the build is +expected and allowed. GitHub only checks. VGraph's CI builds the optimized engine on every change, and each plugin's CI builds against VGraph's `main` from the ref it checks out diff --git a/justfile b/justfile index 01f81de..34cfad3 100644 --- a/justfile +++ b/justfile @@ -447,6 +447,12 @@ plugins-release bump='patch' plugin='': # checkout without it; a stale or debug copy would ship instead. ./build-wasm.sh --release --skip-smoke ./scripts/check-wasm-optimized.sh website/Package/VGraphWasm.wasm + # Which commit built this wasm: publish-plugins names it, and refuses if the + # engine sources have moved since. website/Package is not tracked, so only + # this record ties the artifact to a commit. + REV=$(git rev-parse HEAD) + [ -z "$(git status --porcelain)" ] || REV="$REV-dirty" + echo "$REV $(shasum -a 256 < website/Package/VGraphWasm.wasm | cut -d' ' -f1)" > website/Package/VGRAPH_BUILD ./release-plugins.sh "$ARG" {{plugin}} # Internal: fail with a helpful hint if a plugin repo isn't cloned. @@ -542,17 +548,46 @@ publish-plugins: _require-maintainer (_require-plugin "obsidian-vithanco") (_req # published first, a late failure leaves one plugin released and the other not. FAIL=0 # Both plugins ship the engine, so a release must come from a VGraph commit - # that main holds, and say which one. + # that main holds, and say which one: the one `plugins-release` built from. if [ -n "$(git status --porcelain)" ]; then echo "Preflight: VGraph has uncommitted changes — the engine would ship from code no commit holds." >&2 FAIL=1 fi - git fetch -q origin main 2>/dev/null || true - if ! git merge-base --is-ancestor HEAD origin/main 2>/dev/null; then + if ! git fetch -q origin main 2>/dev/null; then + echo "Preflight: could not fetch VGraph's origin/main to check against." >&2 + FAIL=1 + elif ! git merge-base --is-ancestor HEAD origin/main 2>/dev/null; then echo "Preflight: VGraph $(git rev-parse --short HEAD) is not on origin/main — push and merge it first." >&2 FAIL=1 fi - ENGINE="VGraph $(git rev-parse --short=12 HEAD)" + # What build-wasm.sh reads. A version-bump commit after the build is expected. + ENGINE_PATHS=(Sources Package.swift Package.resolved .swift-version build-wasm.sh + scripts/wasm-sdk.sh scripts/embedded-unicode.sh VGraphWasm/Package.swift + VGraphWasm/Package.resolved VGraphWasm/Sources VGraphWasm/VGraphEditor VGraphWasm/scripts) + BUILT="" + if [ ! -f website/Package/VGRAPH_BUILD ]; then + echo "Preflight: no record of which commit built website/Package — run 'just plugins-release '." >&2 + FAIL=1 + else + read -r BUILT BUILT_SUM < website/Package/VGRAPH_BUILD + if [ "${BUILT%-dirty}" != "$BUILT" ]; then + echo "Preflight: the engine was built from uncommitted changes on ${BUILT:0:12} — commit, then run 'just plugins-release' again." >&2 + FAIL=1 + elif ! git merge-base --is-ancestor "$BUILT" origin/main 2>/dev/null; then + echo "Preflight: the engine was built from ${BUILT:0:12}, which is not on origin/main." >&2 + FAIL=1 + elif ! git diff --quiet "$BUILT" HEAD -- "${ENGINE_PATHS[@]}"; then + echo "Preflight: the engine sources changed since the build at ${BUILT:0:12} — run 'just plugins-release' again." >&2 + FAIL=1 + fi + for w in website/Package obsidian-vithanco vscode-vithanco; do + if [ "$(shasum -a 256 < "$w/VGraphWasm.wasm" | cut -d' ' -f1)" != "$BUILT_SUM" ]; then + echo "Preflight: $w/VGraphWasm.wasm is not the engine built at ${BUILT:0:12}." >&2 + FAIL=1 + fi + done + fi + ENGINE="VGraph ${BUILT:0:12}" for spec in "obsidian-vithanco:main.js" "vscode-vithanco:vithanco-${OBS_V}.vsix"; do DIR=${spec%%:*}; ASSET=${spec#*:} BRANCH=$(git -C "$DIR" branch --show-current) diff --git a/scripts/publish-plugins.test.sh b/scripts/publish-plugins.test.sh index 21663bb..3e6cde4 100755 --- a/scripts/publish-plugins.test.sh +++ b/scripts/publish-plugins.test.sh @@ -50,12 +50,23 @@ given_plugins_at() { # version, in a fresh directory WORK with pushed plugin rep git -C "$WORK/$p" push -q origin main done # WORK stands in for VGraph itself: committed, and pushed to its main. - printf '%s\n' '*.git/' obsidian-vithanco/ vscode-vithanco/ out gh.log > "$WORK/.gitignore" + mkdir -p "$WORK/Sources" && echo 'engine' > "$WORK/Sources/engine.swift" + echo '{}' > "$WORK/plugins.json" + printf '%s\n' '*.git/' obsidian-vithanco/ vscode-vithanco/ website/Package/ out gh.log > "$WORK/.gitignore" git init -q --bare -b main "$WORK/vgraph.git" git -C "$WORK" init -q -b main git -C "$WORK" remote add origin "$WORK/vgraph.git" git -C "$WORK" add . && git -C "$WORK" commit -qm "engine" git -C "$WORK" push -q origin main + record_build +} +# What `just plugins-release` writes after building: the commit and the wasm it produced. +record_build() { + echo "$(git -C "$WORK" rev-parse HEAD) $(shasum -a 256 < "$WORK/website/Package/VGraphWasm.wasm" | cut -d' ' -f1)" \ + > "$WORK/website/Package/VGRAPH_BUILD" +} +commit_and_push() { # file, message + echo "$2" > "$WORK/$1" && git -C "$WORK" add "$1" && git -C "$WORK" commit -qm "$2" && git -C "$WORK" push -q origin main } nothing_released() { # why for p in obsidian-vithanco vscode-vithanco; do @@ -75,7 +86,8 @@ done # Given a local rebuild that changed the committed engine, when publishing, then it is committed under the tag. given_plugins_at 1.2.3 -printf '\0asm\1\0\0\0\1' > "$WORK/obsidian-vithanco/VGraphWasm.wasm" +for w in website/Package obsidian-vithanco vscode-vithanco; do printf '\0asm\1\0\0\0\1' > "$WORK/$w/VGraphWasm.wasm"; done +record_build publish || fail "publishing a changed engine failed: $(cat "$WORK/out")" [ "$(git -C "$WORK/obsidian-vithanco" log -1 --format=%s 1.2.3)" = "chore: release 1.2.3" ] \ || fail "the changed engine was not committed under the tag" @@ -106,12 +118,51 @@ publish && fail "published from a VGraph commit that is not on origin/main" grep -q 'origin/main' "$WORK/out" || fail "does not name origin/main: $(cat "$WORK/out")" nothing_released "unpushed VGraph" -# Given a clean, pushed VGraph, when publishing, then both releases name the engine's commit. +# Given the version bump committed after the build, when publishing, then it +# publishes, and both releases name the commit that built the engine, not HEAD. given_plugins_at 1.2.3 ENGINE=$(git -C "$WORK" rev-parse --short=12 HEAD) -publish || fail "publishing from a clean VGraph failed: $(cat "$WORK/out")" +commit_and_push plugins.json '{"bumped":true}' +publish || fail "publishing after a version-bump commit failed: $(cat "$WORK/out")" [ "$(grep '^release create' "$GH_LOG" | grep -c "$ENGINE")" = 2 ] \ - || fail "the releases do not name VGraph $ENGINE: $(cat "$GH_LOG")" + || fail "the releases do not name the build commit $ENGINE: $(cat "$GH_LOG")" + +# Given an engine change merged after the build, when publishing, then nothing is +# released: the plugins carry the older engine, and the notes would name the newer. +given_plugins_at 1.2.3 +commit_and_push Sources/engine.swift 'engine changed' +publish && fail "published an engine built before the engine changed" +grep -q 'changed since' "$WORK/out" || fail "does not say the engine changed: $(cat "$WORK/out")" +nothing_released "engine changed after the build" + +# Given an engine built from uncommitted changes, when publishing, then nothing is released. +given_plugins_at 1.2.3 +sed -i.bak 's/^\([0-9a-f]*\) /\1-dirty /' "$WORK/website/Package/VGRAPH_BUILD" +publish && fail "published an engine built from uncommitted changes" +grep -q 'uncommitted' "$WORK/out" || fail "does not say the build was uncommitted: $(cat "$WORK/out")" +nothing_released "dirty build" + +# Given a plugin whose wasm is not the recorded build, when publishing, then nothing is released. +given_plugins_at 1.2.3 +printf '\0asm\1\0\0\0\2' > "$WORK/vscode-vithanco/VGraphWasm.wasm" +publish && fail "published a plugin carrying another engine" +grep -q 'vscode-vithanco/VGraphWasm.wasm' "$WORK/out" || fail "does not name the mismatched wasm: $(cat "$WORK/out")" +nothing_released "mismatched wasm" + +# Given no recorded build, when publishing, then nothing is released. +given_plugins_at 1.2.3 +rm "$WORK/website/Package/VGRAPH_BUILD" +publish && fail "published without knowing which commit built the engine" +grep -q 'plugins-release' "$WORK/out" || fail "does not point at plugins-release: $(cat "$WORK/out")" +nothing_released "no recorded build" + +# Given origin cannot be fetched, when publishing, then nothing is released: a +# cached origin/main may still hold a commit the remote has dropped. +given_plugins_at 1.2.3 +git -C "$WORK" remote set-url origin "$WORK/missing.git" +publish && fail "published without fetching origin/main" +grep -q 'fetch' "$WORK/out" || fail "does not say the fetch failed: $(cat "$WORK/out")" +nothing_released "fetch failed" # Given a rebuild that refreshed the Obsidian plugin's vendored engine glue, when # publishing, then the glue is committed under the tag next to the wasm: the From 4499156332cb2b59dbcb3309dcebe1ff84dbb06f Mon Sep 17 00:00:00 2001 From: Klaus Kneupner Date: Thu, 12 Nov 2026 07:34:07 +0100 Subject: [PATCH 7/9] release: let every engine build write its own build record build-wasm.sh replaces website/Package on every build, so a record written by plugins-release was deleted by the `just release` that follows it, and publish-plugins then refused. build-wasm.sh now writes the record itself, through scripts/record-engine-build.sh, which the publish-plugins fixture also uses so the two cannot disagree on the format. --- .github/workflows/ci.yml | 2 +- build-wasm.sh | 2 ++ ...eleases-stay-on-the-maintainers-machine.md | 5 +-- justfile | 11 ++---- scripts/publish-plugins.test.sh | 7 ++-- scripts/record-engine-build.sh | 11 ++++++ scripts/record-engine-build.test.sh | 35 +++++++++++++++++++ 7 files changed, 57 insertions(+), 16 deletions(-) create mode 100755 scripts/record-engine-build.sh create mode 100755 scripts/record-engine-build.test.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 92ce415..2b4935d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -129,7 +129,7 @@ jobs: - name: Shell tests run: | failed=0 - for t in check-wasm-optimized justfile-hygiene doctor-kegs doctor-sdk codeowners licence audit-public publish-plugins; do + for t in check-wasm-optimized justfile-hygiene doctor-kegs doctor-sdk codeowners licence audit-public record-engine-build publish-plugins; do echo "::group::$t" ./scripts/$t.test.sh || failed=1 echo "::endgroup::" diff --git a/build-wasm.sh b/build-wasm.sh index 266be51..adc8d0c 100755 --- a/build-wasm.sh +++ b/build-wasm.sh @@ -196,6 +196,8 @@ awk ' mv ../website/Package/platforms/browser.js.tmp ../website/Package/platforms/browser.js cd .. +# This build replaced website/Package, so it also writes the record of its source. +"$SCRIPT_DIR/scripts/record-engine-build.sh" website/Package echo "WASM build completed in $(( SECONDS - STEP_START ))s" # Show final size diff --git a/docs/adr/0036-releases-stay-on-the-maintainers-machine.md b/docs/adr/0036-releases-stay-on-the-maintainers-machine.md index f6b4650..c50608a 100644 --- a/docs/adr/0036-releases-stay-on-the-maintainers-machine.md +++ b/docs/adr/0036-releases-stay-on-the-maintainers-machine.md @@ -25,8 +25,9 @@ publish or cross-repository credential. `just plugins-release` builds the optimized engine itself before bumping, since each plugin's `release.sh` copies `website/Package` in and a fresh checkout has -none. It records the commit it built from and the wasm's hash in -`website/Package/VGRAPH_BUILD`, because that folder is not tracked. +none. Every engine build records the commit it built from and the wasm's hash in +`website/Package/VGRAPH_BUILD` (`scripts/record-engine-build.sh`, run by +`build-wasm.sh`), because that folder is not tracked and each build replaces it. The engine ships inside both plugins, so a release must say which source it came from. `publish-plugins` names the recorded commit in both releases, and refuses diff --git a/justfile b/justfile index 34cfad3..2d544f0 100644 --- a/justfile +++ b/justfile @@ -254,6 +254,7 @@ test filter='': build ./scripts/doctor-kegs.test.sh ./scripts/doctor-sdk.test.sh ./scripts/embedded-unicode.test.sh + ./scripts/record-engine-build.test.sh ./scripts/codeowners.test.sh ./scripts/licence.test.sh ./scripts/audit-public.test.sh @@ -447,12 +448,6 @@ plugins-release bump='patch' plugin='': # checkout without it; a stale or debug copy would ship instead. ./build-wasm.sh --release --skip-smoke ./scripts/check-wasm-optimized.sh website/Package/VGraphWasm.wasm - # Which commit built this wasm: publish-plugins names it, and refuses if the - # engine sources have moved since. website/Package is not tracked, so only - # this record ties the artifact to a commit. - REV=$(git rev-parse HEAD) - [ -z "$(git status --porcelain)" ] || REV="$REV-dirty" - echo "$REV $(shasum -a 256 < website/Package/VGraphWasm.wasm | cut -d' ' -f1)" > website/Package/VGRAPH_BUILD ./release-plugins.sh "$ARG" {{plugin}} # Internal: fail with a helpful hint if a plugin repo isn't cloned. @@ -548,7 +543,7 @@ publish-plugins: _require-maintainer (_require-plugin "obsidian-vithanco") (_req # published first, a late failure leaves one plugin released and the other not. FAIL=0 # Both plugins ship the engine, so a release must come from a VGraph commit - # that main holds, and say which one: the one `plugins-release` built from. + # that main holds, and say which one: the one build-wasm.sh recorded. if [ -n "$(git status --porcelain)" ]; then echo "Preflight: VGraph has uncommitted changes — the engine would ship from code no commit holds." >&2 FAIL=1 @@ -566,7 +561,7 @@ publish-plugins: _require-maintainer (_require-plugin "obsidian-vithanco") (_req VGraphWasm/Package.resolved VGraphWasm/Sources VGraphWasm/VGraphEditor VGraphWasm/scripts) BUILT="" if [ ! -f website/Package/VGRAPH_BUILD ]; then - echo "Preflight: no record of which commit built website/Package — run 'just plugins-release '." >&2 + echo "Preflight: no record of which commit built website/Package — rebuild it ('just release' or 'just plugins-release')." >&2 FAIL=1 else read -r BUILT BUILT_SUM < website/Package/VGRAPH_BUILD diff --git a/scripts/publish-plugins.test.sh b/scripts/publish-plugins.test.sh index 3e6cde4..7736447 100755 --- a/scripts/publish-plugins.test.sh +++ b/scripts/publish-plugins.test.sh @@ -60,11 +60,8 @@ given_plugins_at() { # version, in a fresh directory WORK with pushed plugin rep git -C "$WORK" push -q origin main record_build } -# What `just plugins-release` writes after building: the commit and the wasm it produced. -record_build() { - echo "$(git -C "$WORK" rev-parse HEAD) $(shasum -a 256 < "$WORK/website/Package/VGraphWasm.wasm" | cut -d' ' -f1)" \ - > "$WORK/website/Package/VGRAPH_BUILD" -} +# What build-wasm.sh writes after every build: the commit and the wasm it produced. +record_build() { ( cd "$WORK" && "$REPO_ROOT/scripts/record-engine-build.sh" website/Package ); } commit_and_push() { # file, message echo "$2" > "$WORK/$1" && git -C "$WORK" add "$1" && git -C "$WORK" commit -qm "$2" && git -C "$WORK" push -q origin main } diff --git a/scripts/record-engine-build.sh b/scripts/record-engine-build.sh new file mode 100755 index 0000000..f8aa3c1 --- /dev/null +++ b/scripts/record-engine-build.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +# Records which VGraph commit built a wasm package, as `[-dirty] ` +# in /VGRAPH_BUILD. The package directory is not tracked, so this is +# the only link from an artifact to its source; publish-plugins reads it. +# Run from the repository root: record-engine-build.sh website/Package +set -euo pipefail + +DIR=$1 +REV=$(git rev-parse HEAD) +[ -z "$(git status --porcelain)" ] || REV="$REV-dirty" +echo "$REV $(shasum -a 256 < "$DIR/VGraphWasm.wasm" | cut -d' ' -f1)" > "$DIR/VGRAPH_BUILD" diff --git a/scripts/record-engine-build.test.sh b/scripts/record-engine-build.test.sh new file mode 100755 index 0000000..438ec1c --- /dev/null +++ b/scripts/record-engine-build.test.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# build-wasm.sh replaces website/Package on every build, so the record of which +# commit built it has to be written by the build itself, or a later build leaves +# publish-plugins with no record, or a stale one. +set -uo pipefail + +SCRIPT="$(cd "$(dirname "$0")" && pwd)/record-engine-build.sh" +ROOT=$(mktemp -d) +trap 'rm -rf "$ROOT"' EXIT +FAILED=0 +fail() { echo "FAIL: $*" >&2; FAILED=1; } +export GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@example.invalid GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@example.invalid + +cd "$ROOT" +git init -q -b main +echo '/website/Package' > .gitignore +mkdir -p Sources website/Package +echo 'engine' > Sources/engine.swift +printf '\0asm\1\0\0\0' > website/Package/VGraphWasm.wasm +git add . && git commit -qm engine +SUM=$(shasum -a 256 < website/Package/VGraphWasm.wasm | cut -d' ' -f1) + +# Given a clean checkout, when recording, then the record is the commit and the wasm's hash. +"$SCRIPT" website/Package || fail "recording a clean build failed" +[ "$(cat website/Package/VGRAPH_BUILD)" = "$(git rev-parse HEAD) $SUM" ] \ + || fail "clean record is '$(cat website/Package/VGRAPH_BUILD)'" + +# Given uncommitted engine changes, when recording, then the commit is marked dirty. +echo 'changed' > Sources/engine.swift +"$SCRIPT" website/Package || fail "recording a dirty build failed" +[ "$(cat website/Package/VGRAPH_BUILD)" = "$(git rev-parse HEAD)-dirty $SUM" ] \ + || fail "dirty record is '$(cat website/Package/VGRAPH_BUILD)'" + +[ "$FAILED" -eq 0 ] && echo "✓ record-engine-build" +exit "$FAILED" From b6c19398dc6a5696477b0870c32f5cd834cb8760 Mon Sep 17 00:00:00 2001 From: Klaus Kneupner Date: Thu, 12 Nov 2026 07:44:03 +0100 Subject: [PATCH 8/9] release: record an unknown commit instead of failing the build CI containers own the checkout as another user, so git refuses to read it ("dubious ownership") and record-engine-build.sh failed the wasm build. It now records `unknown`, the build goes on, and publish-plugins refuses that record with its own message. --- justfile | 5 ++++- scripts/publish-plugins.test.sh | 7 +++++++ scripts/record-engine-build.sh | 10 ++++++++-- scripts/record-engine-build.test.sh | 9 +++++++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/justfile b/justfile index 2d544f0..f93d0b0 100644 --- a/justfile +++ b/justfile @@ -565,7 +565,10 @@ publish-plugins: _require-maintainer (_require-plugin "obsidian-vithanco") (_req FAIL=1 else read -r BUILT BUILT_SUM < website/Package/VGRAPH_BUILD - if [ "${BUILT%-dirty}" != "$BUILT" ]; then + if [ "$BUILT" = unknown ]; then + echo "Preflight: the engine was built from an unknown commit — git could not read the checkout. Rebuild it here." >&2 + FAIL=1 + elif [ "${BUILT%-dirty}" != "$BUILT" ]; then echo "Preflight: the engine was built from uncommitted changes on ${BUILT:0:12} — commit, then run 'just plugins-release' again." >&2 FAIL=1 elif ! git merge-base --is-ancestor "$BUILT" origin/main 2>/dev/null; then diff --git a/scripts/publish-plugins.test.sh b/scripts/publish-plugins.test.sh index 7736447..f951e2a 100755 --- a/scripts/publish-plugins.test.sh +++ b/scripts/publish-plugins.test.sh @@ -146,6 +146,13 @@ publish && fail "published a plugin carrying another engine" grep -q 'vscode-vithanco/VGraphWasm.wasm' "$WORK/out" || fail "does not name the mismatched wasm: $(cat "$WORK/out")" nothing_released "mismatched wasm" +# Given a build whose commit could not be read, when publishing, then nothing is released. +given_plugins_at 1.2.3 +sed -i.bak 's/^[0-9a-f]* /unknown /' "$WORK/website/Package/VGRAPH_BUILD" +publish && fail "published an engine whose source commit is unknown" +grep -q 'unknown commit' "$WORK/out" || fail "does not say the commit is unknown: $(cat "$WORK/out")" +nothing_released "unknown build commit" + # Given no recorded build, when publishing, then nothing is released. given_plugins_at 1.2.3 rm "$WORK/website/Package/VGRAPH_BUILD" diff --git a/scripts/record-engine-build.sh b/scripts/record-engine-build.sh index f8aa3c1..16c3373 100755 --- a/scripts/record-engine-build.sh +++ b/scripts/record-engine-build.sh @@ -1,11 +1,17 @@ #!/usr/bin/env bash # Records which VGraph commit built a wasm package, as `[-dirty] ` +# (or `unknown `) # in /VGRAPH_BUILD. The package directory is not tracked, so this is # the only link from an artifact to its source; publish-plugins reads it. # Run from the repository root: record-engine-build.sh website/Package set -euo pipefail DIR=$1 -REV=$(git rev-parse HEAD) -[ -z "$(git status --porcelain)" ] || REV="$REV-dirty" +# Git may be unable to name the commit (a tarball, or a CI checkout owned by +# another user): the build must still succeed, and publish-plugins refuses it. +if REV=$(git rev-parse HEAD 2>/dev/null) && STATUS=$(git status --porcelain 2>/dev/null); then + [ -z "$STATUS" ] || REV="$REV-dirty" +else + REV=unknown +fi echo "$REV $(shasum -a 256 < "$DIR/VGraphWasm.wasm" | cut -d' ' -f1)" > "$DIR/VGRAPH_BUILD" diff --git a/scripts/record-engine-build.test.sh b/scripts/record-engine-build.test.sh index 438ec1c..a6ad5ff 100755 --- a/scripts/record-engine-build.test.sh +++ b/scripts/record-engine-build.test.sh @@ -31,5 +31,14 @@ echo 'changed' > Sources/engine.swift [ "$(cat website/Package/VGRAPH_BUILD)" = "$(git rev-parse HEAD)-dirty $SUM" ] \ || fail "dirty record is '$(cat website/Package/VGRAPH_BUILD)'" +# Given a build whose source git cannot name (no repository, or one git refuses to +# read, as CI containers do for a checkout owned by another user), when recording, +# then the build still succeeds and records the commit as unknown. +NOGIT=$(mktemp -d "$ROOT/nogit.XXXXXX") +mkdir -p "$NOGIT/website/Package" && cp website/Package/VGraphWasm.wasm "$NOGIT/website/Package/" +( cd "$NOGIT" && GIT_CEILING_DIRECTORIES="$ROOT" "$SCRIPT" website/Package ) || fail "recording without a readable repository failed the build" +[ "$(cat "$NOGIT/website/Package/VGRAPH_BUILD")" = "unknown $SUM" ] \ + || fail "record without a repository is '$(cat "$NOGIT/website/Package/VGRAPH_BUILD")'" + [ "$FAILED" -eq 0 ] && echo "✓ record-engine-build" exit "$FAILED" From 4e8b1b19848838f8396ef41e840c934b244eccda Mon Sep 17 00:00:00 2001 From: Klaus Kneupner Date: Thu, 12 Nov 2026 07:47:29 +0100 Subject: [PATCH 9/9] release: refuse a build record without a hash; keep fixtures in temp record-engine-build.sh hashed the wasm inside echo's arguments, where set -e does not reach, so a missing wasm wrote a record with no hash and exited 0. The hash is now its own checked assignment. The shell tests write and commit fixture files; if mktemp failed, an empty path left them in the caller's directory, such as a VGraph checkout. Every temp directory is now checked before use. --- scripts/publish-plugins.test.sh | 4 ++-- scripts/record-engine-build.sh | 5 ++++- scripts/record-engine-build.test.sh | 14 +++++++++++--- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/scripts/publish-plugins.test.sh b/scripts/publish-plugins.test.sh index f951e2a..60d093d 100755 --- a/scripts/publish-plugins.test.sh +++ b/scripts/publish-plugins.test.sh @@ -5,7 +5,7 @@ set -uo pipefail REPO_ROOT=$(cd "$(dirname "$0")/.." && pwd) -ROOT=$(mktemp -d) +ROOT=$(mktemp -d) || exit 1 trap 'rm -rf "$ROOT"' EXIT FAILED=0 fail() { echo "FAIL: $*" >&2; FAILED=1; } @@ -22,7 +22,7 @@ export VITHANCO_MAINTAINER=1 export GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@example.invalid GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@example.invalid given_plugins_at() { # version, in a fresh directory WORK with pushed plugin repos - WORK=$(mktemp -d "$ROOT/work.XXXXXX") + WORK=$(mktemp -d "$ROOT/work.XXXXXX") || exit 1 export GH_LOG="$WORK/gh.log" : > "$GH_LOG" mkdir -p "$WORK/website/Package" "$WORK/scripts" diff --git a/scripts/record-engine-build.sh b/scripts/record-engine-build.sh index 16c3373..17d7f38 100755 --- a/scripts/record-engine-build.sh +++ b/scripts/record-engine-build.sh @@ -14,4 +14,7 @@ if REV=$(git rev-parse HEAD 2>/dev/null) && STATUS=$(git status --porcelain 2>/d else REV=unknown fi -echo "$REV $(shasum -a 256 < "$DIR/VGraphWasm.wasm" | cut -d' ' -f1)" > "$DIR/VGRAPH_BUILD" +# Its own assignment, so a missing wasm stops here instead of writing a record +# without a hash: set -e does not see a failure inside echo's arguments. +SUM=$(shasum -a 256 < "$DIR/VGraphWasm.wasm" | cut -d' ' -f1) +echo "$REV $SUM" > "$DIR/VGRAPH_BUILD" diff --git a/scripts/record-engine-build.test.sh b/scripts/record-engine-build.test.sh index a6ad5ff..bcc2107 100755 --- a/scripts/record-engine-build.test.sh +++ b/scripts/record-engine-build.test.sh @@ -5,13 +5,13 @@ set -uo pipefail SCRIPT="$(cd "$(dirname "$0")" && pwd)/record-engine-build.sh" -ROOT=$(mktemp -d) +ROOT=$(mktemp -d) || exit 1 trap 'rm -rf "$ROOT"' EXIT FAILED=0 fail() { echo "FAIL: $*" >&2; FAILED=1; } export GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@example.invalid GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@example.invalid -cd "$ROOT" +cd "$ROOT" || exit 1 git init -q -b main echo '/website/Package' > .gitignore mkdir -p Sources website/Package @@ -34,11 +34,19 @@ echo 'changed' > Sources/engine.swift # Given a build whose source git cannot name (no repository, or one git refuses to # read, as CI containers do for a checkout owned by another user), when recording, # then the build still succeeds and records the commit as unknown. -NOGIT=$(mktemp -d "$ROOT/nogit.XXXXXX") +NOGIT=$(mktemp -d "$ROOT/nogit.XXXXXX") || exit 1 mkdir -p "$NOGIT/website/Package" && cp website/Package/VGraphWasm.wasm "$NOGIT/website/Package/" ( cd "$NOGIT" && GIT_CEILING_DIRECTORIES="$ROOT" "$SCRIPT" website/Package ) || fail "recording without a readable repository failed the build" [ "$(cat "$NOGIT/website/Package/VGRAPH_BUILD")" = "unknown $SUM" ] \ || fail "record without a repository is '$(cat "$NOGIT/website/Package/VGRAPH_BUILD")'" +# Given a package without a readable wasm, when recording, then it fails and +# writes no record: a record without a hash would name a build nobody can check. +NOWASM=$(mktemp -d "$ROOT/nowasm.XXXXXX") || exit 1 +mkdir -p "$NOWASM/website/Package" +( cd "$NOWASM" && GIT_CEILING_DIRECTORIES="$ROOT" "$SCRIPT" website/Package 2>/dev/null ) \ + && fail "recording a package without a wasm succeeded" +[ -e "$NOWASM/website/Package/VGRAPH_BUILD" ] && fail "wrote a record without a hash: '$(cat "$NOWASM/website/Package/VGRAPH_BUILD")'" + [ "$FAILED" -eq 0 ] && echo "✓ record-engine-build" exit "$FAILED"