tests.yaml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. name:
  21. Testing ${{ matrix.config.name != 'Default' && format('({0})',
  22. matrix.config.name) || '' }} (${{ matrix.runner }})
  23. strategy:
  24. matrix:
  25. # Test a recent version of each supported OS.
  26. runner: ['ubuntu-22.04', 'macos-14']
  27. # Create a synthetic matrix dimension with the event name for filtering.
  28. event: ['${{ github.event_name }}']
  29. config:
  30. - name: 'Default'
  31. flags: ''
  32. - name: 'Opt'
  33. flags: '-c opt'
  34. - name: 'ASan'
  35. flags: '--config=asan'
  36. exclude:
  37. - runner: 'macos-14'
  38. config: { name: 'ASan', flags: '--config=asan' }
  39. - event: 'pull_request'
  40. config: { name: 'ASan', flags: '--config=asan' }
  41. - event: 'merge_group'
  42. config: { name: 'ASan', flags: '--config=asan' }
  43. runs-on: ${{ matrix.runner }}
  44. steps:
  45. - name: Harden Runner
  46. uses: step-security/harden-runner@58077d3c7e43986b6b15fba718e8ea69e387dfcc # v2.15.1
  47. with:
  48. egress-policy: block
  49. # When adding endpoints, see README.md.
  50. # prettier-ignore
  51. allowed-endpoints: >
  52. *.blob.storage.azure.net:443
  53. *.githubapp.com:443
  54. *.sourceforge.net:443
  55. api.github.com:443
  56. api.ipify.org:443
  57. bcr.bazel.build:443
  58. downloads.sourceforge.net:443
  59. files.pythonhosted.org:443
  60. github.com:443
  61. go.dev:443
  62. mirror.bazel.build:443
  63. mirrors.kernel.org:443
  64. nodejs.org:443
  65. oauth2.googleapis.com:443
  66. objects.githubusercontent.com:443
  67. pypi.org:443
  68. registry.npmjs.org:443
  69. release-assets.githubusercontent.com:443
  70. releases.bazel.build:443
  71. storage.googleapis.com:443
  72. uploads.github.com:443
  73. www.googleapis.com:443
  74. - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
  75. - id: test-setup
  76. uses: ./.github/actions/test-setup
  77. with:
  78. matrix_runner: ${{ matrix.runner }}
  79. base_sha:
  80. ${{ github.event_name == 'pull_request' &&
  81. github.event.pull_request.base.sha ||
  82. github.event.merge_group.base_sha }}
  83. remote_cache_key: ${{ secrets.CARBON_BUILDS_GITHUB }}
  84. targets_file: ${{ runner.temp }}/targets
  85. # Build and run just the tests impacted by the PR or merge group.
  86. - name: Test (${{ matrix.config.name }})
  87. if: steps.test-setup.outputs.has_code == 'true'
  88. shell: bash
  89. env:
  90. # 'libtool_check_unique failed to generate' workaround.
  91. # https://github.com/bazelbuild/bazel/issues/14113#issuecomment-999794586
  92. BAZEL_USE_CPP_ONLY_TOOLCHAIN: 1
  93. TARGETS_FILE: ${{ runner.temp }}/targets
  94. run: |
  95. # Decrease the jobs sharply if we see repeated failures to try to
  96. # work around transient network errors even if it makes things
  97. # slower. Note that we allow passing targets that are incompatible and
  98. # skip thim as-if we were using `//...` style wild card patterns.
  99. ./scripts/run_bazel.py \
  100. --attempts=5 --jobs-on-last-attempt=4 \
  101. test ${{ matrix.config.flags }} \
  102. --target_pattern_file=$TARGETS_FILE
  103. # See "Disk space before build" in `test-setup`.
  104. - name: Disk space after build
  105. if: steps.test-setup.outputs.has_code == 'true'
  106. run: df -h