R1: Linux export pipeline (make dist, make dist-check)

make dist (tools/dist.sh) checks the official export templates against
tools/engine.sha512, installs only the Linux x86_64 ones into the
repo-local engine data, exports the "Linux" preset, checks the binary is
the verified release template, and packs
build/dist/tidewall-<version>-linux-x86_64.tar.gz with a .sha256:
tidewall.x86_64, tidewall.pck, a tidewall-server launcher that runs the
same game headless with clean SIGTERM handling, an example server.cfg,
README, VERSION, licences and asset provenance.

BuildInfo gives the version (application/config/version, now 0.9.0) and
the commit (build_commit.txt written by make dist, or .git in a
checkout). The main menu shows "Version 0.9.0 (commit)" and the server's
start log line carries version and commit.

make dist-check (tools/dist_check.sh) unpacks the package outside the
repo with HOME and XDG dirs in a temp dir and runs smoke against it
(new SMOKE_DIST mode), a whole bot match, and the exported game joining
the exported server over loopback.

A release template crashes on a call on null (exit 139) and ignores
invalid calls, so in package mode smoke's fault check expects only a
non-zero exit.

Closes #60

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 23:51:36 -05:00
co-authored by Claude Opus 5.5
parent 9ce0865c9b
commit 4439d9a84f
18 changed files with 533 additions and 9 deletions
Executable
+96
View File
@@ -0,0 +1,96 @@
#!/usr/bin/env bash
# R1: exports the Linux x86_64 game, which is also the dedicated server, with the
# official Godot export templates and packs them into build/dist/tidewall-<version>-linux-x86_64.tar.gz.
#
# tools/dist.sh
#
# The templates come from tools/godot/ (git-ignored), checked against
# tools/engine.sha512 before use, and are installed into the repo-local engine data
# (.godot-home/), never the user's home. The version is project.godot's
# application/config/version; the commit is written into the export as
# build_commit.txt, which BuildInfo reads.
#
# The package holds:
# tidewall.x86_64 the engine (the official release template)
# tidewall.pck the game
# tidewall-server runs the same game headless as a dedicated server, with
# clean SIGTERM handling
# server.cfg an example server configuration
# LICENSE, LICENSE-ASSETS, README.md, PROVENANCE.md, VERSION
set -euo pipefail
repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo"
engine_version="$(cut -d. -f1-3 tools/engine.version)" # 4.7.2
engine_tag="${engine_version}.$(cut -d. -f4 tools/engine.version)" # 4.7.2.stable
templates_zip="tools/godot/Godot_v${engine_version}-stable_export_templates.tpz"
templates_dir=".godot-home/data/godot/export_templates/$engine_tag"
version="$(sed -n 's/^config\/version="\(.*\)"$/\1/p' project.godot)"
[[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "dist FAIL: no version in project.godot" >&2; exit 1; }
commit="$(git rev-parse --short=12 HEAD)"
if [[ -n "$(git status --porcelain --untracked-files=no)" ]]; then
commit="$commit-dirty"
fi
name="tidewall-$version-linux-x86_64"
out="build/dist"
stage="$out/stage"
package="$out/$name"
tools/godot.sh --verify >/dev/null
# The official templates, checked, then only the Linux x86_64 ones installed.
if [[ ! -f "$templates_dir/linux_release.x86_64" || "$(cat "$templates_dir/.verified" 2>/dev/null)" != "$(grep 'export_templates\.tpz$' tools/engine.sha512 | cut -d' ' -f1)" ]]; then
[[ -f "$templates_zip" ]] || { echo "dist FAIL: missing $templates_zip (see tools/godot.sh)" >&2; exit 1; }
echo "dist: checking the export templates against tools/engine.sha512" >&2
grep 'export_templates\.tpz$' tools/engine.sha512 | sha512sum --check --quiet
mkdir -p "$templates_dir"
unzip -q -o -j "$templates_zip" templates/linux_release.x86_64 templates/linux_debug.x86_64 templates/version.txt -d "$templates_dir"
[[ "$(cat "$templates_dir/version.txt")" == "$engine_tag" ]] || { echo "dist FAIL: templates are for $(cat "$templates_dir/version.txt"), not $engine_tag" >&2; exit 1; }
grep 'export_templates\.tpz$' tools/engine.sha512 | cut -d' ' -f1 >"$templates_dir/.verified"
fi
rm -rf "$stage" "$package" "$out/$name.tar.gz" "$out/$name.tar.gz.sha256"
mkdir -p "$stage" "$package"
trap 'rm -f "$repo/build_commit.txt"' EXIT
printf '%s\n' "$commit" >build_commit.txt
tools/godot.sh --import --quit >/dev/null 2>&1 || true
export_preset() {
local preset="$1" target="$2" raw
echo "dist: exporting '$preset'" >&2
if ! raw="$(tools/godot.sh --export-release "$preset" "$repo/$target" 2>&1)"; then
echo "dist FAIL: exporting '$preset' failed" >&2
tail -n 20 <<<"$raw" >&2
exit 1
fi
if grep -E '^(ERROR|SCRIPT ERROR)' <<<"$raw" >&2; then
echo "dist FAIL: errors while exporting '$preset'" >&2
exit 1
fi
[[ -f "$repo/$target" ]] || { echo "dist FAIL: '$preset' wrote no $target" >&2; exit 1; }
}
export_preset "Linux" "$stage/tidewall.x86_64"
rm -f build_commit.txt
# The exported binary must be the verified official template, unchanged.
cmp -s "$stage/tidewall.x86_64" "$templates_dir/linux_release.x86_64" || { echo "dist FAIL: the exported binary isn't the release template" >&2; exit 1; }
install -m 0755 "$stage/tidewall.x86_64" "$package/tidewall.x86_64"
install -m 0644 "$stage/tidewall.pck" "$package/tidewall.pck"
install -m 0755 packaging/dist/tidewall-server "$package/tidewall-server"
install -m 0644 LICENSE LICENSE-ASSETS "$package/"
install -m 0644 packaging/server/server.cfg "$package/server.cfg"
install -m 0644 packaging/dist/README.md "$package/README.md"
install -m 0644 assets/PROVENANCE.md "$package/PROVENANCE.md"
printf 'Tidewall %s\ncommit %s\nengine Godot %s\n' "$version" "$commit" "$(cat tools/engine.version)" >"$package/VERSION"
# Reproducible-ish archive: fixed owner, sorted names, mtimes from the commit.
stamp="$(git log -1 --format=%ct)"
tar --sort=name --owner=0 --group=0 --numeric-owner --mtime="@$stamp" \
-C "$out" -czf "$out/$name.tar.gz" "$name"
(cd "$out" && sha256sum "$name.tar.gz" >"$name.tar.gz.sha256")
rm -rf "$stage"
echo "dist: $out/$name.tar.gz ($(du -h "$out/$name.tar.gz" | cut -f1)), commit $commit"
tar -tzvf "$out/$name.tar.gz" | awk '{print " " $3 "\t" $6}'
+99
View File
@@ -0,0 +1,99 @@
#!/usr/bin/env bash
# R1: builds the release package with tools/dist.sh, unpacks it outside the repository
# and checks that it works there with nothing from the checkout:
# - its checksum, and that it holds exactly the files it should;
# - tools/smoke.sh against its server (SMOKE_DIST);
# - a whole bot-only match, lobby to results, on its server;
# - its game, headless with the autoplay script, joining its server over loopback UDP
# and playing (as tools/client_check.sh does from the repo);
# - the version and commit in the logs match its VERSION file.
#
# tools/dist_check.sh about 3 minutes
set -uo pipefail
repo="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo"
status=0
fail() {
echo "dist-check FAIL: $*"
status=1
}
tools/dist.sh >/dev/null || { echo "dist-check FAIL: tools/dist.sh failed"; tools/dist.sh 2>&1 | tail -n 10; exit 1; }
archive="$(ls -t build/dist/tidewall-*-linux-x86_64.tar.gz | head -n 1)"
name="$(basename "$archive" .tar.gz)"
work="$(mktemp -d)"
cleanup() {
[[ -n "${server_pid:-}" ]] && kill -TERM "$server_pid" 2>/dev/null
rm -rf "$work"
}
trap cleanup EXIT
(cd "$(dirname "$archive")" && sha256sum --check --quiet "$name.tar.gz.sha256") || fail "the checksum doesn't match"
tar -xzf "$archive" -C "$work"
package="$work/$name"
# Nothing the package runs may reach back into the checkout, and nothing it writes may
# land in the user's home.
export HOME="$work/home" XDG_DATA_HOME="$work/home/data" XDG_CONFIG_HOME="$work/home/config" XDG_CACHE_HOME="$work/home/cache" XDG_STATE_HOME="$work/home/state"
mkdir -p "$HOME"
expected="LICENSE LICENSE-ASSETS PROVENANCE.md README.md VERSION server.cfg tidewall-server tidewall.pck tidewall.x86_64"
actual="$(cd "$package" && ls -A | LC_ALL=C sort | tr '\n' ' ' | sed 's/ $//')"
[[ "$actual" == "$expected" ]] || fail "the package holds '$actual', expected '$expected'"
version="$(sed -n 's/^Tidewall //p' "$package/VERSION")"
commit="$(sed -n 's/^commit //p' "$package/VERSION")"
[[ -n "$version" && -n "$commit" ]] || fail "VERSION doesn't name a version and commit"
echo "dist-check: smoke against $name" >&2
(cd "$work" && SMOKE_DIST="$package" "$repo/tools/smoke.sh") | sed 's/^/ /' || fail "smoke failed against the package"
echo "dist-check: a whole bot match on the package's server" >&2
match_log="$work/match.log"
(cd "$work" && timeout --signal=KILL 600 nice -n 15 "$package/tidewall-server" --seed=2 --bots=24 --matches=1 --unthrottled >"$match_log" 2>&1)
code=$?
[[ "$code" -eq 0 ]] || fail "the bot match exited $code"
grep -q '"event":"results"' "$match_log" || fail "the bot match never reached its results"
grep -q '"errors":0,"event":"stop"' "$match_log" || fail "the bot match logged errors"
start="$(grep -m1 '"event":"start"' "$match_log")"
grep -q "\"version\":\"$version\"" <<<"$start" || fail "the server log doesn't give version $version"
grep -q "\"commit\":\"$commit\"" <<<"$start" || fail "the server log doesn't give commit $commit"
echo " bot match: results reached, version $version, commit $commit"
echo "dist-check: the package's game joins its server" >&2
port=$((20000 + RANDOM % 20000))
server_log="$work/server.log"
cd "$work"
TIDEWALL_STATE="$work/server-state" nice -n 15 "$package/tidewall-server" --listen --port="$port" --seed=2 --bots=1 --matches=1 >"$server_log" 2>&1 &
server_pid=$!
cd "$repo"
for _ in $(seq 1 100); do
grep -q '"event":"start"' "$server_log" 2>/dev/null && break
sleep 0.1
done
client_log="$work/client.log"
(cd "$work" && timeout --signal=KILL 120 nice -n 15 "$package/tidewall.x86_64" --headless -- --connect="127.0.0.1:$port" --name=Mara --autoplay --client-seconds=55 >"$client_log" 2>&1)
client_code=$?
kill -TERM "$server_pid" 2>/dev/null
wait "$server_pid"
server_code=$?
server_pid=""
report="$(grep -m1 '"event":"client"' "$client_log" || true)"
[[ "$client_code" -eq 0 ]] || fail "the game exited with $client_code"
[[ "$server_code" -eq 0 ]] || fail "the server exited with $server_code"
[[ -n "$report" ]] || fail "the game said nothing"
grep -q '"joined":true' <<<"$report" || fail "the game never joined"
grep -q '"phases":\["lobby","countdown","drop"' <<<"$report" || fail "the game didn't follow the match from the lobby into the drop"
grep -q '"bad_packets":0' <<<"$report" || fail "the game was sent packets it couldn't read"
playing="$(sed -n 's/.*"frames_playing":\([0-9]*\).*/\1/p' <<<"$report")"
[[ "${playing:-0}" -ge 300 ]] || fail "the game's player was in the match for only ${playing:-0} frames"
grep -q '"event":"player_joined".*"name":"Mara"' "$server_log" || fail "the server never saw the game join"
grep -q '"errors":0,"event":"stop"' "$server_log" || fail "the server logged errors"
echo " game: joined, in the match for ${playing:-0} frames"
if [[ -n "$(ls -A "$HOME/data" 2>/dev/null | grep -v '^godot$')" ]]; then
fail "the package wrote outside the engine's user data: $(ls -A "$HOME/data")"
fi
if [[ "$status" -eq 0 ]]; then
echo "dist-check: ok ($name works outside the repository: smoke, a bot match, and its game playing on its server)"
fi
exit "$status"
+32 -8
View File
@@ -9,6 +9,8 @@
#
# tools/smoke.sh unthrottled, so it finishes in seconds
# SMOKE_REALTIME=1 tools/smoke.sh at the real 30 Hz tick rate (about 34 seconds)
# SMOKE_DIST=DIR tools/smoke.sh the same checks on an unpacked release package
# (R1): DIR/tidewall-server instead of the repo
set -uo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."
@@ -18,11 +20,21 @@ pace="--unthrottled"
[[ "${SMOKE_REALTIME:-0}" == "1" ]] && pace=""
status=0
code=0
dist="${SMOKE_DIST:-}"
if [[ -n "$dist" ]]; then
[[ -x "$dist/tidewall-server" ]] || { echo "smoke FAIL: no $dist/tidewall-server"; exit 2; }
dist_state="$(mktemp -d)"
trap 'rm -rf "$dist_state"' EXIT
fi
# run <args...>: runs the server, sets $output (JSON lines only) and $code.
run() {
local raw
raw="$(timeout --signal=KILL 300 tools/godot.sh -- --server "$@" 2>&1)"
if [[ -n "$dist" ]]; then
raw="$(TIDEWALL_STATE="$dist_state" timeout --signal=KILL 300 "$dist/tidewall-server" "$@" 2>&1)"
else
raw="$(timeout --signal=KILL 300 tools/godot.sh -- --server "$@" 2>&1)"
fi
code=$?
output="$(grep '^{' <<<"$raw")"
stderr_tail="$(grep -v '^{' <<<"$raw" | tail -n 15)"
@@ -52,7 +64,7 @@ seeded="$(grep -c "\"seed\":$seed[,}]" <<<"$output")"
[[ "$lines" -eq "$seeded" ]] || fail "only $seeded of $lines log lines carry the seed"
[[ "$(field stats ticks)" == "$ticks" ]] || fail "ran $(field stats ticks) ticks, expected $ticks"
hash="$(field stats state_hash)"
echo "smoke: $ticks ticks, 24 bots, seed $seed"
echo "smoke: $ticks ticks, 24 bots, seed $seed${dist:+, release package $dist}"
echo "smoke: tick us min $(field stats min_us) mean $(field stats mean_us) p50 $(field stats p50_us)" \
"p95 $(field stats p95_us) p99 $(field stats p99_us) max $(field stats max_us)," \
"$(field stats over_budget) over the $(field stats budget_us) us budget"
@@ -63,8 +75,14 @@ run --seed="$seed" --bots=24 --ticks="$ticks" --unthrottled
|| fail "a second run with the same seed gave a different state hash"
run --seed="$seed" --bots=2 --ticks=50 --unthrottled --fault=script-error
[[ "$code" -eq 1 ]] || fail "a script error exited $code, expected 1"
[[ "$(field stop errors)" -ge 1 ]] || fail "a script error wasn't counted in the stop line"
if [[ -n "$dist" ]]; then
# A release template has no script error checks: the call on null crashes the
# process (139) rather than being reported. Either way it must not exit 0.
[[ "$code" -ne 0 ]] || fail "a script error exited 0 in the release package"
else
[[ "$code" -eq 1 ]] || fail "a script error exited $code, expected 1"
[[ "$(field stop errors)" -ge 1 ]] || fail "a script error wasn't counted in the stop line"
fi
run --bots=99 --nonsense
[[ "$code" -eq 2 ]] || fail "a bad command line exited $code, expected 2"
@@ -79,9 +97,13 @@ run --listen --port="$port" --seed="$seed" --bots=4 --ticks=120 --unthrottled
# SIGTERM to the packaged wrapper becomes a clean stop: stats and stop lines, exit 0.
state="$(mktemp -d)"
TIDEWALL_ENGINE="$(pwd)/tools/godot/$(sed -n 's/^\([0-9a-f]*\) *tools\/godot\/\(.*_linux\.x86_64\)$/\2/p' tools/engine.sha512)" \
TIDEWALL_GAME="$(pwd)" TIDEWALL_STATE="$state" \
packaging/server/tidewall-server --seed="$seed" --bots=2 >"$state/log" 2>&1 &
if [[ -n "$dist" ]]; then
TIDEWALL_STATE="$state" "$dist/tidewall-server" --seed="$seed" --bots=2 >"$state/log" 2>&1 &
else
TIDEWALL_ENGINE="$(pwd)/tools/godot/$(sed -n 's/^\([0-9a-f]*\) *tools\/godot\/\(.*_linux\.x86_64\)$/\2/p' tools/engine.sha512)" \
TIDEWALL_GAME="$(pwd)" TIDEWALL_STATE="$state" \
packaging/server/tidewall-server --seed="$seed" --bots=2 >"$state/log" 2>&1 &
fi
wrapper=$!
for _ in $(seq 1 100); do
grep -q '"event":"start"' "$state/log" 2>/dev/null && break
@@ -97,6 +119,8 @@ grep -q '"event":"stats"' <<<"$output" || fail "SIGTERM left no stats line"
[[ "$(field stop exit_code)" == "0" ]] || fail "SIGTERM left no clean stop line"
if [[ "$status" -eq 0 ]]; then
echo "smoke: ok (clean run, reproducible hash, script error exits 1, bad config exits 2, listens, SIGTERM stops cleanly)"
fault_exit="1"
[[ -n "$dist" ]] && fault_exit="non-zero"
echo "smoke: ok (clean run, reproducible hash, script error exits $fault_exit, bad config exits 2, listens, SIGTERM stops cleanly)"
fi
exit "$status"