Skip to content

PSMDB-1884: fix clang-tidy workflow #62

PSMDB-1884: fix clang-tidy workflow

PSMDB-1884: fix clang-tidy workflow #62

Workflow file for this run

name: clang-tidy
on:
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
permissions:
contents: read
security-events: write
env:
CLANG_TIDY_SARIF_VERSION: "0.8.0"
jobs:
changed_files:
name: Check for changed C++ files
runs-on: ubuntu-latest
if: ${{ !contains(github.event.pull_request.labels.*.name, 'ci-skip-clang-tidy') }}
outputs:
changed_files: ${{ steps.changed.outputs.all_changed_files }}
steps:
- uses: actions/checkout@v4
- name: Get changed files
id: changed
uses: tj-actions/changed-files@v45
with:
files: |
**/*.cpp
**/*.c
- name: List changed files
run: |
echo "Changed files: ${{ steps.changed.outputs.all_changed_files }}"
analyze:
name: Run clang-tidy analysis
runs-on: ubuntu-latest
if: ${{ !contains(github.event.pull_request.labels.*.name, 'ci-skip-clang-tidy') && needs.changed_files.outputs.changed_files != '' }}
needs: changed_files
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup environment
uses: ./.github/actions/setup-env
- name: Setup AWS SDK
uses: ./.github/actions/setup-aws-sdk
- name: Bazel cache
uses: actions/cache@v4
id: bazel_cache
with:
path: |
~/.cache/bazel
~/.cache/bazelisk
key: ${{ runner.os }}-bazel-cache
- name: clang-tidy-sarif cache
uses: actions/cache@v4
id: clang_tidy_sarif_cache
with:
path: ~/.cargo
key: ${{ runner.os }}-clang-tidy-sarif-${{ env.CLANG_TIDY_SARIF_VERSION }}
- name: Install clang-tidy-sarif
if: steps.clang_tidy_sarif_cache.outputs.cache-hit != 'true'
run: cargo install clang-tidy-sarif --version "${CLANG_TIDY_SARIF_VERSION}" --locked
- name: Generate compile_commands.json and build mongo_tidy_checks plugin
run: |
{
echo 'common --config=local'
echo 'build --build_enterprise=false'
echo 'build --//bazel/config:compiler_type=clang'
} > .bazelrc.compiledb
bazel \
--bazelrc=.bazelrc.compiledb \
build \
//:compiledb \
//src/mongo/tools/mongo_tidy_checks:mongo_tidy_checks
- name: Run clang-tidy
run: |
CHANGED="${{ needs.changed_files.outputs.changed_files }}"
echo "Changed C++ files: '$CHANGED'"
external/mongo_toolchain_v5/v5/bin/clang-tidy \
--load="bazel-bin/src/mongo/tools/mongo_tidy_checks/libmongo_tidy_checks.so" \
$CHANGED \
| clang-tidy-sarif --output=clang-tidy-results.sarif
- name: Upload SARIF results
if: always()
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: clang-tidy-results.sarif
category: clang-tidy