This commit is contained in:
2026-06-22 23:52:11 +09:30
parent 0b59ae204a
commit 04151399ee
2 changed files with 176 additions and 36 deletions
+92 -15
View File
@@ -1,26 +1,84 @@
#!/bin/bash
set -e
set -euo pipefail
TARGET=$1
TARGET="${1:-}"
if [[ -z "$TARGET" ]]; then
echo "Missing TARGET (Mac or iOS)"
echo "ERROR: Missing TARGET (Mac or iOS)"
exit 1
fi
echo "=== Mac Build Starting ==="
echo "Target: $TARGET"
echo "===================================="
echo " Unity CI Build (Mac Agent)"
echo " Target: $TARGET"
echo "===================================="
UNITY_VERSION="2022.3.62f1"
# -----------------------------
# 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_EXE="$UNITY_ROOT/$UNITY_VERSION/Unity.app/Contents/MacOS/Unity"
if [[ ! -f "$UNITY_EXE" ]]; then
echo "Unity not installed at $UNITY_EXE"
exit 1
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"
@@ -29,17 +87,36 @@ case "$TARGET" in
METHOD="BuildScript.iOS"
;;
*)
echo "Unknown target: $TARGET"
echo "ERROR: Unknown target: $TARGET"
exit 1
;;
esac
"$UNITY_EXE" \
echo "Using Unity method: $METHOD"
# -----------------------------
# Run Unity build
# -----------------------------
"$UNITY_APP" \
-batchmode \
-nographics \
-quit \
-projectPath "$(pwd)" \
-executeMethod $METHOD \
-logFile -
-executeMethod "$METHOD" \
-logFile "build-$TARGET.log"
echo "=== Build SUCCESS: $TARGET ==="
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 "===================================="