tests.yaml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. jobs:
  26. test:
  27. strategy:
  28. matrix:
  29. os: [ubuntu-latest, macos-latest]
  30. build_mode: [fastbuild, opt]
  31. runs-on: ${{ matrix.os }}
  32. steps:
  33. # Checkout the pull request head or the branch.
  34. - name: Checkout pull request
  35. if: github.event_name == 'pull_request_target'
  36. uses: actions/checkout@v3
  37. with:
  38. ref: ${{ github.event.pull_request.head.sha }}
  39. - name: Checkout branch
  40. if: github.event_name != 'pull_request_target'
  41. uses: actions/checkout@v3
  42. # Setup Python and related tools.
  43. - uses: actions/setup-python@v4
  44. with:
  45. # Match the min version listed in docs/project/contribution_tools.md
  46. python-version: '3.9'
  47. # On macOS we need Go and to use it to install Bazelisk.
  48. - uses: actions/setup-go@v3
  49. if: matrix.os == 'macos-latest'
  50. - name: Install bazelisk
  51. if: matrix.os == 'macos-latest'
  52. run: |
  53. go get github.com/bazelbuild/bazelisk
  54. echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
  55. # On macOS, use Homebrew to install a recent LLVM and Clang.
  56. - name: Setup LLVM and Clang (macOS)
  57. if: matrix.os == 'macos-latest'
  58. env:
  59. HOMEBREW_NO_INSTALL_CLEANUP: 1
  60. HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1
  61. run: |
  62. echo '*** Updating brew'
  63. brew update
  64. echo '*** Installing LLVM deps'
  65. brew install --force-bottle --only-dependencies llvm
  66. echo '*** Installing LLVM itself'
  67. brew install --force-bottle --force --verbose llvm
  68. echo '*** brew info llvm'
  69. brew info llvm
  70. echo '*** brew config'
  71. brew config
  72. echo '*** Updating PATH'
  73. echo "$(brew --prefix llvm)/bin" >> $GITHUB_PATH
  74. # On Ubuntu, use apt.llvm.org to install a recent LLVM and Clang.
  75. - name: Setup LLVM and Clang (Ubuntu)
  76. if: matrix.os == 'ubuntu-latest'
  77. run: |
  78. wget https://apt.llvm.org/llvm.sh
  79. chmod +x llvm.sh
  80. sudo ./llvm.sh 15 all
  81. rm llvm.sh
  82. echo "/usr/lib/llvm-15/bin" >> $GITHUB_PATH
  83. # Print the various tool paths and versions to help in debugging.
  84. - name: Print tool debugging info
  85. run: |
  86. echo '*** PATH'
  87. echo $PATH
  88. echo '*** bazelisk'
  89. which bazelisk
  90. bazelisk --version
  91. echo '*** python'
  92. which python
  93. python --version
  94. echo '*** clang'
  95. which clang
  96. clang --version
  97. echo '*** clang++'
  98. which clang++
  99. clang++ --version
  100. # Extract our access key for our build cache.
  101. - name: Extract access key
  102. env:
  103. GCP_BUILDS_SERVICE_ACCOUNT: ${{ secrets.GCP_BUILDS_SERVICE_ACCOUNT }}
  104. run: |
  105. echo "$GCP_BUILDS_SERVICE_ACCOUNT" \
  106. | base64 -d > $HOME/gcp-builds-service-account.json
  107. # Add our bazel configuration and print basic info to ease debugging.
  108. - name: Configure Bazel and print info
  109. env:
  110. # Add a cache version for changes that bazel won't otherwise detect,
  111. # like llvm version changes.
  112. CACHE_VERSION: 1
  113. run: |
  114. cat >user.bazelrc <<EOF
  115. # Enable remote cache for our CI.
  116. build --remote_cache=https://storage.googleapis.com/carbon-builds-github-v${CACHE_VERSION}-${{ matrix.os }}
  117. build --google_credentials=$HOME/gcp-builds-service-account.json
  118. # General build options.
  119. build --verbose_failures
  120. test --test_output=errors
  121. EOF
  122. bazelisk info
  123. # Build all targets first to isolate build failures.
  124. - name: Build (${{ matrix.build_mode }})
  125. env:
  126. # 'libtool_check_unique failed to generate' workaround.
  127. # https://github.com/bazelbuild/bazel/issues/14113#issuecomment-999794586
  128. BAZEL_USE_CPP_ONLY_TOOLCHAIN: 1
  129. run: bazelisk build -c ${{ matrix.build_mode }} //...:all
  130. # Run all test targets.
  131. - name: Test (${{ matrix.build_mode }})
  132. env:
  133. # 'libtool_check_unique failed to generate' workaround.
  134. # https://github.com/bazelbuild/bazel/issues/14113#issuecomment-999794586
  135. BAZEL_USE_CPP_ONLY_TOOLCHAIN: 1
  136. run: bazelisk test -c ${{ matrix.build_mode }} //...:all