Skip to content

Fix clang-tidy action from external repos #43

Fix clang-tidy action from external repos

Fix clang-tidy action from external repos #43

Workflow file for this run

name: Clang Tidy
on:
pull_request_target: # Required to post comments on PR from forks
jobs:
clang-tidy-review:
runs-on: ubuntu-latest
if: startsWith(github.event_name, 'pull_request') # Posting a review only makes sense on PRs
steps:
# Repo config for pull_request_target
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
submodules: recursive
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Install clang-tidy
run: |
sudo debconf-communicate <<< "set man-db/auto-update false"
sudo dpkg-reconfigure man-db
sudo apt-get update
sudo apt-get install -y clang-19 clang-tidy-19
- uses: actions/setup-python@v5
with:
python-version: "3.13"
cache: "pip"
- name: Generate compilation database
run: |
cd ${{ github.workspace }}
./dbt configure
sed -i 's/-mthumb-interwork//g' build/compile_commands.json
sed -i 's/-fdevirtualize-at-ltrans//g' build/compile_commands.json
sed -i 's/-fuse-linker-plugin//g' build/compile_commands.json
- name: Install clang-tidy-review
run: pip install ${{github.workspace}}/contrib/clang_tidy_review
- name: Extract system includes from GCC
run: |
${{ github.workspace }}/toolchain/current/arm-none-eabi-gcc/bin/arm-none-eabi-g++ -mcpu=cortex-a9 -mfpu=neon -mfloat-abi=hard -E -x c++ - -v < /dev/null 2>&1 \
| sed -n '/^#include <...> search starts here:$/,/^End of search list.$/p' \
| tail -n +2 \
| head -n -1 \
| sed 's/^\s*//g' \
| sed 's/^\(.*\)$/--extra-arg-before=-isystem\1/g' > system_includes.txt
echo "Extracted system includes:"
cat system_includes.txt
- name: Run clang-tidy-review
run: |
review \
--token=${{ secrets.GITHUB_TOKEN }} \
--repo=${{ github.event.pull_request.base.repo.full_name }} \
--pr=${{ github.event.pull_request.number }} \
--split_workflow=True \
--clang_tidy_binary=clang-tidy-19 \
--build_dir=${{ github.workspace }}/build \
--config_file=${{ github.workspace }}/.clang-tidy \
$(cat system_includes.txt) \
--extra-arg-before="--no-standard-includes"
env:
USER: ${{ github.event.pull_request.user.login }}
- name: Post review
run: |
post \
--token=${{ secrets.GITHUB_TOKEN }} \
--repo=${{ github.event.pull_request.base.repo.full_name }} \
--lgtm-comment-body="" \
--num-comments-as-exitcode=True \
clang-tidy-review-output.json