Files
horizon-airdef/tools/ci/vanilla-data.sh
T
Ludovic Marie 989f843b1c vanilla-data.sh: keep everything horizon-prepare writes per preparer version, beside the shared data
The first parity run kept only .local/horizon-client per preparer version; the exporters' outputs beside it
stayed in the checkout, and the dedicated server, which finds registries.json at
<resources>/../../datagen, didn't find it next to the prepared folder (world_spawn failed).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-14 22:17:20 +02:00

71 lines
3.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# The vanilla data for this checkout on the self-hosted runner. Horizon never downloads the game: the runner
# holds the maintainer's own copy, imported and decompiled once (HORIZON_SHARED_SOURCE, default
# ~/code/horizon-parity/shared-local). It is cloned once into the runner's work folder ($RUNNER_WORKSPACE/
# shared-local; APFS clones, so no second copy of the bytes), and .local/ links to it as in a parity worktree.
# .local/horizon-client and the exporter outputs beside it, what horizon-prepare makes, are prepared by this
# checkout's own preparer once per preparer version (its sources, the exporters and research-lock.json), so a
# change to the preparer is checked with what it prepares; the four newest preparations are kept.
set -euo pipefail
shared="${RUNNER_WORKSPACE:?}/shared-local"
source="${HORIZON_SHARED_SOURCE:-$HOME/code/horizon-parity/shared-local}"
version=$(sed -n 's/.*"version": *"\([^"]*\)".*/\1/p' research-lock.json | head -1)
if [ ! -f "$shared/minecraft/$version/prepared.json" ]; then
[ -f "$source/minecraft/$version/prepared.json" ] || { echo "::error::no imported Minecraft $version in $source"; exit 1; }
mkdir -p "$shared"
if [ "$(uname)" = Darwin ]; then
for entry in "$source"/*; do
[ "$(basename "$entry")" = horizon-client ] || cp -cR "$entry" "$shared/"
done
else
for entry in "$source"/*; do
[ "$(basename "$entry")" = horizon-client ] || cp -R --reflink=auto "$entry" "$shared/"
done
fi
fi
mkdir -p .local "$shared/prepared"
for entry in "$shared"/*; do
name=$(basename "$entry")
case "$name" in prepared|*.log) continue ;; esac
if [ -L ".local/$name" ] || [ ! -e ".local/$name" ]; then ln -sfn "$entry" ".local/$name"; fi
done
key=$(git ls-files -s crates/horizon-prepare mods/horizon/src/test/java research-lock.json | shasum -a 256 | cut -c1-16)
prepared="$shared/prepared/$key"
# horizon-prepare writes .local/horizon-client and its exporters' outputs beside it: all of them live in
# $prepared, listed in $prepared/.entries, and .local/ links to them.
if [ ! -f "$prepared/.entries" ]; then
echo "Preparing resources with this checkout's horizon-prepare ($key)"
rm -rf "$prepared" && mkdir -p "$prepared"
# Links to another preparation's outputs go first, so what this one writes shows up as new entries.
for entry in .local/*; do
if [ -L "$entry" ] && [[ "$(readlink "$entry")" == "$shared/prepared/"* ]]; then rm "$entry"; fi
done
before=$(ls -1A .local | LC_ALL=C sort)
started=$SECONDS
cargo build --release --locked -p horizon-prepare
if ! target/release/horizon-prepare --root "$PWD" > "$RUNNER_TEMP/prepare.log" 2>&1; then
tail -40 "$RUNNER_TEMP/prepare.log"
rm -rf "$prepared"
exit 1
fi
LC_ALL=C comm -13 <(echo "$before") <(ls -1A .local | LC_ALL=C sort) > "$RUNNER_TEMP/prepared-entries"
while read -r name; do mv ".local/$name" "$prepared/$name"; done < "$RUNNER_TEMP/prepared-entries"
mv "$RUNNER_TEMP/prepared-entries" "$prepared/.entries"
echo "Prepared in $((SECONDS - started)) s: $(tr '\n' ' ' < "$prepared/.entries")"
fi
# The game finds some data relative to its resources (<resources>/../../datagen): beside the prepared folders,
# the same neighbours as in the shared folder.
for entry in "$shared"/*; do
name=$(basename "$entry")
case "$name" in prepared|*.log) continue ;; esac
[ -e "$prepared/$name" ] || ln -sfn "$entry" "$prepared/$name"
done
while read -r name; do
if [ -L ".local/$name" ] || [ ! -e ".local/$name" ]; then ln -sfn "$prepared/$name" ".local/$name"; else
echo "::error::.local/$name is not a link to the prepared resources"; exit 1; fi
done < "$prepared/.entries"
touch "$prepared"
# The four newest preparations stay.
ls -1dt "$shared/prepared"/*/ 2>/dev/null | tail -n +5 | while read -r old; do rm -rf "$old"; done