tests.yaml 5.8 KB

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