android-build.yml 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. name: Android Build
  9. # These jobs are to be triggered by ar.yml
  10. on:
  11. workflow_dispatch:
  12. workflow_call:
  13. inputs:
  14. compiler:
  15. required: true
  16. type: string
  17. config:
  18. required: true
  19. type: string
  20. image:
  21. required: true
  22. type: string
  23. platform:
  24. required: true
  25. type: string
  26. type:
  27. required: true
  28. type: string
  29. last_artifact:
  30. required: false
  31. type: boolean
  32. run-name: ${{ inputs.platform }} - ${{ inputs.type }}
  33. # Activate compiler cache
  34. env:
  35. O3DE_ENABLE_COMPILER_CACHE: true
  36. O3DE_COMPILER_CACHE_PATH: 'C:\ProgramData\Chocolatey\bin\ccache.exe'
  37. NDK_VERSION: 25.1.8937393
  38. # Note: All 3P Github Actions use the commit hash for security reasons
  39. # Avoid using the tag version, which is vulnerable to supply chain attacks
  40. jobs:
  41. Build:
  42. strategy:
  43. fail-fast: false
  44. runs-on: ${{ inputs.image }}
  45. steps:
  46. - name: Checkout repo
  47. uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
  48. with:
  49. show-progress: false
  50. - name: Git LFS pull
  51. # Minimal pull for profile builds, otherwise pull all
  52. run: |
  53. git lfs install
  54. if ("${{ inputs.type }}" -eq "profile") { git lfs pull --include "*.ico,*.bmp" } else { git lfs pull }
  55. - name: Setup DevDrive
  56. uses: samypr100/setup-dev-drive@b9079d2711b01ed39de859c79c96484bfd80e078 # v3.4.1
  57. with:
  58. drive-size: 130GB
  59. drive-format: NTFS
  60. drive-path: "D:/dev_drive.vhdx"
  61. workspace-copy: true
  62. trusted-dev-drive: true
  63. - name: Setup 3p, user, and build folders
  64. # Symlink the .o3de folder to the github workspace to avoid permission issues
  65. run: |
  66. "3rdParty", "build", ".o3de" | % {New-Item "${{ env.DEV_DRIVE_WORKSPACE }}\$_" -ItemType 'Directory' -Force}
  67. "temp" | % {New-Item "${{ env.DEV_DRIVE }}\$_" -ItemType 'Directory' -Force}
  68. ".o3de" | % {New-Item -Path $env:USERPROFILE\$_ -ItemType SymbolicLink -Target ${{ env.DEV_DRIVE_WORKSPACE }}\$_ -Force}
  69. "AutomatedTesting\Cache", "AutomatedTesting\user" | % {New-Item "${{ env.DEV_DRIVE_WORKSPACE }}\$_" -ItemType 'Directory' -Force}
  70. - name: Move Page File to Workspace drive
  71. # Configure the page file to the workspace drive for the duration of the run
  72. run: |
  73. Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" `
  74. -Name "PagingFiles" -Value "${{ env.DEV_DRIVE }}\temp\pagefile.sys 8192 8192"
  75. echo "Page file moved to ${{ env.DEV_DRIVE }}\temp\pagefile.sys"
  76. - name: Get drive info
  77. run: |
  78. Get-PSDrive
  79. - name: Setup ccache
  80. uses: Chocobo1/setup-ccache-action@f84f86840109403e0fe0ded8b0766c9633affa16 # v1.4.7
  81. continue-on-error: true
  82. if: always()
  83. with:
  84. windows_compile_environment: msvc
  85. prepend_symlinks_to_path: false
  86. store_cache: false
  87. restore_cache: false
  88. ccache_options: |
  89. max_size=10G
  90. inode_cache=true
  91. hash_dir=false
  92. temporary_dir=${{ env.DEV_DRIVE }}\temp
  93. cache_dir=${{ env.DEV_DRIVE_WORKSPACE }}\.ccache
  94. - name: Check for rerun
  95. id: check-rerun
  96. run: |
  97. # GitHub sets GITHUB_RUN_ATTEMPT to track reruns
  98. if ($env:GITHUB_RUN_ATTEMPT -gt 1) {
  99. echo "is_rerun=true" >> $env:GITHUB_OUTPUT
  100. echo "This is rerun attempt #$env:GITHUB_RUN_ATTEMPT"
  101. } else {
  102. echo "is_rerun=false" >> $env:GITHUB_OUTPUT
  103. echo "This is the first run attempt"
  104. }
  105. - name: Get last run
  106. # Get the last runid of the target branch of a PR or the current branch
  107. # Skip if this is a rerun to either freshly build or get artifacts from existing run
  108. uses: dawidd6/action-download-artifact@07ab29fd4a977ae4d2b275087cf67563dfdf0295 # v9
  109. id: last-run-id
  110. if: ${{ inputs.last_artifact && steps.check-rerun.outputs.is_rerun != 'true' }}
  111. continue-on-error: true
  112. with:
  113. workflow_search: true
  114. workflow_conclusion: ""
  115. branch: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || github.ref_name }}
  116. search_artifacts: true
  117. check_artifacts: true
  118. name: O3DE-${{ inputs.platform }}-${{ inputs.config }}-build
  119. dry_run: true
  120. - name: Set artifact run ID
  121. # Set the run ID of the artifact to be used for the download step
  122. id: set-artifact-run-id
  123. if: steps.last-run-id.outcome == 'success' && inputs.last_artifact == true
  124. run: |
  125. $runId = ${{ fromJSON(steps.last-run-id.outputs.artifacts)[0].workflow_run.id }}
  126. echo "artifact_run_id=$runId" >> $env:GITHUB_OUTPUT
  127. echo "Using artifacts from previous run: $runId"
  128. - name: Restore artifact cache
  129. # Restore the artifact from the "Get last run" step or from the current run
  130. uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
  131. id: restore-artifact-cache
  132. continue-on-error: true
  133. with:
  134. name: O3DE-${{ inputs.platform }}-${{ inputs.config }}-build
  135. github-token: ${{ secrets.GITHUB_TOKEN }}
  136. path: ${{ env.DEV_DRIVE_WORKSPACE }}
  137. run-id: ${{ steps.set-artifact-run-id.outputs.artifact_run_id || github.run_id }}
  138. - name: Extract artifact
  139. # Extract the tar file from the artifact
  140. id: extract-artifact
  141. continue-on-error: true
  142. if: ${{ steps.restore-artifact-cache.outcome == 'success' }}
  143. working-directory: ${{ env.DEV_DRIVE_WORKSPACE }}
  144. run: |
  145. if (Test-Path ${{ env.DEV_DRIVE_WORKSPACE }}\cache.tar) {
  146. tar -xvpf ${{ env.DEV_DRIVE_WORKSPACE }}\cache.tar
  147. rm ${{ env.DEV_DRIVE_WORKSPACE }}\cache.tar
  148. ${{ env.O3DE_COMPILER_CACHE_PATH }} --zero-stats --cleanup
  149. }
  150. - name: Setup cmake
  151. # Pin the version of cmake
  152. uses: lukka/get-cmake@56d043d188c3612951d8755da8f4b709ec951ad6 # v3.31.6
  153. with:
  154. cmakeVersion: "~3.30.0"
  155. - name: Set MSBuild options
  156. # Configuire VS environment variables through the developer command prompt for MSVC
  157. uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0
  158. - name: Configure environment
  159. # Install dependencies for gradle and clang builds from the NDK
  160. continue-on-error: true
  161. working-directory: ${{ env.DEV_DRIVE_WORKSPACE }}
  162. run: |
  163. echo "Installing dependencies"
  164. echo "Getting python..."
  165. python\get_python.bat
  166. echo "Installing NDK ${{ env.NDK_VERSION }}..."
  167. & "$env:ANDROID_HOME\cmdline-tools\latest\bin\sdkmanager.bat" --install 'ndk;${{ env.NDK_VERSION }}' --sdk_root=$env:ANDROID_HOME
  168. echo "Accepting Android SDK licenses..."
  169. "y`ny" | & "$env:ANDROID_HOME\cmdline-tools\latest\bin\sdkmanager.bat" --licenses --sdk_root=$env:ANDROID_HOME
  170. echo "LY_NDK_DIR=$env:ANDROID_HOME\ndk\${{ env.NDK_VERSION }}" >> $env:GITHUB_ENV
  171. echo "JDK_HOME=$env:JAVA_HOME_17_X64" >> $env:GITHUB_ENV
  172. echo "JAVA_HOME=$env:JAVA_HOME_17_X64" >> $env:GITHUB_ENV
  173. echo "GRADLE_BUILD_HOME=$env:GRADLE_HOME" >> $env:GITHUB_ENV
  174. - name: Build ${{ inputs.type }}
  175. # Builds with presets in ../scripts/build/Platform/Android/build_config.json
  176. # Set temp folders to the workspace drive as the boot drive is slow
  177. working-directory: ${{ env.DEV_DRIVE_WORKSPACE }}
  178. timeout-minutes: 330
  179. run: |
  180. $env:LY_3RDPARTY_PATH = "${{ env.DEV_DRIVE_WORKSPACE }}\3rdParty"
  181. $env:LY_PACKAGE_SERVER_URLS = "https://d1gg6ket0m44ly.cloudfront.net;https://d3t6xeg4fgfoum.cloudfront.net"
  182. $env:TEMP = "${{ env.DEV_DRIVE }}\temp"
  183. $env:TMP = "${{ env.DEV_DRIVE }}\temp"
  184. scripts\o3de.bat register --this-engine # Resolves registration issue with gradle build
  185. python\python.cmd -u scripts\build\ci_build.py --platform ${{ inputs.platform }} --type ${{ inputs.type }}
  186. - name: Compress artifacts
  187. # Compress with posix format to preserve permissions and timestamps at nanosecond precision
  188. # Skip compression and upload if the type is a test to reduce dirty build artifacts from previous runs
  189. id: compress-artifacts
  190. if: ${{ (steps.extract-artifact.outcome == 'success' || steps.extract-artifact.outcome == 'skipped') && !cancelled() && !contains(inputs.type, 'test') }}
  191. continue-on-error: true
  192. working-directory: ${{ env.DEV_DRIVE_WORKSPACE }}
  193. run: |
  194. try {
  195. tar --format=posix -cvpf ${{ env.DEV_DRIVE_WORKSPACE }}\cache.tar `
  196. .ccache `
  197. .o3de\python\downloaded_packages `
  198. 3rdParty\downloaded_packages `
  199. AutomatedTesting\Cache
  200. } catch {
  201. echo "Warning: Error during tar compression"
  202. }
  203. - name: Save artifacts
  204. uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
  205. if: ${{ steps.compress-artifacts.conclusion == 'success' && !cancelled() && !contains(inputs.type, 'test') }}
  206. continue-on-error: true
  207. with:
  208. name: O3DE-${{ inputs.platform }}-${{ inputs.config }}-build
  209. compression-level: 1
  210. overwrite: true
  211. path: |
  212. ${{ env.DEV_DRIVE_WORKSPACE }}\cache.tar