magicciv/scripts/run/build-info.sh

41 lines
1.6 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# Regenerates src/game/build_info.json from the current git state.
# Invoke before an export so the About screen shows the correct commit.
#
# Available two ways:
# * Directly: `./scripts/run/build-info.sh`
# * Via runner: `./run build:info` (calls cmd_build_info below)
#
# Previously this file was top-level executable code — sourcing it via
# the runner's `for _script in scripts/run/*.sh; source "$_script"` loop
# regenerated build_info.json on EVERY `./run <anything>` invocation,
# including quick ones like `./run lint:gd`. Wrapping in a function makes
# the write lazy: only runs when explicitly called by a build/export cmd.
# Regenerate src/game/build_info.json. Idempotent, side-effect-free at source time.
cmd_build_info() {
local repo_root="${REPO_ROOT:-$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)}"
local commit build_date version_base version
commit="$(git -C "$repo_root" rev-parse --short=12 HEAD 2>/dev/null || echo unknown)"
build_date="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
version_base="$(awk -F'"' '/^config\/version=/ {print $2}' "$repo_root/src/game/project.godot" 2>/dev/null || echo 0.0.0)"
version="${version_base}-ea"
cat > "$repo_root/src/game/build_info.json" <<EOF
{
"version": "$version",
"commit": "$commit",
"build_date": "$build_date",
"godot_rust": "0.2"
}
EOF
echo "Wrote build_info.json: $version @ $commit"
}
# Keep the direct-invocation path working (`./scripts/run/build-info.sh`).
# BASH_SOURCE[0] == $0 exactly when the file is executed, not sourced.
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
set -euo pipefail
cmd_build_info
fi