|
| 1 | +name: Clang-Tidy action |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + pull_request: |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + scan_regex: |
| 9 | + description: "Regex used to select files from compile_commands.json" |
| 10 | + required: false |
| 11 | + default: "/(core|class|common|osal|port|platform)/.*[.]c$" |
| 12 | + |
| 13 | +jobs: |
| 14 | + clang-tidy: |
| 15 | + name: clang-tidy |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Checkout repository |
| 19 | + uses: actions/checkout@v4 |
| 20 | + |
| 21 | + - name: Install dependencies |
| 22 | + run: | |
| 23 | + sudo apt-get update |
| 24 | + sudo apt-get install -y clang-tidy cmake ninja-build jq ripgrep wget |
| 25 | +
|
| 26 | + - name: Download hpm_sdk |
| 27 | + run: | |
| 28 | + cd ~ |
| 29 | + git clone --depth 1 https://github.com/hpmicro/hpm_sdk.git |
| 30 | +
|
| 31 | + - name: Download RISC-V toolchain |
| 32 | + run: | |
| 33 | + cd ~ |
| 34 | + wget -q https://github.com/hpmicro/riscv-gnu-toolchain/releases/download/2023.10.18/rv32imac_zicsr_zifencei_multilib_b_ext-linux.tar.gz |
| 35 | + tar -xzf rv32imac_zicsr_zifencei_multilib_b_ext-linux.tar.gz |
| 36 | +
|
| 37 | + - name: Generate HPM compile database |
| 38 | + run: | |
| 39 | + cd tests/hpmicro |
| 40 | + export HPM_SDK_BASE=~/hpm_sdk |
| 41 | + export GNURISCV_TOOLCHAIN_PATH=~/rv32imac_zicsr_zifencei_multilib_b_ext-linux |
| 42 | + export HPM_SDK_TOOLCHAIN_VARIANT= |
| 43 | + cmake -S . -B build -GNinja \ |
| 44 | + -DBOARD=hpm6800evk \ |
| 45 | + -DHPM_BUILD_TYPE=flash_sdram_xip \ |
| 46 | + -DCMAKE_BUILD_TYPE=debug \ |
| 47 | + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON |
| 48 | +
|
| 49 | + - name: Run clang-tidy |
| 50 | + shell: bash |
| 51 | + env: |
| 52 | + SCAN_REGEX: ${{ github.event.inputs.scan_regex || '/(core|class|common|osal|port|platform)/.*[.]c$' }} |
| 53 | + run: | |
| 54 | + TOOLCHAIN="$HOME/rv32imac_zicsr_zifencei_multilib_b_ext-linux" |
| 55 | + GCC="$TOOLCHAIN/bin/riscv32-unknown-elf-gcc" |
| 56 | + GCC_INCLUDE="$("$GCC" -print-file-name=include)" |
| 57 | + GCC_INCLUDE_FIXED="$("$GCC" -print-file-name=include-fixed)" |
| 58 | +
|
| 59 | + set +e |
| 60 | + jq -r '.[].file' tests/hpmicro/build/compile_commands.json \ |
| 61 | + | rg "^${GITHUB_WORKSPACE}${SCAN_REGEX}" \ |
| 62 | + | xargs -r -n1 clang-tidy \ |
| 63 | + -p tests/hpmicro/build \ |
| 64 | + --quiet \ |
| 65 | + --extra-arg-before=--target=riscv32-unknown-elf \ |
| 66 | + --extra-arg=-isystem"$GCC_INCLUDE" \ |
| 67 | + --extra-arg=-isystem"$GCC_INCLUDE_FIXED" \ |
| 68 | + > clang-tidy.log 2>&1 |
| 69 | + tidy_status=$? |
| 70 | + set -e |
| 71 | +
|
| 72 | + grep -E "warning:|error:" clang-tidy.log | tee clang-tidy-summary.log || true |
| 73 | +
|
| 74 | + while IFS= read -r line; do |
| 75 | + if [[ "$line" =~ ^([^:]+):([0-9]+):([0-9]+):[[:space:]]warning:[[:space:]](.*)$ ]]; then |
| 76 | + echo "::warning file=${BASH_REMATCH[1]},line=${BASH_REMATCH[2]},col=${BASH_REMATCH[3]}::${BASH_REMATCH[4]}" |
| 77 | + elif [[ "$line" =~ ^([^:]+):([0-9]+):([0-9]+):[[:space:]]error:[[:space:]](.*)$ ]]; then |
| 78 | + echo "::error file=${BASH_REMATCH[1]},line=${BASH_REMATCH[2]},col=${BASH_REMATCH[3]}::${BASH_REMATCH[4]}" |
| 79 | + fi |
| 80 | + done < clang-tidy-summary.log |
| 81 | +
|
| 82 | + if [ "$tidy_status" -ne 0 ]; then |
| 83 | + exit "$tidy_status" |
| 84 | + fi |
| 85 | +
|
| 86 | + - name: Upload clang-tidy logs |
| 87 | + if: always() |
| 88 | + uses: actions/upload-artifact@v4 |
| 89 | + with: |
| 90 | + name: clang-tidy-logs |
| 91 | + path: | |
| 92 | + clang-tidy.log |
| 93 | + clang-tidy-summary.log |
0 commit comments