Skip to content

Commit

Permalink
ci: run clang tools directly if run on all files
Browse files Browse the repository at this point in the history
  • Loading branch information
jnooree committed Oct 17, 2023
1 parent 9d6e338 commit 56bbb02
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/_run-clang-tools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,22 @@ jobs:
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-S . -B build -G Ninja
- name: Run clang tools to all files
if: ${{ always() && !inputs.files-changed-only }}
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
VERS=16
sudo ./llvm.sh $VERS
sudo apt-get install -y clang-tidy-$VERS clang-format-$VERS
sudo ln -sf clang-tidy-$VERS /usr/bin/clang-tidy
sudo ln -sf clang-format-$VERS /usr/bin/clang-format
./scripts/run_clang_tools.sh -c
- uses: cpp-linter/cpp-linter-action@v2
if: ${{ always() && inputs.files-changed-only }}
id: clang-tools
with:
version: "16"
Expand All @@ -46,10 +61,9 @@ jobs:
tidy-checks: ""
database: build
ignore: ".github|build|third-party|test"
files-changed-only: ${{ inputs.files-changed-only }}
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Fail fast
if: ${{ steps.clang-tools.outputs.checks-failed > 0 }}
if: ${{ always() && steps.clang-tools.outputs.checks-failed > 0 }}
run: echo "Some files failed the linting checks!" && exit 1
12 changes: 11 additions & 1 deletion scripts/run_clang_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ if [[ ! -d build ]]; then
exit 1
fi

cf_args=("-i")
while getopts 'c' opt; do
case "$opt" in
c) cf_args=(-n --Werror) ;;
*) break ;;
esac
done

shift $((OPTIND - 1))

files="$(mktemp)"
if [[ $# -eq 0 ]]; then
find include src python/nuri \
Expand All @@ -24,5 +34,5 @@ else
printf '%s\0' "$@" >"$files"
fi

xargs -0 -P0 -n1 clang-format -i <"$files"
xargs -0 -P0 -n1 clang-format "${cf_args[@]}" <"$files"
xargs -0 -P0 -n1 clang-tidy -p build --extra-arg-before=-Werror <"$files"

0 comments on commit 56bbb02

Please sign in to comment.