linux-build.yml 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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: Linux 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. desktop:
  33. required: false
  34. type: boolean
  35. run-name: ${{ inputs.platform }} - ${{ inputs.type }}
  36. # Note: All 3P Github Actions use the commit hash for security reasons
  37. # Avoid using the tag version, which is vulnerable to supply chain attacks
  38. jobs:
  39. Build:
  40. strategy:
  41. fail-fast: false
  42. runs-on: ${{ inputs.image }}
  43. steps:
  44. - name: Maximize build space
  45. # Resize and combine disks as LVM in order to maximize the amount of space for builds
  46. uses: easimon/maximize-build-space@fc881a613ad2a34aca9c9624518214ebc21dfc0c # v10
  47. with:
  48. root-reserve-mb: 8000
  49. swap-size-mb: 200
  50. remove-dotnet: true
  51. remove-haskell: true
  52. remove-codeql: true
  53. remove-docker-images: true
  54. - name: Checkout repo
  55. uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
  56. with:
  57. show-progress: false
  58. - name: Git LFS pull
  59. # Minimal pull for profile builds, otherwise pull all
  60. run: |
  61. git lfs install
  62. [[ "${{ inputs.type }}" == "profile" ]] && git lfs pull --include "*.ico,*.bmp" || git lfs pull
  63. - name: Setup 3p, user, and build folders
  64. run: |
  65. mkdir -p .o3de build 3rdParty && ln -sf "$(pwd)/.o3de" ~/.o3de
  66. - name: Setup ccache
  67. uses: Chocobo1/setup-ccache-action@f84f86840109403e0fe0ded8b0766c9633affa16 # v1.4.7
  68. continue-on-error: true
  69. if: always()
  70. with:
  71. prepend_symlinks_to_path: false
  72. store_cache: false
  73. restore_cache: false
  74. ccache_options: |
  75. max_size=10G
  76. hash_dir=false
  77. cache_dir=${{ github.workspace }}/.ccache
  78. - name: Check for rerun
  79. id: check-rerun
  80. run: |
  81. # GitHub sets GITHUB_RUN_ATTEMPT to track reruns
  82. if [ "$GITHUB_RUN_ATTEMPT" -gt 1 ]; then
  83. echo "is_rerun=true" >> $GITHUB_OUTPUT
  84. echo "This is rerun attempt #$GITHUB_RUN_ATTEMPT"
  85. else
  86. echo "is_rerun=false" >> $GITHUB_OUTPUT
  87. echo "This is the first run attempt"
  88. fi
  89. - name: Get last run
  90. # Get the last runid of the target branch of a PR or the current branch
  91. # Skip if this is a rerun to either freshly build or get artifacts from existing run
  92. uses: dawidd6/action-download-artifact@07ab29fd4a977ae4d2b275087cf67563dfdf0295 # v9
  93. id: last-run-id
  94. if: ${{ inputs.last_artifact && steps.check-rerun.outputs.is_rerun != 'true' }}
  95. continue-on-error: true
  96. with:
  97. workflow_search: true
  98. workflow_conclusion: ""
  99. branch: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref || github.ref_name }}
  100. search_artifacts: true
  101. check_artifacts: true
  102. name: O3DE-${{ inputs.platform }}-${{ inputs.config }}-build
  103. dry_run: true
  104. - name: Set artifact run ID
  105. # Set the run ID of the artifact to be used for the download step
  106. id: set-artifact-run-id
  107. if: steps.last-run-id.outcome == 'success' && inputs.last_artifact == true
  108. run: |
  109. runId=${{ fromJSON(steps.last-run-id.outputs.artifacts)[0].workflow_run.id }}
  110. echo "artifact_run_id=$runId" >> $GITHUB_OUTPUT
  111. echo "Using artifacts from previous run: $runId"
  112. - name: Restore artifact cache
  113. # Restore the artifact from the "Get last run" step or from the current run
  114. id: restore-artifact-cache
  115. uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
  116. continue-on-error: true
  117. with:
  118. name: O3DE-${{ inputs.platform }}-${{ inputs.config }}-build
  119. github-token: ${{ secrets.GITHUB_TOKEN }}
  120. run-id: ${{ steps.set-artifact-run-id.outputs.artifact_run_id || github.run_id }}
  121. - name: Extract artifact
  122. # Extract the tar file from the artifact
  123. id: extract-artifact
  124. continue-on-error: true
  125. if: ${{ steps.restore-artifact-cache.outcome == 'success' }}
  126. run: |
  127. if [ -f ${{ github.workspace }}/cache.tar ]; then
  128. tar -xvpf ${{ github.workspace }}/cache.tar --ignore-failed-read
  129. rm ${{ github.workspace }}/cache.tar
  130. ccache --zero-stats --cleanup
  131. fi
  132. - name: Setup cmake
  133. # Pin the version of cmake
  134. uses: lukka/get-cmake@56d043d188c3612951d8755da8f4b709ec951ad6 # v3.31.6
  135. with:
  136. cmakeVersion: "~3.30.0"
  137. - name: Configure environment
  138. # Install dependencies. The desktop packages are for tests and assetprocessor
  139. continue-on-error: true
  140. run: |
  141. echo "Installing dependencies"
  142. pushd ./scripts/build/build_node/Platform/Linux
  143. sudo ./install-ubuntu.sh
  144. popd
  145. echo "Getting python..."
  146. ./python/get_python.sh
  147. echo "Installing additional python dependencies..."
  148. ./python/pip.sh install tempfile2 PyGithub
  149. # If desktop is true, install desktop and x11 packages, otherwise install base packages
  150. [[ "${{ inputs.desktop }}" == "true" ]] && \
  151. sudo apt-get install -qq ubuntu-desktop libreoffice- thunderbird- xorg mesa-utils vulkan-tools libevdev-dev libevdev2 -y || \
  152. sudo apt-get install -qq libevdev-dev libevdev2 -y
  153. sudo apt -y autoremove --purge
  154. sudo apt -y autoclean
  155. sudo apt clean
  156. df -h
  157. - name: Build ${{ inputs.type }}
  158. # Builds with presets in ../scripts/build/Platform/Linux/build_config.json
  159. timeout-minutes: 330
  160. run: |
  161. export LY_3RDPARTY_PATH=${{ github.workspace }}/3rdParty
  162. export LY_PACKAGE_SERVER_URLS="https://d1gg6ket0m44ly.cloudfront.net;https://d3t6xeg4fgfoum.cloudfront.net"
  163. export CC=${{ inputs.compiler == 'gcc' && 'gcc' || 'clang' }}
  164. export CXX=${{ inputs.compiler == 'gcc' && 'g++' || 'clang++' }}
  165. export CMAKE_C_COMPILER_LAUNCHER=ccache
  166. export CMAKE_CXX_COMPILER_LAUNCHER=ccache
  167. export DISPLAY=:0
  168. export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
  169. if [ "${{ inputs.desktop }}" == "true" ]; then
  170. Xvfb :0 -screen 0 1400x1050x16 & # Start X virtual framebuffer for tests
  171. fi
  172. python/python.sh -u scripts/build/ci_build.py --platform ${{ inputs.platform }} --type ${{ inputs.type }}
  173. - name: Compress artifacts
  174. # Compress with posix format to preserve permissions and timestamps at nanosecond precision
  175. # Skip compression and upload if the type is a test to reduce dirty build artifacts from previous runs
  176. id: compress-artifacts
  177. if: ${{ (steps.extract-artifact.outcome == 'success' || steps.extract-artifact.outcome == 'skipped') && !cancelled() && !contains(inputs.type, 'test') }}
  178. continue-on-error: true
  179. run: |
  180. tar --format=posix -cvpf ${{ github.workspace }}/cache.tar --ignore-failed-read \
  181. .ccache \
  182. .o3de/python/downloaded_packages \
  183. 3rdParty/downloaded_packages \
  184. AutomatedTesting/Cache
  185. - name: Save artifacts
  186. uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
  187. if: ${{ steps.compress-artifacts.conclusion == 'success' && !cancelled() && !contains(inputs.type, 'test') }}
  188. continue-on-error: true
  189. with:
  190. name: O3DE-${{ inputs.platform }}-${{ inputs.config }}-build
  191. compression-level: 1
  192. overwrite: true
  193. path: |
  194. ${{ github.workspace }}/cache.tar