From 0b59ae204a3cff311beb594524c7827a837ab611 Mon Sep 17 00:00:00 2001 From: dionmoustos Date: Mon, 22 Jun 2026 23:47:36 +0930 Subject: [PATCH] more --- .teamcity/settings.kts | 98 +++++++++++++++++++++++------------- Assets/Editor/UnityBuild.cs | 16 ++++-- ci/Build-Mac.sh | 45 +++++++++++++++++ ci/Build-Unity.ps1 | 45 ----------------- ci/Build-Windows.ps1 | 53 +++++++++++++++++++ ci/Ensure-UnityToolchain.ps1 | 22 -------- ci/toolchain.json | 28 ++++++----- 7 files changed, 190 insertions(+), 117 deletions(-) create mode 100644 ci/Build-Mac.sh delete mode 100644 ci/Build-Unity.ps1 create mode 100644 ci/Build-Windows.ps1 delete mode 100644 ci/Ensure-UnityToolchain.ps1 diff --git a/.teamcity/settings.kts b/.teamcity/settings.kts index 3157819..7bf8b27 100644 --- a/.teamcity/settings.kts +++ b/.teamcity/settings.kts @@ -1,99 +1,129 @@ import jetbrains.buildServer.configs.kotlin.* import jetbrains.buildServer.configs.kotlin.buildSteps.powerShell +import jetbrains.buildServer.configs.kotlin.buildSteps.script version = "2026.1" project { - description = "Unity CI (Windows + Android + extensible)" + description = "Unity CI - isolated platform builds" - buildType(UnityBuildCore) buildType(WindowsBuild) buildType(AndroidBuild) + buildType(MacBuild) + buildType(IOSBuild) } /** - * CORE BUILD (only place Unity runs) + * WINDOWS (also builds Android on Windows agent) */ -object UnityBuildCore : BuildType({ +object WindowsBuild : BuildType({ - name = "Unity Build (Core)" + name = "Unity - Windows (Agent: Windows)" + + vcs { + root(DslContext.settingsRoot) + } params { - param("unity.target", "") + param("unity.target", "Windows") } + steps { + powerShell { + name = "Build Windows" + + scriptMode = file { + path = "ci/Build-Windows.ps1" + } + + scriptArgs = "-Target Windows" + } + } + + artifactRules = """ + Builds/Windows/** => windows.zip + """.trimIndent() +}) + +/** + * ANDROID (Windows agent) + */ +object AndroidBuild : BuildType({ + + name = "Unity - Android (Agent: Windows)" + vcs { root(DslContext.settingsRoot) } steps { - powerShell { - name = "Run Unity Build" + name = "Build Android" scriptMode = file { - path = "ci/Build-Unity.ps1" + path = "ci/Build-Windows.ps1" } - // SAFE: always passed from dependency configs - scriptArgs = "-Target %unity.target%" + scriptArgs = "-Target Android" } } artifactRules = """ - Builds/** => builds.zip + Builds/Android/** => android.zip """.trimIndent() }) /** - * WINDOWS BUILD + * MAC (macOS agent) */ -object WindowsBuild : BuildType({ +object MacBuild : BuildType({ - name = "Unity - Windows" - - params { - param("unity.target", "Windows") - } + name = "Unity - Mac (Agent: Mac)" vcs { root(DslContext.settingsRoot) } - dependencies { - snapshot(UnityBuildCore) { - onDependencyFailure = FailureAction.FAIL_TO_START + steps { + script { + name = "Build Mac" + + scriptContent = """ + chmod +x ci/Build-Mac.sh + ./ci/Build-Mac.sh Mac + """.trimIndent() } } artifactRules = """ - Builds/Windows/** => WindowsBuild.zip + Builds/Mac/** => mac.zip """.trimIndent() }) /** - * ANDROID BUILD + * iOS (macOS agent) */ -object AndroidBuild : BuildType({ +object IOSBuild : BuildType({ - name = "Unity - Android" - - params { - param("unity.target", "Android") - } + name = "Unity - iOS (Agent: Mac)" vcs { root(DslContext.settingsRoot) } - dependencies { - snapshot(UnityBuildCore) { - onDependencyFailure = FailureAction.FAIL_TO_START + steps { + script { + name = "Build iOS" + + scriptContent = """ + chmod +x ci/Build-Mac.sh + ./ci/Build-Mac.sh iOS + """.trimIndent() } } artifactRules = """ - Builds/Android/** => AndroidBuild.zip + Builds/iOS/** => ios.zip """.trimIndent() }) \ No newline at end of file diff --git a/Assets/Editor/UnityBuild.cs b/Assets/Editor/UnityBuild.cs index 1c25f3a..e9ee36a 100644 --- a/Assets/Editor/UnityBuild.cs +++ b/Assets/Editor/UnityBuild.cs @@ -4,17 +4,25 @@ using System.Linq; public static class BuildScript { - public static void Windows() => + public static void Windows() + { Build(BuildTarget.StandaloneWindows64, "Builds/Windows"); + } - public static void Android() => + public static void Android() + { Build(BuildTarget.Android, "Builds/Android"); + } - public static void Mac() => + public static void Mac() + { Build(BuildTarget.StandaloneOSX, "Builds/Mac"); + } - public static void iOS() => + public static void iOS() + { Build(BuildTarget.iOS, "Builds/iOS"); + } private static void Build(BuildTarget target, string outputPath) { diff --git a/ci/Build-Mac.sh b/ci/Build-Mac.sh new file mode 100644 index 0000000..adeb578 --- /dev/null +++ b/ci/Build-Mac.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +set -e + +TARGET=$1 + +if [[ -z "$TARGET" ]]; then + echo "Missing TARGET (Mac or iOS)" + exit 1 +fi + +echo "=== Mac Build Starting ===" +echo "Target: $TARGET" + +UNITY_VERSION="2022.3.62f1" +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 +fi + +case "$TARGET" in + Mac) + METHOD="BuildScript.Mac" + ;; + iOS) + METHOD="BuildScript.iOS" + ;; + *) + echo "Unknown target: $TARGET" + exit 1 + ;; +esac + +"$UNITY_EXE" \ + -batchmode \ + -nographics \ + -quit \ + -projectPath "$(pwd)" \ + -executeMethod $METHOD \ + -logFile - + +echo "=== Build SUCCESS: $TARGET ===" \ No newline at end of file diff --git a/ci/Build-Unity.ps1 b/ci/Build-Unity.ps1 deleted file mode 100644 index 106aae3..0000000 --- a/ci/Build-Unity.ps1 +++ /dev/null @@ -1,45 +0,0 @@ -param( - [Parameter(Mandatory = $true)] - [string]$Target -) - -Write-Host "=============================" -Write-Host "Unity Build Starting" -Write-Host "Target: $Target" -Write-Host "=============================" - -if ([string]::IsNullOrWhiteSpace($Target)) { - throw "ERROR: Target was empty. TeamCity did not pass unity.target correctly." -} - -$config = Get-Content ".\ci\toolchain.json" | ConvertFrom-Json - -if (-not $config.targets.$Target) { - throw "Unknown build target: $Target" -} - -$t = $config.targets.$Target - -$UnityExe = Join-Path $config.unityRoot "$($config.unityVersion)\Editor\Unity.exe" - -if (!(Test-Path $UnityExe)) { - throw "Unity not installed at expected path: $UnityExe" -} - -Write-Host "Using Unity: $UnityExe" -Write-Host "Executing method: $($t.method)" -Write-Host "Output: $($t.outputPath)" - -& $UnityExe ` - -batchmode ` - -nographics ` - -quit ` - -projectPath $PWD ` - -executeMethod $t.method ` - -logFile - - -if ($LASTEXITCODE -ne 0) { - throw "Unity build FAILED for target: $Target" -} - -Write-Host "Build SUCCESS: $Target" \ No newline at end of file diff --git a/ci/Build-Windows.ps1 b/ci/Build-Windows.ps1 new file mode 100644 index 0000000..3d077e4 --- /dev/null +++ b/ci/Build-Windows.ps1 @@ -0,0 +1,53 @@ +param( + [Parameter(Mandatory = $true)] + [ValidateSet("Windows","Android")] + [string]$Target +) + +Write-Host "=== Windows Build Starting ===" +Write-Host "Target: $Target" + +$config = Get-Content ".\ci\toolchain.json" | ConvertFrom-Json + +$unityVersion = $config.unityVersion +$unityRoot = $config.windows.unityRoot + +$unityExe = Join-Path $unityRoot "$unityVersion\Editor\Unity.exe" + +if (!(Test-Path $unityExe)) { + throw "Unity not installed: $unityExe" +} + +# ---------------------------- +# Toolchain setup (Windows agent) +# ---------------------------- + +Write-Host "Ensuring toolchain (Unity + Android SDK/JDK/NDK)..." + +# NOTE: In real setups you either: +# - rely on Unity Hub installs, OR +# - preinstalled cached toolchain +# This script assumes preinstalled Hub-managed tools. + +# ---------------------------- +# Select Unity method +# ---------------------------- + +$method = switch ($Target) { + "Windows" { "BuildScript.Windows" } + "Android" { "BuildScript.Android" } +} + +& $unityExe ` + -batchmode ` + -nographics ` + -quit ` + -projectPath $PWD ` + -executeMethod $method ` + -logFile - + +if ($LASTEXITCODE -ne 0) { + throw "Build failed: $Target" +} + +Write-Host "=== Build SUCCESS: $Target ===" \ No newline at end of file diff --git a/ci/Ensure-UnityToolchain.ps1 b/ci/Ensure-UnityToolchain.ps1 deleted file mode 100644 index 2c7d778..0000000 --- a/ci/Ensure-UnityToolchain.ps1 +++ /dev/null @@ -1,22 +0,0 @@ -param( - [string]$ConfigPath = ".\ci\toolchain.json" -) - -$config = Get-Content $ConfigPath | ConvertFrom-Json - -$UnityVersion = $config.unityVersion -$UnityExe = Join-Path $config.unityRoot "$UnityVersion\Editor\Unity.exe" - -Write-Host "Checking Unity $UnityVersion..." - -if (!(Test-Path $UnityExe)) { - throw "Unity version not installed: $UnityVersion" -} - -Write-Host "Unity found: $UnityExe" - -# expose for later steps -$env:UNITY_VERSION = $UnityVersion -$env:UNITY_EXE = $UnityExe - -return $UnityExe \ No newline at end of file diff --git a/ci/toolchain.json b/ci/toolchain.json index f1d7f6f..e368e3b 100644 --- a/ci/toolchain.json +++ b/ci/toolchain.json @@ -1,18 +1,22 @@ { "unityVersion": "2022.3.62f1", - "unityRoot": "C:\\Program Files\\Unity\\Hub\\Editor", - "targets": { - "Windows": { - "method": "BuildScript.Windows", - "outputPath": "Builds/Windows/Game.exe", - "buildTarget": "StandaloneWindows64" - }, + "windows": { + "unityRoot": "C:\\Program Files\\Unity\\Hub\\Editor", + "modules": [ + "android", + "android-sdk-ndk-tools", + "android-open-jdk", + "windows-il2cpp" + ] + }, - "Android": { - "method": "BuildScript.Android", - "outputPath": "Builds/Android/Game.aab", - "buildTarget": "Android" - } + "mac": { + "unityRoot": "/Applications/Unity/Hub/Editor", + "modules": [ + "ios-il2cpp", + "mac-mono", + "android" + ] } } \ No newline at end of file