Files

75 lines
2.5 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -euo pipefail
root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$root_dir"
GODOT_BIN="${GODOT_BIN:-/snap/bin/godot4}"
if [[ ! -x "$GODOT_BIN" ]]; then
GODOT_BIN="$(command -v godot4 || command -v godot || true)"
fi
if [[ -z "$GODOT_BIN" ]]; then
echo "visual check unavailable: set GODOT_BIN or install godot4/godot" >&2
exit 2
fi
"$root_dir/scripts/godot-import.sh"
mkdir -p artifacts
log_path="artifacts/visual-check.log"
initial_capture_path="artifacts/visual-check.png"
exit_capture_path="artifacts/visual-check-exit.png"
compact_capture_path="artifacts/visual-check-compact.png"
rm -f "$initial_capture_path" "$exit_capture_path" "$compact_capture_path"
: > "$log_path"
runner=()
if [[ -z "${DISPLAY:-}" ]]; then
if command -v xvfb-run >/dev/null 2>&1; then
runner=(xvfb-run --auto-servernum --server-args="-screen 0 1920x1080x24")
else
echo "visual check unavailable: DISPLAY is unset and xvfb-run is not installed" | tee "$log_path" >&2
exit 2
fi
fi
run_capture() {
local label="$1"
local capture_argument="$2"
shift 2
set +e
timeout --foreground 20s "${runner[@]}" "$GODOT_BIN" --path . "$@" -- --"$capture_argument" >>"$log_path" 2>&1
local status=$?
set -e
if (( status != 0 )); then
echo "visual check failed: $label capture Godot exited with status $status; see $log_path" >&2
exit "$status"
fi
}
run_capture "initial" "capture"
run_capture "exit" "capture-exit"
# This is a real 1280×720 window capture, not a unit-level HUD relayout call.
# The fixed window size makes the compact artboard and PNG reproducible under
# Xvfb as well as an interactive DISPLAY.
run_capture "compact" "visual-check-compact" --windowed --resolution 1280x720
# Godot's SCRIPT ERROR / Parse Error diagnostics are actionable application
# failures. Do not treat unrelated backend diagnostics (for example the
# expected xkbcommon Compose warnings emitted by some Snap/Xvfb setups) as an
# application failure.
if grep -Ev '^ERROR: [0-9]+ resources still in use at exit$' "$log_path" | grep -Eq 'SCRIPT ERROR|Parse Error|^ERROR:'; then
echo "visual check failed: Godot application error; see $log_path" >&2
exit 1
fi
measure_capture() {
local capture_path="$1"
if ! python3 "$root_dir/scripts/check-visual-capture.py" "$capture_path"; then
echo "visual check failed: invalid or unreadable capture $capture_path" >&2
exit 1
fi
}
measure_capture "$initial_capture_path"
measure_capture "$exit_capture_path"
measure_capture "$compact_capture_path"