tests.yaml 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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: Tests
  5. on:
  6. push:
  7. branches: [trunk, action-test]
  8. pull_request:
  9. merge_group:
  10. permissions:
  11. contents: read # For actions/checkout.
  12. pull-requests: read # For dorny/paths-filter to read pull requests.
  13. # Cancel previous workflows on the PR when there are multiple fast commits.
  14. # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#concurrency
  15. concurrency:
  16. group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
  17. cancel-in-progress: true
  18. jobs:
  19. test:
  20. strategy:
  21. matrix:
  22. # Test a recent version of each supported OS.
  23. runner: ['ubuntu-22.04', 'macos-14']
  24. build_mode: [fastbuild, opt]
  25. runs-on: ${{ matrix.runner }}
  26. steps:
  27. - name: Harden Runner
  28. uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
  29. with:
  30. egress-policy: block
  31. # When adding endpoints, see README.md.
  32. # prettier-ignore
  33. allowed-endpoints: >
  34. *.dl.sourceforge.net:443
  35. api.github.com:443
  36. bcr.bazel.build:443
  37. downloads.sourceforge.net:443
  38. github.com:443
  39. mirrors.kernel.org:443
  40. nodejs.org:443
  41. oauth2.googleapis.com:443
  42. objects.githubusercontent.com:443
  43. pypi.org:443
  44. releases.bazel.build:443
  45. sourceforge.net:443
  46. storage.googleapis.com:443
  47. - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  48. - id: test-setup
  49. uses: ./.github/actions/test-setup
  50. with:
  51. matrix_runner: ${{ matrix.runner }}
  52. base_sha:
  53. ${{ github.event_name == 'pull_request' &&
  54. github.event.pull_request.base.sha ||
  55. github.event.merge_group.base_sha }}
  56. remote_cache_key: ${{ secrets.CARBON_BUILDS_GITHUB }}
  57. targets_file: ${{ runner.temp }}/targets
  58. # Build and run just the tests impacted by the PR or merge group.
  59. - name: Test (${{ matrix.build_mode }})
  60. if: steps.test-setup.outputs.has_code == 'true'
  61. shell: bash
  62. env:
  63. # 'libtool_check_unique failed to generate' workaround.
  64. # https://github.com/bazelbuild/bazel/issues/14113#issuecomment-999794586
  65. BAZEL_USE_CPP_ONLY_TOOLCHAIN: 1
  66. TARGETS_FILE: ${{ runner.temp }}/targets
  67. run: |
  68. # Decrease the jobs sharply if we see repeated failures to try to
  69. # work around transient network errors even if it makes things
  70. # slower.
  71. ./scripts/run_bazel.py \
  72. --attempts=5 --jobs-on-last-attempt=4 \
  73. test -c ${{ matrix.build_mode }} \
  74. --target_pattern_file=$TARGETS_FILE
  75. # See "Disk space before build" in `test-setup`.
  76. - name: Disk space after build
  77. if: steps.test-setup.outputs.has_code == 'true'
  78. run: df -h