Skip to content

Commit

Permalink
fix: if condition for job skipping and make clang-tidy incremental
Browse files Browse the repository at this point in the history
Split string and iterate through files
  • Loading branch information
danctorres committed Nov 15, 2024
1 parent 193e45b commit be2e9f6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/bazel_buildifier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Run Buildifier
run: |-
echo "${{ steps.changed_files.outputs.all }}"
if echo "${{ steps.changed_files.outputs.all }}" | grep -qE '(BUILD|WORKSPACE|MODULE\.bazel|\.bazelrc)$'; then
IFS=' ' read -r -a files <<< "${{ steps.changed_files.outputs.all }}"
bazel_files=()
for file in "${files[@]}"; do
if [[ "$file" == BUILD || "$file" == WORKSPACE || "$file" == MODULE\.bazel || "$file" == \.bazelrc ]]; then
bazel_files+=("$file")
fi
done
if [ ${#bazel_files[@]} -gt 0 ]; then
echo "Running bazel buildifier"
bazel run //bazel:buildifier_check
else
Expand Down
14 changes: 11 additions & 3 deletions .github/workflows/clang_format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ jobs:
- name: Set up clang-format
run: sudo apt-get install clang-format
- name: Run clang-format
run: |
if echo "${{ steps.changed_files.outputs.all }}" | grep -qE '\.(cpp|h|hpp|cc|cxx|hxx)$'; then
run: |-
IFS=' ' read -r -a files <<< "${{ steps.changed_files.outputs.all }}"
cpp_files=()
for file in "${files[@]}"; do
if [[ "$file" == *.cpp || "$file" == *.h || "$file" == *.hpp || "$file" == *.cc || "$file" == *.cxx || "$file" == *.hxx ]]; then
cpp_files+=("$file")
fi
done
if [ ${#cpp_files[@]} -gt 0 ]; then
echo -e "Running clang-format"
find . -name "*.cpp" -o -name "*.h" -o -name "*.hpp" -o -name "*.cc" -o -name "*.cxx" -o -name "*.hxx" | xargs clang-format --dry-run --Werror
clang-format --dry-run --Werror "${cpp_files[@]}"
else
echo -e "Skipping clang-format since no source files were changed."
fi
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/clang_tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ jobs:
format: space-delimited
token: ${{ secrets.GITHUB_TOKEN }}
- name: Run Clang-Tidy
run: |
if echo "${{ steps.changed_files.outputs.all }}" | grep -qE '\.(cpp|h|hpp|cc|cxx|hxx)$'; then
run: |-
IFS=' ' read -r -a files <<< "${{ steps.changed_files.outputs.all }}"
cpp_files=()
for file in "${files[@]}"; do
if [[ "$file" == *.cpp || "$file" == *.h || "$file" == *.hpp || "$file" == *.cc || "$file" == *.cxx || "$file" == *.hxx ]]; then
cpp_files+=("$file")
fi
done
if [ ${#cpp_files[@]} -gt 0 ]; then
echo -e "Running clang-tidy"
bazel build //... \
--aspects @bazel_clang_tidy//clang_tidy:clang_tidy.bzl%clang_tidy_aspect \
Expand Down

0 comments on commit be2e9f6

Please sign in to comment.