From be2e9f666f74da0d344d1075762872c741336288 Mon Sep 17 00:00:00 2001 From: dtor Date: Fri, 15 Nov 2024 14:39:08 +0000 Subject: [PATCH] fix: if condition for job skipping and make clang-tidy incremental Split string and iterate through files --- .github/workflows/bazel_buildifier.yml | 11 +++++++++-- .github/workflows/clang_format.yml | 14 +++++++++++--- .github/workflows/clang_tidy.yml | 12 ++++++++++-- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/.github/workflows/bazel_buildifier.yml b/.github/workflows/bazel_buildifier.yml index abfa35f..241b33b 100644 --- a/.github/workflows/bazel_buildifier.yml +++ b/.github/workflows/bazel_buildifier.yml @@ -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 diff --git a/.github/workflows/clang_format.yml b/.github/workflows/clang_format.yml index 08be52d..670c3a2 100644 --- a/.github/workflows/clang_format.yml +++ b/.github/workflows/clang_format.yml @@ -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 diff --git a/.github/workflows/clang_tidy.yml b/.github/workflows/clang_tidy.yml index 7779370..8ddf992 100644 --- a/.github/workflows/clang_tidy.yml +++ b/.github/workflows/clang_tidy.yml @@ -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 \