Jp car motion cpp #446
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# yamllint disable rule:line-length | |
--- | |
name: Clang | |
on: # yamllint disable-line rule:truthy | |
pull_request: | |
branches: ['*'] | |
jobs: | |
tidy: | |
runs-on: ubuntu-latest | |
container: | |
image: dtors/base-cpp:latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Configure Git Safe Directory | |
run: | | |
git config --global --add safe.directory $(pwd) | |
- name: Find affected files | |
run: | | |
git fetch origin ${{ github.base_ref }} --depth=1 | |
git diff --diff-filter=ACM --name-only origin/${{ github.base_ref }} > affected_files.txt | |
echo "Affected files:" | |
cat affected_files.txt | |
- name: Find affected cpp files | |
run: | | |
> affected_cpp_files.txt | |
while read file; do | |
if [[ "$file" == *.c || "$file" == *.cc || "$file" == *.cpp || "$file" == *.cxx || "$file" == *.h || "$file" == *.hpp || "$file" == *.hxx ]]; then | |
echo "$file" >> affected_cpp_files.txt | |
fi | |
done < affected_files.txt | |
sort -u affected_cpp_files.txt -o affected_cpp_files.txt | |
echo "Affected cpp files:" | |
cat affected_cpp_files.txt | |
echo "cpp_files=$(cat affected_cpp_files.txt | tr -s '\n' ' ' | sed 's/^[ \t]*//;s/[ \t]*$//')" >> $GITHUB_ENV | |
shell: bash | |
- name: Generate Compile Commands | |
if: env.cpp_files != '' | |
run: | | |
echo "Generating compile commands" | |
bazelisk run @hedron_compile_commands//:refresh_all | |
shell: bash | |
- name: Run Clang-Tidy | |
if: env.cpp_files != '' | |
run: | | |
echo "Running: clang-tidy ${cpp_files} -p ./compile_commands.json" | |
clang-tidy $cpp_files -p ./compile_commands.json | |
shell: bash | |
- name: Skip Clang-Tidy | |
if: env.cpp_files == '' | |
run: echo "No affected cpp files found. Skipping Clang-Tidy." | |
- name: Show failure message | |
if: failure() | |
run: |- | |
echo -e "To automatically apply suggested fixes, run the following command: | |
====================================================================================== | |
1. Generate compile commands: | |
bazel run @hedron_compile_commands//:refresh_all | |
2. Run clang-tidy: | |
find . -iname \"*.c\" -o -iname \"*.cc\" -o -iname \"*.cpp\" -o -iname \"*.cxx\" -o -iname \"*.h\" -o -iname \"*.hpp\" -o -iname \"*.hxx\" | xargs clang-tidy -p ./compile_commands.json | |
3. Run clang-tidy: | |
find . -iname \"*.c\" -o -iname \"*.cc\" -o -iname \"*.cpp\" -o -iname \"*.cxx\" -o -iname \"*.h\" -o -iname \"*.hpp\" -o -iname \"*.hxx\" | xargs clang-tidy -p ./compile_commands.json -fix --fix-errors | |
======================================================================================" |