tests.yaml 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. # Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. # Exceptions. See /LICENSE for license information.
  3. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. name: test
  5. on:
  6. push:
  7. branches: [trunk]
  8. pull_request_target:
  9. merge_group:
  10. # Cancel previous workflows on the PR when there are multiple fast commits.
  11. # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency
  12. concurrency:
  13. group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
  14. cancel-in-progress: true
  15. jobs:
  16. test:
  17. strategy:
  18. matrix:
  19. # At present, these images are newer than "latest". We use them to test
  20. # against more recent tooling versions.
  21. # https://github.com/actions/runner-images
  22. os: [ubuntu-22.04, macos-12]
  23. build_mode: [fastbuild, opt]
  24. runs-on: ${{ matrix.os }}
  25. steps:
  26. # Ubuntu images start with 23GB available, and this adds 14GB more. For
  27. # comparison, MacOS images have >100GB free.
  28. - name: Free up disk space (Ubuntu)
  29. if: matrix.os == 'ubuntu-22.04'
  30. uses: jlumbroso/free-disk-space@v1.2.0
  31. with:
  32. android: true
  33. dotnet: true
  34. haskell: true
  35. # Although we could delete more, if we run into a limit, it provides a
  36. # little flexibility to get space while trying to shrink the build.
  37. # There's also support for docker images at head (1.2.0 is still
  38. # the latest release).
  39. large-packages: false
  40. swap-storage: false
  41. # Checkout the pull request head or the branch.
  42. - name: Checkout pull request
  43. if: github.event_name == 'pull_request_target'
  44. uses: actions/checkout@v3
  45. with:
  46. ref: ${{ github.event.pull_request.head.sha }}
  47. - name: Checkout branch
  48. if: github.event_name != 'pull_request_target'
  49. uses: actions/checkout@v3
  50. # Tests should only run on applicable paths, but we still need to have an
  51. # action run for the merge queue. We filter steps based on the paths here,
  52. # and condition steps on the output.
  53. - id: filter
  54. uses: dorny/paths-filter@v2
  55. with:
  56. filters: |
  57. ignore:
  58. - '**/*.md'
  59. - 'LICENSE'
  60. - 'CODEOWNERS'
  61. - '.git*'
  62. # Setup Python and related tools.
  63. - uses: actions/setup-python@v4
  64. if: steps.filter.outputs.ignore == 'false'
  65. with:
  66. # Match the min version listed in docs/project/contribution_tools.md
  67. python-version: '3.9'
  68. # Use LLVM following:
  69. # https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md
  70. # Both 14 and 15 are candidates because GitHub is testing new images.
  71. - name: Setup LLVM and Clang (macOS)
  72. if: steps.filter.outputs.ignore == 'false' && matrix.os == 'macos-12'
  73. run: |
  74. LLVM_PATH="$(brew --prefix llvm@15)"
  75. if [[ ! -e "${LLVM_PATH}" ]]; then
  76. LLVM_PATH="$(brew --prefix llvm@14)"
  77. fi
  78. echo "Using ${LLVM_PATH}"
  79. echo "${LLVM_PATH}/bin" >> $GITHUB_PATH
  80. echo '*** ls "${LLVM_PATH}"'
  81. ls "${LLVM_PATH}"
  82. echo '*** ls "${LLVM_PATH}/bin"'
  83. ls "${LLVM_PATH}/bin"
  84. # Use LLVM following:
  85. # https://github.com/actions/runner-images/blob/main/images/linux/Ubuntu2204-Readme.md
  86. # Both 14 and 15 are candidates for forwards compatibility, although 15
  87. # isn't provided.
  88. - name: Setup LLVM and Clang (Ubuntu)
  89. if:
  90. steps.filter.outputs.ignore == 'false' && matrix.os == 'ubuntu-22.04'
  91. run: |
  92. LLVM_PATH="/usr/lib/llvm-15"
  93. if [[ ! -e "${LLVM_PATH}" ]]; then
  94. LLVM_PATH="/usr/lib/llvm-14"
  95. fi
  96. echo "Using ${LLVM_PATH}"
  97. echo "${LLVM_PATH}/bin" >> $GITHUB_PATH
  98. echo '*** ls "${LLVM_PATH}"'
  99. ls "${LLVM_PATH}"
  100. echo '*** ls "${LLVM_PATH}/bin"'
  101. ls "${LLVM_PATH}/bin"
  102. # Print the various tool paths and versions to help in debugging.
  103. - name: Print tool debugging info
  104. if: steps.filter.outputs.ignore == 'false'
  105. run: |
  106. echo '*** PATH'
  107. echo $PATH
  108. echo '*** bazelisk'
  109. which bazelisk
  110. bazelisk --version
  111. echo '*** python'
  112. which python
  113. python --version
  114. echo '*** clang'
  115. which clang
  116. clang --version
  117. echo '*** clang++'
  118. which clang++
  119. clang++ --version
  120. # Extract our access key for our build cache.
  121. - name: Extract access key
  122. if: steps.filter.outputs.ignore == 'false'
  123. env:
  124. GCP_BUILDS_SERVICE_ACCOUNT: ${{ secrets.GCP_BUILDS_SERVICE_ACCOUNT }}
  125. run: |
  126. echo "$GCP_BUILDS_SERVICE_ACCOUNT" \
  127. | base64 -d > $HOME/gcp-builds-service-account.json
  128. # We need to replace the `.` with a `_` for the build cache.
  129. - name: Setup LLVM and Clang (macOS)
  130. if: steps.filter.outputs.ignore == 'false' && matrix.os == 'macos-12'
  131. run: |
  132. echo "os_for_cache=macos-12" >> $GITHUB_ENV
  133. - name: Setup LLVM and Clang (Ubuntu)
  134. if:
  135. steps.filter.outputs.ignore == 'false' && matrix.os == 'ubuntu-22.04'
  136. run: |
  137. echo "os_for_cache=ubuntu-22_04" >> $GITHUB_ENV
  138. # Add our bazel configuration and print basic info to ease debugging.
  139. - name: Configure Bazel and print info
  140. if: steps.filter.outputs.ignore == 'false'
  141. env:
  142. # Add a cache version for changes that bazel won't otherwise detect,
  143. # like llvm version changes.
  144. CACHE_VERSION: 1
  145. run: |
  146. cat >user.bazelrc <<EOF
  147. # Enable remote cache for our CI.
  148. build --remote_cache=https://storage.googleapis.com/carbon-builds-github-v${CACHE_VERSION}-${{ env.os_for_cache }}
  149. build --google_credentials=$HOME/gcp-builds-service-account.json
  150. # Set an artificially high jobs count. This flag controls the number
  151. # of concurrency Bazel itself uses, which is essential for actions
  152. # that are internally blocked on for example downloading results form
  153. # the cache above. Without setting this high, Bazel will pick a small
  154. # number based on the available host CPUs and the reality will be a
  155. # long chain of largely serialized download events with little or no
  156. # usage of the host machine. Fortunately, local actions are
  157. # *separately* gated on `--local_*_resources` that will avoid a large
  158. # jobs value overwhelming the host. There is a bug to make downloads
  159. # behave completely asynchronously and remove the need for this filed
  160. # back in 2018 but work seemed to not finish:
  161. # https://github.com/bazelbuild/bazel/issues/6394
  162. #
  163. # There is a new effort (yay!) but until then it seems worth using the
  164. # workaround of a high jobs value. The biggest downside (increased
  165. # heap usage) seems like it isn't currently a big loss for our builds.
  166. build --jobs=200
  167. # General build options.
  168. build --verbose_failures
  169. test --test_output=errors
  170. EOF
  171. bazelisk info
  172. # Just for visibility, print space before and after the build.
  173. - name: Disk space before build
  174. if: steps.filter.outputs.ignore == 'false'
  175. run: df -h
  176. # Build all targets first to isolate build failures.
  177. - name: Build (${{ matrix.build_mode }})
  178. if: steps.filter.outputs.ignore == 'false'
  179. env:
  180. # 'libtool_check_unique failed to generate' workaround.
  181. # https://github.com/bazelbuild/bazel/issues/14113#issuecomment-999794586
  182. BAZEL_USE_CPP_ONLY_TOOLCHAIN: 1
  183. run: bazelisk build -c ${{ matrix.build_mode }} //...:all
  184. # Run all test targets.
  185. - name: Test (${{ matrix.build_mode }})
  186. if: steps.filter.outputs.ignore == 'false'
  187. env:
  188. # 'libtool_check_unique failed to generate' workaround.
  189. # https://github.com/bazelbuild/bazel/issues/14113#issuecomment-999794586
  190. BAZEL_USE_CPP_ONLY_TOOLCHAIN: 1
  191. run: bazelisk test -c ${{ matrix.build_mode }} //...:all
  192. # See "Disk space before build".
  193. - name: Disk space after build
  194. if: steps.filter.outputs.ignore == 'false'
  195. run: df -h