tests.yaml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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:
  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. - name: Create environment variables
  34. run: |
  35. echo "BAZEL_OUTPUT_BASE_PATH=$HOME/.cache/bazel-output-base" >> $GITHUB_ENV
  36. echo "BAZEL=bazelisk --output_base=$HOME/.cache/bazel-output-base" >> $GITHUB_ENV
  37. - name: Checkout
  38. uses: actions/checkout@v2
  39. with:
  40. submodules: true
  41. # Setup Python and related tools.
  42. - uses: actions/setup-python@v2
  43. with:
  44. # Match the min version listed in docs/project/contribution_tools.md
  45. python-version: '3.6'
  46. # On macOS we need Go and to use it to install Bazelisk.
  47. - uses: actions/setup-go@v2
  48. if: matrix.os == 'macos-latest'
  49. - name: Install bazelisk
  50. if: matrix.os == 'macos-latest'
  51. run: |
  52. go get github.com/bazelbuild/bazelisk
  53. echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
  54. # Print the various tool versions to help in debugging.
  55. - name: Print tool versions
  56. run: |
  57. bazelisk --version
  58. python --version
  59. # Make the date available to subsequent steps.
  60. - name: Get date
  61. id: date
  62. shell: bash
  63. run: |
  64. echo "::set-output name=date::$(/bin/date -u "+%Y%m%d")"
  65. # Preserve and restore the Bazel cache across builds.
  66. #
  67. # These cached entries are keyed on this file (which configures the
  68. # command and other inputs) as well as the date. Because Bazel is
  69. # hermetic, it doesn't matter if we get a "stale" entry here, but it makes
  70. # the cache less efficient. So we use the date to get a fresh baseline
  71. # cache once per day. We include this file so that changing the build
  72. # structure itself returns us to a clean state. We can also increment the
  73. # counter in this comment to forcibly rotate this hash in the event we get
  74. # a corrupted cache that breaks Bazel. This is a risk because we very
  75. # selectively prune directories out of the internals of the Bazel output
  76. # base to reduce the storage of the cache. At any point, this might break
  77. # invariants and require us to clear our caches. There is no way to
  78. # actually delete them and so instead we can simply bump the counter here.
  79. #
  80. # Current cache version: 2
  81. - name: Cache Bazel build data
  82. uses: actions/cache@v2
  83. with:
  84. # We exclude the install symlink so that Bazel reconnects to the
  85. # current installation. This helps repair any damage done by other
  86. # exclusions as well. Then we exclude the `external` tree because
  87. # those are all downloaded and rapidly rebuilt, so no benefit from
  88. # downloading them with the cached state.
  89. path: |
  90. ${{ env.BAZEL_OUTPUT_BASE_PATH }}
  91. !${{ env.BAZEL_OUTPUT_BASE_PATH }}/install
  92. !${{ env.BAZEL_OUTPUT_BASE_PATH }}/external
  93. key: |
  94. bazel-${{ matrix.os }}-${{ matrix.build_mode }}-${{ hashFiles('.github/workflows/tests.yaml')
  95. }}-${{ steps.date.outputs.date }}
  96. # When we get a cache miss, try finding the most recent previous day's
  97. # cache to start.
  98. restore-keys: |
  99. bazel-${{ matrix.os }}-${{ matrix.build_mode }}-${{ hashFiles('.github/workflows/tests.yaml')
  100. }}-
  101. # Print Bazel diagnostics to make debugging easier.
  102. - name: Print Bazel info
  103. run: |
  104. ${{ env.BAZEL }} info
  105. # Build all targets first to isolate build failures.
  106. - name: Build (${{ matrix.build_mode }})
  107. run: |
  108. ${{ env.BAZEL }} build -c ${{ matrix.build_mode }} --verbose_failures \
  109. --deleted_packages=migrate_cpp,migrate_cpp/cpp_refactoring \
  110. //...:all
  111. # Run all test targets.
  112. - name: Test (${{ matrix.build_mode }})
  113. run: |
  114. ${{ env.BAZEL }} test -c ${{ matrix.build_mode }} --test_output errors \
  115. --deleted_packages=migrate_cpp,migrate_cpp/cpp_refactoring \
  116. --verbose_failures //...:all
  117. # We manually shut down the Bazel server to make sure the cached files
  118. # don't interact with it.
  119. - name: Shutdown Bazel
  120. run: |
  121. ${{ env.BAZEL }} shutdown