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/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]>( 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 () => { 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/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..c50608a 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,25 @@ 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. 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 +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`, 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 +50,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. diff --git a/justfile b/justfile index 4ecac52..f93d0b0 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 @@ -443,6 +444,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. @@ -537,6 +542,50 @@ 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: 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 + fi + 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 + # 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 — rebuild it ('just release' or 'just plugins-release')." >&2 + FAIL=1 + else + read -r BUILT BUILT_SUM < website/Package/VGRAPH_BUILD + 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 + 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) @@ -561,11 +610,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 +628,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 +647,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..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" @@ -43,10 +43,33 @@ 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. + 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 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 +} +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; } @@ -60,7 +83,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" @@ -76,5 +100,82 @@ 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 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) +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 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 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" +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 +# 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" diff --git a/scripts/record-engine-build.sh b/scripts/record-engine-build.sh new file mode 100755 index 0000000..17d7f38 --- /dev/null +++ b/scripts/record-engine-build.sh @@ -0,0 +1,20 @@ +#!/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 +# 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 +# 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 new file mode 100755 index 0000000..bcc2107 --- /dev/null +++ b/scripts/record-engine-build.test.sh @@ -0,0 +1,52 @@ +#!/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) || 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" || exit 1 +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)'" + +# 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") || 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"