ci: Unify clang-tidy and clang-tidy-diff jobs
This commit is contained in:
@@ -16,7 +16,7 @@ check-style-clang-format:
|
||||
timeout: 1h
|
||||
|
||||
# Clang-tidy
|
||||
.base-clang-tidy:
|
||||
clang-tidy:
|
||||
stage: code-linting
|
||||
image: ubuntu:latest
|
||||
variables:
|
||||
@@ -36,62 +36,39 @@ check-style-clang-format:
|
||||
--enable-clang-tidy
|
||||
--enable-examples --enable-tests --enable-asserts
|
||||
--enable-mpi --enable-python-bindings
|
||||
script:
|
||||
- if (git remote | grep -qw upstream) ; then
|
||||
git remote set-url upstream https://gitlab.com/nsnam/ns-3-dev.git ;
|
||||
else
|
||||
git remote add upstream https://gitlab.com/nsnam/ns-3-dev.git ;
|
||||
fi
|
||||
- git fetch upstream $CI_DEFAULT_BRANCH
|
||||
|
||||
# Run clang-tidy-diff. If running on default branch, Git diff is empty and this is ignored.
|
||||
# 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 |
|
||||
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
|
||||
|
||||
# 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 ] || (git diff -U0 --name-only upstream/$CI_DEFAULT_BRANCH | grep -q ".clang-tidy") || (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
|
||||
2> /dev/null ;
|
||||
fi
|
||||
|
||||
# Check job results
|
||||
- (! egrep -A 3 "error:|warning:|note:" $CLANG_TIDY_OUTPUT)
|
||||
- echo "No clang-tidy errors found"
|
||||
artifacts:
|
||||
paths:
|
||||
- $CLANG_TIDY_OUTPUT
|
||||
when: on_failure
|
||||
timeout: 3h
|
||||
|
||||
clang-tidy:
|
||||
extends: .base-clang-tidy
|
||||
rules:
|
||||
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
||||
when: never
|
||||
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
||||
when: on_success
|
||||
- changes:
|
||||
paths:
|
||||
- .clang-tidy
|
||||
compare_to: master
|
||||
when: on_success
|
||||
script:
|
||||
- run-clang-tidy-14 -p cmake-cache/ -quiet
|
||||
1> $CLANG_TIDY_OUTPUT
|
||||
2> /dev/null
|
||||
- (! egrep -A 3 "error:|warning:|note:" $CLANG_TIDY_OUTPUT)
|
||||
- echo "No clang-tidy errors found"
|
||||
|
||||
clang-tidy-diff:
|
||||
extends: .base-clang-tidy
|
||||
rules:
|
||||
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
||||
when: never
|
||||
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
||||
when: never
|
||||
- changes:
|
||||
paths:
|
||||
- .clang-tidy
|
||||
compare_to: master
|
||||
when: never
|
||||
- when: on_success
|
||||
script:
|
||||
- git remote add upstream https://gitlab.com/nsnam/ns-3-dev.git
|
||||
- git fetch upstream master
|
||||
# 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/master |
|
||||
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
|
||||
- if egrep -A 3 "file not found \[clang-diagnostic-error\]" $CLANG_TIDY_OUTPUT ; then
|
||||
echo "Clang-tidy could not find the above files. Running a full clang-tidy check." ;
|
||||
run-clang-tidy-14 -p cmake-cache/ -quiet
|
||||
1> $CLANG_TIDY_OUTPUT
|
||||
2> /dev/null ;
|
||||
fi
|
||||
- (! egrep -A 3 "error:|warning:|note:" $CLANG_TIDY_OUTPUT)
|
||||
- echo "No clang-tidy errors found"
|
||||
|
||||
# Emacs line
|
||||
emacs-line:
|
||||
stage: code-linting
|
||||
|
||||
Reference in New Issue
Block a user