tests.yaml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. paths:
  9. # Conservatively run the tests. However, skip them if the only paths in
  10. # the pull request match files that we know don't impact the build.
  11. - '**'
  12. - '!**/*.md'
  13. - '!LICENSE'
  14. - '!CODEOWNERS'
  15. - '!.git*'
  16. pull_request_target:
  17. paths:
  18. # Conservatively run the tests. However, skip them if the only paths in
  19. # the pull request match files that we know don't impact the build.
  20. - '**'
  21. - '!**/*.md'
  22. - '!LICENSE'
  23. - '!CODEOWNERS'
  24. - '!.git*'
  25. merge_group:
  26. paths:
  27. # Conservatively run the tests. However, skip them if the only paths in
  28. # the pull request match files that we know don't impact the build.
  29. - '**'
  30. - '!**/*.md'
  31. - '!LICENSE'
  32. - '!CODEOWNERS'
  33. - '!.git*'
  34. # Cancel previous workflows on the PR when there are multiple fast commits.
  35. # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency
  36. concurrency:
  37. group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
  38. cancel-in-progress: true
  39. jobs:
  40. test:
  41. strategy:
  42. matrix:
  43. # At present, these images are newer than "latest". We use them to test
  44. # against more recent tooling versions.
  45. # https://github.com/actions/runner-images
  46. os: [ubuntu-22.04, macos-12]
  47. build_mode: [fastbuild, opt]
  48. runs-on: ${{ matrix.os }}
  49. steps:
  50. # Checkout the pull request head or the branch.
  51. - name: Checkout pull request
  52. if: github.event_name == 'pull_request_target'
  53. uses: actions/checkout@v3
  54. with:
  55. ref: ${{ github.event.pull_request.head.sha }}
  56. - name: Checkout branch
  57. if: github.event_name != 'pull_request_target'
  58. uses: actions/checkout@v3
  59. # Setup Python and related tools.
  60. - uses: actions/setup-python@v4
  61. with:
  62. # Match the min version listed in docs/project/contribution_tools.md
  63. python-version: '3.9'
  64. # Use LLVM following:
  65. # https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md
  66. # Both 14 and 15 are candidates because GitHub is testing new images.
  67. - name: Setup LLVM and Clang (macOS)
  68. if: matrix.os == 'macos-12'
  69. run: |
  70. LLVM_PATH="$(brew --prefix llvm@15)"
  71. if [[ ! -e "${LLVM_PATH}" ]]; then
  72. LLVM_PATH="$(brew --prefix llvm@14)"
  73. fi
  74. echo "Using ${LLVM_PATH}"
  75. echo "${LLVM_PATH}/bin" >> $GITHUB_PATH
  76. echo '*** ls "${LLVM_PATH}"'
  77. ls "${LLVM_PATH}"
  78. echo '*** ls "${LLVM_PATH}/bin"'
  79. ls "${LLVM_PATH}/bin"
  80. # Use LLVM following:
  81. # https://github.com/actions/runner-images/blob/main/images/linux/Ubuntu2204-Readme.md
  82. # Both 14 and 15 are candidates for forwards compatibility, although 15
  83. # isn't provided.
  84. - name: Setup LLVM and Clang (Linux)
  85. if: matrix.os == 'ubuntu-22.04'
  86. run: |
  87. LLVM_PATH="/usr/lib/llvm-15"
  88. if [[ ! -e "${LLVM_PATH}" ]]; then
  89. LLVM_PATH="/usr/lib/llvm-14"
  90. fi
  91. echo "Using ${LLVM_PATH}"
  92. echo "${LLVM_PATH}/bin" >> $GITHUB_PATH
  93. echo '*** ls "${LLVM_PATH}"'
  94. ls "${LLVM_PATH}"
  95. echo '*** ls "${LLVM_PATH}/bin"'
  96. ls "${LLVM_PATH}/bin"
  97. # Print the various tool paths and versions to help in debugging.
  98. - name: Print tool debugging info
  99. run: |
  100. echo '*** PATH'
  101. echo $PATH
  102. echo '*** bazelisk'
  103. which bazelisk
  104. bazelisk --version
  105. echo '*** python'
  106. which python
  107. python --version
  108. echo '*** clang'
  109. which clang
  110. clang --version
  111. echo '*** clang++'
  112. which clang++
  113. clang++ --version
  114. # Extract our access key for our build cache.
  115. - name: Extract access key
  116. env:
  117. GCP_BUILDS_SERVICE_ACCOUNT: ${{ secrets.GCP_BUILDS_SERVICE_ACCOUNT }}
  118. run: |
  119. echo "$GCP_BUILDS_SERVICE_ACCOUNT" \
  120. | base64 -d > $HOME/gcp-builds-service-account.json
  121. # We need to replace the `.` with a `_` for the build cache.
  122. - name: Setup LLVM and Clang (macOS)
  123. if: matrix.os == 'macos-12'
  124. run: |
  125. echo "os_for_cache=macos-12" >> $GITHUB_ENV
  126. - name: Setup LLVM and Clang (Linux)
  127. if: matrix.os == 'ubuntu-22.04'
  128. run: |
  129. echo "os_for_cache=ubuntu-22_04" >> $GITHUB_ENV
  130. # Add our bazel configuration and print basic info to ease debugging.
  131. - name: Configure Bazel and print info
  132. env:
  133. # Add a cache version for changes that bazel won't otherwise detect,
  134. # like llvm version changes.
  135. CACHE_VERSION: 1
  136. run: |
  137. cat >user.bazelrc <<EOF
  138. # Enable remote cache for our CI.
  139. build --remote_cache=https://storage.googleapis.com/carbon-builds-github-v${CACHE_VERSION}-${{ env.os_for_cache }}
  140. build --google_credentials=$HOME/gcp-builds-service-account.json
  141. # General build options.
  142. build --verbose_failures
  143. test --test_output=errors
  144. EOF
  145. bazelisk info
  146. # Build all targets first to isolate build failures.
  147. - name: Build (${{ matrix.build_mode }})
  148. env:
  149. # 'libtool_check_unique failed to generate' workaround.
  150. # https://github.com/bazelbuild/bazel/issues/14113#issuecomment-999794586
  151. BAZEL_USE_CPP_ONLY_TOOLCHAIN: 1
  152. run: bazelisk build -c ${{ matrix.build_mode }} //...:all
  153. # Run all test targets.
  154. - name: Test (${{ matrix.build_mode }})
  155. env:
  156. # 'libtool_check_unique failed to generate' workaround.
  157. # https://github.com/bazelbuild/bazel/issues/14113#issuecomment-999794586
  158. BAZEL_USE_CPP_ONLY_TOOLCHAIN: 1
  159. run: bazelisk test -c ${{ matrix.build_mode }} //...:all