From a7214a780df1212866a35fb9c6c62fea6a84d663 Mon Sep 17 00:00:00 2001 From: Eduardo Almeida Date: Wed, 3 May 2023 05:30:03 +0100 Subject: [PATCH] ci: Do not run clang-tidy-diff when also running full clang-tidy --- utils/tests/gitlab-ci-code-linting.yml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/utils/tests/gitlab-ci-code-linting.yml b/utils/tests/gitlab-ci-code-linting.yml index 7b741bfc4..0786acc80 100644 --- a/utils/tests/gitlab-ci-code-linting.yml +++ b/utils/tests/gitlab-ci-code-linting.yml @@ -22,6 +22,7 @@ clang-tidy: variables: MPI_CI: 1 CLANG_TIDY_OUTPUT: clang-tidy-output.log + FILES_CHANGED: git-diff-name-only.log before_script: - apt update - DEBIAN_FRONTEND=noninteractive apt install -y @@ -43,17 +44,21 @@ clang-tidy: git remote add upstream https://gitlab.com/nsnam/ns-3-dev.git ; fi - git fetch upstream $CI_DEFAULT_BRANCH + - git diff --name-only upstream/$CI_DEFAULT_BRANCH > $FILES_CHANGED - # Run clang-tidy-diff. If running on default branch, Git diff is empty and this is ignored. + # Run clang-tidy-diff in the opposite cases of the if-else below. # File paths generated by git diff are relative to the working tree. Therefore, iregex should only contain paths relative to the working tree. - - git diff -U0 upstream/$CI_DEFAULT_BRANCH | + - if !([[ $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH ]] || (grep -q ".clang-tidy" $FILES_CHANGED)) ; then + echo "Running clang-tidy-diff" ; + git diff -U0 upstream/$CI_DEFAULT_BRANCH | clang-tidy-diff-14.py -path cmake-cache/ -p1 -quiet -use-color -iregex "(contrib|examples|src|scratch|utils)\/.+\.(cpp|cc|cxx|c|h|hpp)" 1> $CLANG_TIDY_OUTPUT - 2> /dev/null + 2> /dev/null ; + fi # Run full clang-tidy in the following cases: 1) default branch, 2) ".clang-tidy" file changed, 3) clang-tidy-diff had an error - - if [[ $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH ]] || (echo $(git diff --name-only upstream/$CI_DEFAULT_BRANCH) | grep -q ".clang-tidy") || (egrep -q -A 3 "file not found \[clang-diagnostic-error\]" $CLANG_TIDY_OUTPUT) ; then + - if [[ $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH ]] || (grep -q ".clang-tidy" $FILES_CHANGED) || (egrep -q -A 3 "file not found \[clang-diagnostic-error\]" $CLANG_TIDY_OUTPUT) ; then echo "Running full clang-tidy" ; run-clang-tidy-14 -p cmake-cache/ -quiet 1> $CLANG_TIDY_OUTPUT