Files
Emberwild/tools/export.sh

68 lines
3.2 KiB
Bash
Executable File

#!/bin/sh
# Builds the packaged game (export_presets.cfg) into build/:
#
# tools/export.sh # macOS and Windows
# tools/export.sh macOS # just one ("macOS" or "Windows")
#
# build/Emberwild-<version>-macos.zip the .app (universal: Apple silicon + Intel),
# ad-hoc signed, not notarised
# build/Emberwild-<version>-windows.zip Emberwild.exe + Emberwild.pck (+ a console
# wrapper), unsigned
#
# Needs the Godot export templates for this Godot's version (Editor > Manage
# Export Templates, or the .tpz from the Godot release page).
cd "$(dirname "$0")/.." || exit 1
. tools/godot_env.sh
VERSION=$(sed -n 's/^config\/version="\(.*\)"/\1/p' project.godot | head -1)
PROTOCOL=$(sed -n 's/^const PROTOCOL := \([0-9]*\).*/\1/p' scripts/net/net.gd | head -1)
# The packages' own version numbers must say the same as the game's.
for v in $(grep -E '^application/(short_version|version|file_version|product_version)=' export_presets.cfg | sed 's/.*="\(.*\)"/\1/'); do
if [ "$v" != "$VERSION" ]; then
echo "export_presets.cfg says $v but project.godot's config/version is $VERSION: make them match"; exit 1
fi
done
which=${1:-all}
mkdir -p build
"$GODOT" --headless --path . --import >/dev/null 2>&1
if [ "$which" = all ] || [ "$which" = macOS ]; then
rm -rf build/macos && mkdir -p build/macos
"$GODOT" --headless --path . --export-release "macOS" build/macos/Emberwild.zip > build/export-macos.log 2>&1
if [ -f build/macos/Emberwild.zip ]; then
mv build/macos/Emberwild.zip "build/Emberwild-$VERSION-macos.zip"
echo "built build/Emberwild-$VERSION-macos.zip"
else
echo "macOS export failed: see build/export-macos.log"; exit 1
fi
fi
if [ "$which" = all ] || [ "$which" = Windows ]; then
rm -rf build/windows && mkdir -p build/windows/Emberwild
"$GODOT" --headless --path . --export-release "Windows" build/windows/Emberwild/Emberwild.exe > build/export-windows.log 2>&1
if [ -f build/windows/Emberwild/Emberwild.exe ]; then
(cd build/windows && rm -f "../Emberwild-$VERSION-windows.zip" && zip -qr "../Emberwild-$VERSION-windows.zip" Emberwild)
echo "built build/Emberwild-$VERSION-windows.zip"
else
echo "Windows export failed: see build/export-windows.log"; exit 1
fi
fi
# build/version.json, for the release (scripts/core/updates.gd reads it):
# upload it with the zips. NOTES="..." tools/export.sh adds a line of notes.
python3 - "$VERSION" "$PROTOCOL" "${NOTES:-}" <<'EOF'
import hashlib, json, os, sys, datetime
version, protocol, notes = sys.argv[1], int(sys.argv[2]), sys.argv[3]
out = {"version": version, "protocol": protocol, "date": datetime.date.today().isoformat(), "downloads": {}}
if notes:
out["notes"] = notes
for plat in ("macos", "windows"):
f = "build/Emberwild-%s-%s.zip" % (version, plat)
if os.path.exists(f):
h = hashlib.sha256(open(f, "rb").read()).hexdigest()
out["downloads"][plat] = {"file": os.path.basename(f), "sha256": h, "size": os.path.getsize(f)}
json.dump(out, open("build/version.json", "w"), indent="\t")
print("wrote build/version.json (%s, protocol %d: %s)" % (version, protocol, ", ".join(out["downloads"]) or "no packages"))
EOF