|
| 1 | +name: Build — Android & Windows |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [master, deploy] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + platform: |
| 9 | + description: 'Target platform' |
| 10 | + required: true |
| 11 | + default: 'Both' |
| 12 | + type: choice |
| 13 | + options: [Android, Windows, Both] |
| 14 | + |
| 15 | +env: |
| 16 | + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true |
| 17 | + |
| 18 | +jobs: |
| 19 | + # ──────────────────────────────────────────────────────────────────────────── |
| 20 | + plan: |
| 21 | + name: Plan |
| 22 | + runs-on: ubuntu-latest |
| 23 | + outputs: |
| 24 | + build_android: ${{ steps.flags.outputs.build_android }} |
| 25 | + build_windows: ${{ steps.flags.outputs.build_windows }} |
| 26 | + any_build: ${{ steps.flags.outputs.any_build }} |
| 27 | + |
| 28 | + steps: |
| 29 | + - name: Parse flags |
| 30 | + id: flags |
| 31 | + run: | |
| 32 | + MSG="${{ github.event.head_commit.message }}" |
| 33 | + TRIGGER="${{ github.event_name }}" |
| 34 | + SELECTED="${{ github.event.inputs.platform }}" |
| 35 | +
|
| 36 | + android=false; windows=false |
| 37 | +
|
| 38 | + if [ "$TRIGGER" = "workflow_dispatch" ]; then |
| 39 | + case "$SELECTED" in |
| 40 | + Android) android=true ;; |
| 41 | + Windows) windows=true ;; |
| 42 | + Both) android=true; windows=true ;; |
| 43 | + esac |
| 44 | + else |
| 45 | + # --build alone (word-boundary) triggers everything |
| 46 | + if echo "$MSG" | grep -qE '(^|[[:space:]])--build([[:space:]]|$)'; then |
| 47 | + android=true; windows=true |
| 48 | + fi |
| 49 | + echo "$MSG" | grep -qi -- '--build-android' && android=true |
| 50 | + echo "$MSG" | grep -qi -- '--build-windows' && windows=true |
| 51 | + fi |
| 52 | +
|
| 53 | + any=false |
| 54 | + { [ "$android" = "true" ] || [ "$windows" = "true" ]; } && any=true |
| 55 | +
|
| 56 | + echo "build_android=$android" >> $GITHUB_OUTPUT |
| 57 | + echo "build_windows=$windows" >> $GITHUB_OUTPUT |
| 58 | + echo "any_build=$any" >> $GITHUB_OUTPUT |
| 59 | +
|
| 60 | + echo "📋 Plan → Android: $android | Windows: $windows" |
| 61 | +
|
| 62 | + # ──────────────────────────────────────────────────────────────────────────── |
| 63 | + build: |
| 64 | + name: Build — ${{ matrix.targetPlatform }} |
| 65 | + runs-on: ubuntu-latest |
| 66 | + needs: plan |
| 67 | + if: needs.plan.outputs.any_build == 'true' |
| 68 | + |
| 69 | + strategy: |
| 70 | + fail-fast: false |
| 71 | + matrix: |
| 72 | + include: |
| 73 | + - targetPlatform: Android |
| 74 | + plan_key: build_android |
| 75 | + - targetPlatform: StandaloneWindows64 |
| 76 | + plan_key: build_windows |
| 77 | + |
| 78 | + steps: |
| 79 | + - name: Gate |
| 80 | + id: gate |
| 81 | + run: | |
| 82 | + case "${{ matrix.plan_key }}" in |
| 83 | + build_android) VAL="${{ needs.plan.outputs.build_android }}" ;; |
| 84 | + build_windows) VAL="${{ needs.plan.outputs.build_windows }}" ;; |
| 85 | + esac |
| 86 | + echo "should_build=$VAL" >> $GITHUB_OUTPUT |
| 87 | + [ "$VAL" = "true" ] \ |
| 88 | + && echo "✅ Building ${{ matrix.targetPlatform }}" \ |
| 89 | + || echo "⏭️ Skipping ${{ matrix.targetPlatform }}" |
| 90 | +
|
| 91 | + - name: Free Disk Space |
| 92 | + if: steps.gate.outputs.should_build == 'true' |
| 93 | + run: | |
| 94 | + sudo apt-get remove -y '^dotnet-.*' '^llvm-.*' 'php.*' '^mongodb-.*' \ |
| 95 | + '^mysql-.*' azure-cli google-chrome-stable firefox powershell \ |
| 96 | + mono-devel libgl1-mesa-dri || true |
| 97 | + sudo apt-get autoremove -y && sudo apt-get clean |
| 98 | + sudo rm -rf /usr/share/dotnet /usr/local/lib/android \ |
| 99 | + /opt/ghc /usr/local/share/boost "$AGENT_TOOLSDIRECTORY" |
| 100 | + docker system prune -a -f || true |
| 101 | + sudo swapoff -a || true && sudo rm -f /swapfile |
| 102 | + echo "📊 Disk after cleanup:"; df -h / |
| 103 | +
|
| 104 | + - name: Checkout |
| 105 | + if: steps.gate.outputs.should_build == 'true' |
| 106 | + uses: actions/checkout@v4 |
| 107 | + with: |
| 108 | + fetch-depth: 0 |
| 109 | + lfs: true |
| 110 | + |
| 111 | + - name: Cache Library |
| 112 | + if: steps.gate.outputs.should_build == 'true' |
| 113 | + uses: actions/cache@v4 |
| 114 | + with: |
| 115 | + path: PackageSandbox/Library |
| 116 | + key: Library-${{ matrix.targetPlatform }}-${{ hashFiles('PackageSandbox/Assets/**', 'PackageSandbox/Packages/**', 'PackageSandbox/ProjectSettings/**') }} |
| 117 | + restore-keys: | |
| 118 | + Library-${{ matrix.targetPlatform }}- |
| 119 | + Library- |
| 120 | +
|
| 121 | + - name: Build — ${{ matrix.targetPlatform }} |
| 122 | + if: steps.gate.outputs.should_build == 'true' |
| 123 | + uses: game-ci/unity-builder@v4 |
| 124 | + env: |
| 125 | + UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} |
| 126 | + UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} |
| 127 | + UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} |
| 128 | + with: |
| 129 | + # Point at PackageSandbox which is the actual Unity project |
| 130 | + projectPath: PackageSandbox |
| 131 | + targetPlatform: ${{ matrix.targetPlatform }} |
| 132 | + unityVersion: 2022.3.13f1 |
| 133 | + buildName: PackageSandbox |
| 134 | + customParameters: -disable-assembly-updater |
| 135 | + |
| 136 | + - name: Upload |
| 137 | + if: steps.gate.outputs.should_build == 'true' && success() |
| 138 | + uses: actions/upload-artifact@v4 |
| 139 | + with: |
| 140 | + name: PackageSandbox-${{ matrix.targetPlatform }}-${{ github.run_number }} |
| 141 | + path: build/${{ matrix.targetPlatform }} |
| 142 | + retention-days: 14 |
| 143 | + |
| 144 | + - name: Skipped |
| 145 | + if: steps.gate.outputs.should_build == 'false' |
| 146 | + run: echo "⏭️ ${{ matrix.targetPlatform }} not requested." |
| 147 | + |
| 148 | + # ──────────────────────────────────────────────────────────────────────────── |
| 149 | + no-build: |
| 150 | + name: No build requested |
| 151 | + runs-on: ubuntu-latest |
| 152 | + needs: plan |
| 153 | + if: needs.plan.outputs.any_build == 'false' |
| 154 | + steps: |
| 155 | + - run: | |
| 156 | + echo "ℹ️ No build requested." |
| 157 | + echo " Push with --build, --build-android, or --build-windows in commit message," |
| 158 | + echo " or trigger manually via Actions → Run workflow." |
0 commit comments