windows-build.yml 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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: Windows 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. # Note: All 3P Github Actions use the commit hash for security reasons
  38. # Avoid using the tag version, which is vulnerable to supply chain attacks
  39. jobs:
  40. Build:
  41. strategy:
  42. fail-fast: false
  43. runs-on: ${{ inputs.image }}
  44. steps:
  45. - name: Checkout repo
  46. uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
  47. with:
  48. show-progress: false
  49. - name: Git LFS pull
  50. # Minimal pull for profile builds, otherwise pull all
  51. run: |
  52. git lfs install
  53. if ("${{ inputs.type }}" -eq "profile") { git lfs pull --include "*.ico,*.bmp" } else { git lfs pull }
  54. - name: Setup DevDrive
  55. uses: samypr100/setup-dev-drive@b9079d2711b01ed39de859c79c96484bfd80e078 # v3.4.1
  56. with:
  57. drive-size: 130GB
  58. drive-format: NTFS
  59. drive-path: "D:/dev_drive.vhdx"
  60. workspace-copy: true
  61. trusted-dev-drive: true
  62. - name: Setup 3p, user, and build folders
  63. # Symlink the .o3de folder to the github workspace to avoid permission issues
  64. run: |
  65. "3rdParty", "build", ".o3de" | % {New-Item "${{ env.DEV_DRIVE_WORKSPACE }}\$_" -ItemType 'Directory' -Force}
  66. "temp" | % {New-Item "${{ env.DEV_DRIVE }}\$_" -ItemType 'Directory' -Force}
  67. ".o3de" | % {New-Item -Path $env:USERPROFILE\$_ -ItemType SymbolicLink -Target ${{ env.DEV_DRIVE_WORKSPACE }}\$_ -Force}
  68. "AutomatedTesting\Cache", "AutomatedTesting\user" | % {New-Item "${{ env.DEV_DRIVE_WORKSPACE }}\$_" -ItemType 'Directory' -Force}
  69. - name: Move Page File to Workspace drive
  70. # Configure the page file to the workspace drive for the duration of the run
  71. run: |
  72. Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" `
  73. -Name "PagingFiles" -Value "${{ env.DEV_DRIVE }}\temp\pagefile.sys 8192 8192"
  74. echo "Page file moved to ${{ env.DEV_DRIVE }}\temp\pagefile.sys"
  75. - name: Get drive info
  76. run: |
  77. Get-PSDrive
  78. - name: Setup ccache
  79. uses: Chocobo1/setup-ccache-action@f84f86840109403e0fe0ded8b0766c9633affa16 # v1.4.7
  80. continue-on-error: true
  81. if: always()
  82. with:
  83. windows_compile_environment: msvc
  84. prepend_symlinks_to_path: false
  85. store_cache: false
  86. restore_cache: false
  87. ccache_options: |
  88. max_size=10G
  89. inode_cache=true
  90. hash_dir=false
  91. temporary_dir=${{ env.DEV_DRIVE }}\temp
  92. cache_dir=${{ env.DEV_DRIVE_WORKSPACE }}\.ccache
  93. - name: Check for rerun
  94. id: check-rerun
  95. run: |
  96. # GitHub sets GITHUB_RUN_ATTEMPT to track reruns
  97. if ($env:GITHUB_RUN_ATTEMPT -gt 1) {
  98. echo "is_rerun=true" >> $env:GITHUB_OUTPUT
  99. echo "This is rerun attempt #$env:GITHUB_RUN_ATTEMPT"
  100. } else {
  101. echo "is_rerun=false" >> $env:GITHUB_OUTPUT
  102. echo "This is the first run attempt"
  103. }
  104. - name: Get last run
  105. # Get the last runid of the target branch of a PR or the current branch
  106. # Skip if this is a rerun to either freshly build or get artifacts from existing run
  107. uses: dawidd6/action-download-artifact@07ab29fd4a977ae4d2b275087cf67563dfdf0295 # v9
  108. id: last-run-id
  109. if: ${{ inputs.last_artifact && steps.check-rerun.outputs.is_rerun != 'true' }}
  110. continue-on-error: true
  111. with:
  112. workflow_search: true
  113. workflow_conclusion: ""
  114. branch: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || github.ref_name }}
  115. search_artifacts: true
  116. check_artifacts: true
  117. name: O3DE-${{ inputs.platform }}-${{ inputs.config }}-build
  118. dry_run: true
  119. - name: Set artifact run ID
  120. # Set the run ID of the artifact to be used for the download step
  121. id: set-artifact-run-id
  122. if: steps.last-run-id.outcome == 'success' && inputs.last_artifact == true
  123. run: |
  124. $runId = ${{ fromJSON(steps.last-run-id.outputs.artifacts)[0].workflow_run.id }}
  125. echo "artifact_run_id=$runId" >> $env:GITHUB_OUTPUT
  126. echo "Using artifacts from previous run: $runId"
  127. - name: Restore artifact cache
  128. # Restore the artifact from the "Get last run" step or from the current run
  129. uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
  130. id: restore-artifact-cache
  131. continue-on-error: true
  132. with:
  133. name: O3DE-${{ inputs.platform }}-${{ inputs.config }}-build
  134. github-token: ${{ secrets.GITHUB_TOKEN }}
  135. path: ${{ env.DEV_DRIVE_WORKSPACE }}
  136. run-id: ${{ steps.set-artifact-run-id.outputs.artifact_run_id || github.run_id }}
  137. - name: Extract artifact
  138. # Extract the tar file from the artifact
  139. id: extract-artifact
  140. continue-on-error: true
  141. if: ${{ steps.restore-artifact-cache.outcome == 'success' }}
  142. working-directory: ${{ env.DEV_DRIVE_WORKSPACE }}
  143. run: |
  144. if (Test-Path ${{ env.DEV_DRIVE_WORKSPACE }}\cache.tar) {
  145. tar -xvpf ${{ env.DEV_DRIVE_WORKSPACE }}\cache.tar
  146. rm ${{ env.DEV_DRIVE_WORKSPACE }}\cache.tar
  147. ${{ env.O3DE_COMPILER_CACHE_PATH }} --zero-stats --cleanup
  148. }
  149. - name: Setup cmake
  150. # Pin the version of cmake
  151. uses: lukka/get-cmake@56d043d188c3612951d8755da8f4b709ec951ad6 # v3.31.6
  152. with:
  153. cmakeVersion: "~3.30.0"
  154. - name: Set MSBuild options
  155. # Configuire VS environment variables through the developer command prompt for MSVC
  156. uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0
  157. - name: Configure environment
  158. working-directory: ${{ env.DEV_DRIVE_WORKSPACE }}
  159. run: |
  160. echo "Installing dependencies"
  161. echo "Getting python..."
  162. python\get_python.bat
  163. echo "Installing additional python dependencies..."
  164. python\pip.sh install tempfile2 PyGithub
  165. - name: Build ${{ inputs.type }}
  166. # Builds with presets in ../scripts/build/Platform/Windows/build_config.json
  167. # Set temp folders to the workspace drive as the boot drive is slow
  168. working-directory: "${{ env.DEV_DRIVE_WORKSPACE }}"
  169. timeout-minutes: 330
  170. run: |
  171. $env:LY_3RDPARTY_PATH = "${{ env.DEV_DRIVE_WORKSPACE }}\3rdParty"
  172. $env:TEMP = "${{ env.DEV_DRIVE }}\temp"
  173. $env:TMP = "${{ env.DEV_DRIVE }}\temp"
  174. python\python.cmd -u scripts\build\ci_build.py --platform ${{ inputs.platform }} --type ${{ inputs.type }}
  175. - name: Compress artifacts
  176. # Compress with posix format to preserve permissions and timestamps at nanosecond precision
  177. # Skip compression and upload if the type is a test to reduce dirty build artifacts from previous runs
  178. id: compress-artifacts
  179. if: ${{ (steps.extract-artifact.outcome == 'success' || steps.extract-artifact.outcome == 'skipped') && !cancelled() && !contains(inputs.type, 'test') }}
  180. continue-on-error: true
  181. working-directory: ${{ env.DEV_DRIVE_WORKSPACE }}
  182. run: |
  183. try {
  184. tar --format=posix -cvpf ${{ env.DEV_DRIVE_WORKSPACE }}\cache.tar `
  185. .ccache `
  186. .o3de\python\downloaded_packages `
  187. 3rdParty\downloaded_packages `
  188. AutomatedTesting\Cache
  189. } catch {
  190. echo "Warning: Error during tar compression"
  191. }
  192. - name: Save artifacts
  193. uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
  194. if: ${{ steps.compress-artifacts.conclusion == 'success' && !cancelled() && !contains(inputs.type, 'test') }}
  195. continue-on-error: true
  196. with:
  197. name: O3DE-${{ inputs.platform }}-${{ inputs.config }}-build
  198. compression-level: 1
  199. overwrite: true
  200. path: |
  201. ${{ env.DEV_DRIVE_WORKSPACE }}\cache.tar