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 #!/bin/bash
set -e set -euo pipefail
TARGET=$1 TARGET="${1:-}"
if [[ -z "$TARGET" ]]; then if [[ -z "$TARGET" ]]; then
echo "Missing TARGET (Mac or iOS)" echo "ERROR: Missing TARGET (Mac or iOS)"
exit 1 exit 1
fi fi
echo "=== Mac Build Starting ===" echo "===================================="
echo "Target: $TARGET" 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_ROOT="/Applications/Unity/Hub/Editor"
UNITY_EXE="$UNITY_ROOT/$UNITY_VERSION/Unity.app/Contents/MacOS/Unity"
if [[ ! -f "$UNITY_EXE" ]]; then UNITY_APP="$UNITY_ROOT/$UNITY_VERSION/Unity.app/Contents/MacOS/Unity"
echo "Unity not installed at $UNITY_EXE"
exit 1 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 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 case "$TARGET" in
Mac) Mac)
METHOD="BuildScript.Mac" METHOD="BuildScript.Mac"
@@ -29,17 +87,36 @@ case "$TARGET" in
METHOD="BuildScript.iOS" METHOD="BuildScript.iOS"
;; ;;
*) *)
echo "Unknown target: $TARGET" echo "ERROR: Unknown target: $TARGET"
exit 1 exit 1
;; ;;
esac esac
"$UNITY_EXE" \ echo "Using Unity method: $METHOD"
# -----------------------------
# Run Unity build
# -----------------------------
"$UNITY_APP" \
-batchmode \ -batchmode \
-nographics \ -nographics \
-quit \ -quit \
-projectPath "$(pwd)" \ -projectPath "$(pwd)" \
-executeMethod $METHOD \ -executeMethod "$METHOD" \
-logFile - -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 "===================================="
+84 -21
View File
@@ -4,50 +4,113 @@ param(
[string]$Target [string]$Target
) )
Write-Host "=== Windows Build Starting ===" $ErrorActionPreference = "Stop"
Write-Host "Target: $Target"
Write-Host "===================================="
Write-Host " Unity CI Build (Windows Agent)"
Write-Host " Target: $Target"
Write-Host "===================================="
# -----------------------------
# Load toolchain config
# -----------------------------
$config = Get-Content ".\ci\toolchain.json" | ConvertFrom-Json $config = Get-Content ".\ci\toolchain.json" | ConvertFrom-Json
$unityVersion = $config.unityVersion $unityVersion = $config.unityVersion
$unityRoot = $config.windows.unityRoot $unityRoot = $config.windows.unityRoot
$unityExe = Join-Path $unityRoot "$unityVersion\Editor\Unity.exe" $hubExe = "${env:ProgramFiles}\Unity Hub\Unity Hub.exe"
if (!(Test-Path $unityExe)) { if (!(Test-Path $hubExe)) {
throw "Unity not installed: $unityExe" throw "Unity Hub not found at: $hubExe"
} }
# ---------------------------- # -----------------------------
# Toolchain setup (Windows agent) # Ensure Unity is installed
# ---------------------------- # -----------------------------
$unityEditorPath = Join-Path $unityRoot "$unityVersion\Editor\Unity.exe"
Write-Host "Ensuring toolchain (Unity + Android SDK/JDK/NDK)..." if (!(Test-Path $unityEditorPath)) {
# NOTE: In real setups you either: Write-Host "Unity $unityVersion not found. Installing via Unity Hub..."
# - rely on Unity Hub installs, OR
# - preinstalled cached toolchain
# This script assumes preinstalled Hub-managed tools.
# ---------------------------- # Install Unity Editor
# Select Unity method & $hubExe -- --headless install `
# ---------------------------- --version $unityVersion `
--changeset "" 2>$null
if ($LASTEXITCODE -ne 0) {
throw "Failed to install Unity $unityVersion"
}
}
Write-Host "Unity found: $unityEditorPath"
# -----------------------------
# Ensure required modules
# -----------------------------
# NOTE:
# Unity Hub CLI installs modules per version.
# These are cached per editor version, not reinstalled each build.
$modules = $config.windows.modules
Write-Host "Ensuring Unity modules: $($modules -join ', ')"
foreach ($module in $modules) {
Write-Host "Checking module: $module"
# Check installed modules via Unity Hub
$installed = & $hubExe -- --headless editors --installed
if ($installed -notmatch "$unityVersion.*$module") {
Write-Host "Installing module: $module"
& $hubExe -- --headless install-modules `
--version $unityVersion `
--module $module
if ($LASTEXITCODE -ne 0) {
throw "Failed to install module: $module"
}
}
else {
Write-Host "Module already installed: $module"
}
}
# -----------------------------
# Resolve Unity build method
# -----------------------------
$method = switch ($Target) { $method = switch ($Target) {
"Windows" { "BuildScript.Windows" } "Windows" { "BuildScript.Windows" }
"Android" { "BuildScript.Android" } "Android" { "BuildScript.Android" }
} }
& $unityExe ` Write-Host "Using Unity method: $method"
# -----------------------------
# Run Unity build
# -----------------------------
& $unityEditorPath `
-batchmode ` -batchmode `
-nographics ` -nographics `
-quit ` -quit `
-projectPath $PWD ` -projectPath $PWD `
-executeMethod $method ` -executeMethod $method `
-logFile - -logFile build-$Target.log
if ($LASTEXITCODE -ne 0) { $exitCode = $LASTEXITCODE
throw "Build failed: $Target"
# -----------------------------
# Validate result
# -----------------------------
if ($exitCode -ne 0) {
throw "Unity build failed ($Target). Exit code: $exitCode"
} }
Write-Host "=== Build SUCCESS: $Target ===" Write-Host "===================================="
Write-Host " BUILD SUCCESS: $Target"
Write-Host "===================================="