122 lines
2.7 KiB
Bash
122 lines
2.7 KiB
Bash
#!/bin/bash
|
|
|
|
set -euo pipefail
|
|
|
|
TARGET="${1:-}"
|
|
|
|
if [[ -z "$TARGET" ]]; then
|
|
echo "ERROR: Missing TARGET (Mac or iOS)"
|
|
exit 1
|
|
fi
|
|
|
|
echo "===================================="
|
|
echo " Unity CI Build (Mac Agent)"
|
|
echo " Target: $TARGET"
|
|
echo "===================================="
|
|
|
|
# -----------------------------
|
|
# Load toolchain config
|
|
# -----------------------------
|
|
CONFIG_FILE="./ci/toolchain.json"
|
|
|
|
UNITY_VERSION=$(cat "$CONFIG_FILE" | python3 -c "import sys, json; print(json.load(sys.stdin)['unityVersion'])")
|
|
UNITY_ROOT="/Applications/Unity/Hub/Editor"
|
|
|
|
UNITY_APP="$UNITY_ROOT/$UNITY_VERSION/Unity.app/Contents/MacOS/Unity"
|
|
|
|
HUB="/Applications/Unity Hub.app/Contents/MacOS/Unity Hub"
|
|
|
|
# -----------------------------
|
|
# Ensure Unity exists
|
|
# -----------------------------
|
|
if [[ ! -f "$UNITY_APP" ]]; then
|
|
echo "Unity $UNITY_VERSION not found. Installing via Unity Hub..."
|
|
|
|
"$HUB" -- --headless install \
|
|
--version "$UNITY_VERSION"
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
echo "ERROR: Failed to install Unity $UNITY_VERSION"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
echo "Unity found at: $UNITY_APP"
|
|
|
|
# -----------------------------
|
|
# Ensure required modules
|
|
# -----------------------------
|
|
echo "Ensuring Unity modules..."
|
|
|
|
MODULES=$(cat "$CONFIG_FILE" | python3 -c "
|
|
import sys, json
|
|
print(' '.join(json.load(sys.stdin)['mac']['modules']))
|
|
")
|
|
|
|
for module in $MODULES; do
|
|
|
|
echo "Checking module: $module"
|
|
|
|
INSTALLED=$("$HUB" -- --headless editors --installed || true)
|
|
|
|
if echo "$INSTALLED" | grep -q "$UNITY_VERSION.*$module"; then
|
|
echo "Module already installed: $module"
|
|
else
|
|
echo "Installing module: $module"
|
|
|
|
"$HUB" -- --headless install-modules \
|
|
--version "$UNITY_VERSION" \
|
|
--module "$module"
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
echo "ERROR: Failed to install module $module"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
done
|
|
|
|
# -----------------------------
|
|
# Resolve Unity build method
|
|
# -----------------------------
|
|
case "$TARGET" in
|
|
Mac)
|
|
METHOD="BuildScript.Mac"
|
|
;;
|
|
iOS)
|
|
METHOD="BuildScript.iOS"
|
|
;;
|
|
*)
|
|
echo "ERROR: Unknown target: $TARGET"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
echo "Using Unity method: $METHOD"
|
|
|
|
# -----------------------------
|
|
# Run Unity build
|
|
# -----------------------------
|
|
"$UNITY_APP" \
|
|
-batchmode \
|
|
-nographics \
|
|
-quit \
|
|
-projectPath "$(pwd)" \
|
|
-executeMethod "$METHOD" \
|
|
-logFile "build-$TARGET.log"
|
|
|
|
EXIT_CODE=$?
|
|
|
|
# -----------------------------
|
|
# Validate result
|
|
# -----------------------------
|
|
if [[ $EXIT_CODE -ne 0 ]]; then
|
|
echo "===================================="
|
|
echo " BUILD FAILED: $TARGET"
|
|
echo "===================================="
|
|
exit $EXIT_CODE
|
|
fi
|
|
|
|
echo "===================================="
|
|
echo " BUILD SUCCESS: $TARGET"
|
|
echo "====================================" |