From 8db85fd6ca2de7e7a54ea9d53aea6f0b7e19aa6f Mon Sep 17 00:00:00 2001 From: "Y.Hisaki" Date: Wed, 27 Nov 2024 20:52:01 +0900 Subject: [PATCH 1/3] feat(clang-tidy): introducing .clang-tidy-ignore Signed-off-by: Y.Hisaki --- clang-tidy/action.yaml | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/clang-tidy/action.yaml b/clang-tidy/action.yaml index f5800b1f..a2968384 100644 --- a/clang-tidy/action.yaml +++ b/clang-tidy/action.yaml @@ -36,12 +36,6 @@ inputs: runs: using: composite steps: - - name: Show targets - run: | - echo "target packages: ${{ inputs.target-packages }}" - echo "target files: ${{ inputs.target-files }}" - shell: bash - - name: Install curl run: | sudo apt-get -yqq update @@ -115,28 +109,43 @@ runs: if [ "${{ inputs.target-files }}" != "" ]; then target_files="${{ inputs.target-files }}" else - package_path=$(colcon list --paths-only --packages-select ${{ inputs.target-packages }}) - target_files=$(find $package_path -type f \( -name '*.cpp' -o -name '*.hpp' \) -not -path '*/test/*' -not -path '*/examples/*') + mapfile -t package_paths < <(colcon list --paths-only --packages-select ${{ inputs.target-packages }}) + ignore_patterns=() + ignore_patterns+=( -not -path "*/test/*" ) + if [ -f .clang-tidy-ignore ]; then + while IFS= read -r pattern; do + ignore_patterns+=( -not -path "$pattern" ) + done < .clang-tidy-ignore + fi + target_files=$(find "${package_paths[@]}" -name '*.cpp' "${ignore_patterns[@]}" | tr '\n' ' ') fi - echo "target-files=$target_files" >> $GITHUB_OUTPUT shell: bash + - name: Show target files + if: ${{ steps.get-target-files.outputs.target-files != '' }} + run: | + echo "Target files:" + for file in "${{ steps.get-target-files.outputs.target-files }}" ; do + echo $file + done + shell: bash + - name: Analyze if: ${{ steps.get-target-files.outputs.target-files != '' }} run: | mkdir /tmp/clang-tidy-result - clang-tidy -p build/ -export-fixes /tmp/clang-tidy-result/fixes.yaml ${{ steps.get-target-files.outputs.target-files }} > /tmp/clang-tidy-result/report.txt || true + run-clang-tidy -p build/ -export-fixes /tmp/clang-tidy-result/fixes.yaml -j $(nproc) ${{ steps.get-target-files.outputs.target-files }} > /tmp/clang-tidy-result/report.log || true echo "${{ github.event.number }}" > /tmp/clang-tidy-result/pr-id.txt echo "${{ github.event.pull_request.head.repo.full_name }}" > /tmp/clang-tidy-result/pr-head-repo.txt echo "${{ github.event.pull_request.head.ref }}" > /tmp/clang-tidy-result/pr-head-ref.txt shell: bash - - name: Check if the report.txt file exists + - name: Check if the report.log file exists id: check-report-txt-existence uses: autowarefoundation/autoware-github-actions/check-file-existence@v1 with: - files: /tmp/clang-tidy-result/report.txt + files: /tmp/clang-tidy-result/report.log - name: Check if the fixes.yaml file exists id: check-fixes-yaml-existence @@ -154,7 +163,7 @@ runs: - name: Mark the workflow as failed if clang-tidy find an error if: ${{ steps.check-report-txt-existence.outputs.exists == 'true' }} run: | - if [ -n "$(grep ": error:" /tmp/clang-tidy-result/report.txt)" ]; then + if [ -n "$(grep ": error:" /tmp/clang-tidy-result/report.log)" ]; then exit 1 fi shell: bash From c9ae70f1b25fd484c54ceb2aaa194c4137173b18 Mon Sep 17 00:00:00 2001 From: "Y.Hisaki" Date: Thu, 28 Nov 2024 16:34:03 +0900 Subject: [PATCH 2/3] clang-tidy-ignore path as argument Signed-off-by: Y.Hisaki --- clang-tidy/action.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/clang-tidy/action.yaml b/clang-tidy/action.yaml index a2968384..cb11fc65 100644 --- a/clang-tidy/action.yaml +++ b/clang-tidy/action.yaml @@ -8,6 +8,10 @@ inputs: clang-tidy-config-url: description: "" required: true + clang-tidy-ignore-path: + description: "" + required: false + default: ".clang-tidy-ignore" target-packages: description: "" required: true @@ -112,7 +116,7 @@ runs: mapfile -t package_paths < <(colcon list --paths-only --packages-select ${{ inputs.target-packages }}) ignore_patterns=() ignore_patterns+=( -not -path "*/test/*" ) - if [ -f .clang-tidy-ignore ]; then + if [ -f ${{ inputs.clang-tidy-ignore-path }} ]; then while IFS= read -r pattern; do ignore_patterns+=( -not -path "$pattern" ) done < .clang-tidy-ignore From 7f0318e481ac530514a0b41b2ffa082c89a54c40 Mon Sep 17 00:00:00 2001 From: "Y.Hisaki" Date: Thu, 28 Nov 2024 17:06:31 +0900 Subject: [PATCH 3/3] fix yamllint Signed-off-by: Y.Hisaki --- clang-tidy/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tidy/action.yaml b/clang-tidy/action.yaml index cb11fc65..1488000b 100644 --- a/clang-tidy/action.yaml +++ b/clang-tidy/action.yaml @@ -11,7 +11,7 @@ inputs: clang-tidy-ignore-path: description: "" required: false - default: ".clang-tidy-ignore" + default: .clang-tidy-ignore target-packages: description: "" required: true