From facf6eea0414365891f4b73088bda9fbf0667725 Mon Sep 17 00:00:00 2001 From: Jon Ross-Perkins Date: Thu, 4 Jan 2024 13:45:53 -0800 Subject: [PATCH] Check clang-tidy in tests.yaml (#3567) Example success: https://github.com/carbon-language/carbon-lang/actions/runs/7414437667/job/20175507192 Example failure: https://github.com/carbon-language/carbon-lang/actions/runs/7414486486/job/20175656728 --- .github/workflows/tests.yaml | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 74187211fe45..065c209bd2a9 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -25,6 +25,10 @@ jobs: # https://github.com/actions/runner-images os: [ubuntu-22.04, macos-12] build_mode: [fastbuild, opt] + # The clang-tidy config doesn't work on macos (missing `truncate`). + include: + - os: 'ubuntu-22.04' + build_mode: 'clang-tidy' runs-on: ${{ matrix.os }} steps: @@ -251,20 +255,22 @@ jobs: # Then use `target-determinator` as wrapped by our script. ./scripts/target_determinator.py $GIT_BASE_SHA >$TARGETS_FILE + # Bazel requires a test target to run the test command. There may be + # no targets or there may only be non-test targets that we want to + # build, so simply inject an explicit no-op test target. + echo "//scripts:no_op_test" >> $TARGETS_FILE + # Build and run just the tests impacted by the PR or merge group. - name: Test (${{ matrix.build_mode }}) - if: steps.filter.outputs.has_code == 'true' + if: + steps.filter.outputs.has_code == 'true' && matrix.build_mode != + 'clang-tidy' env: # 'libtool_check_unique failed to generate' workaround. # https://github.com/bazelbuild/bazel/issues/14113#issuecomment-999794586 BAZEL_USE_CPP_ONLY_TOOLCHAIN: 1 TARGETS_FILE: ${{ runner.temp }}/targets run: | - # Bazel requires a test target to run the test command. There may be - # no targets or there may only be non-test targets that we want to - # build, so simply inject an explicit no-op test target. - echo "//scripts:no_op_test" >> $TARGETS_FILE - for i in {1..5}; do if (( $i == 4 )); then # Decrease the jobs sharply if we see repeated failures to try to @@ -307,6 +313,20 @@ jobs: # Propagate the Bazel exit code. exit $bazel_exit + # Run in the clang-tidy config. This is done as part of tests so that we + # aren't duplicating bazel/llvm setup. + # + # The `-k` flag is used to print all clang-tidy errors. + - name: clang-tidy + if: + steps.filter.outputs.has_code == 'true' && matrix.os == 'ubuntu-22.04' + && matrix.build_mode == 'clang-tidy' + env: + TARGETS_FILE: ${{ runner.temp }}/targets + run: | + bazelisk build --config=clang-tidy -k \ + --target_pattern_file=$TARGETS_FILE + # See "Disk space before build". - name: Disk space after build if: steps.filter.outputs.has_code == 'true'