135 lines
4.0 KiB
YAML
135 lines
4.0 KiB
YAML
# ns-3 CI/CD script with the code-linting stage
|
|
#
|
|
# Contains jobs to check the ns-3 coding style and perform lint checking.
|
|
|
|
# Clang-format
|
|
.check-style-clang-format:
|
|
stage: .pre
|
|
image: ubuntu:rolling
|
|
before_script:
|
|
- apt update
|
|
- DEBIAN_FRONTEND=noninteractive apt install -y
|
|
python3
|
|
clang-format-$CLANG_FORMAT_VERSION
|
|
script:
|
|
- python3 utils/check-style-clang-format.py --verbose .
|
|
timeout: 1h
|
|
|
|
check-style-clang-format-17:
|
|
extends: .check-style-clang-format
|
|
variables:
|
|
CLANG_FORMAT_VERSION: 17
|
|
|
|
check-style-clang-format-16:
|
|
extends: .check-style-clang-format
|
|
variables:
|
|
CLANG_FORMAT_VERSION: 16
|
|
|
|
check-style-clang-format-15:
|
|
extends: .check-style-clang-format
|
|
variables:
|
|
CLANG_FORMAT_VERSION: 15
|
|
|
|
check-style-clang-format-14:
|
|
extends: .check-style-clang-format
|
|
variables:
|
|
CLANG_FORMAT_VERSION: 14
|
|
|
|
# Clang-tidy
|
|
clang-tidy-17:
|
|
stage: code-linting
|
|
image: ubuntu:rolling
|
|
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
|
|
clang cmake
|
|
clang-tidy clang-tidy-17
|
|
libboost-all-dev libeigen3-dev libgtk-3-dev libopenmpi-dev libsqlite3-dev
|
|
gsl-bin libgsl-dev libgsl27
|
|
git ssh
|
|
- ./ns3 configure -d debug
|
|
--enable-clang-tidy
|
|
--enable-examples --enable-tests --enable-asserts
|
|
--enable-mpi
|
|
script:
|
|
- if (git remote | grep -qw upstream) ; then
|
|
git remote remove upstream ;
|
|
fi
|
|
- git remote add -t $CI_DEFAULT_BRANCH --no-tags -f upstream https://gitlab.com/nsnam/ns-3-dev.git
|
|
- git diff --name-only upstream/$CI_DEFAULT_BRANCH > $FILES_CHANGED
|
|
|
|
# Run full clang-tidy in the following cases: 1) default branch, 2) ".clang-tidy" file changed
|
|
# Run clang-tidy-diff in the opposite cases.
|
|
# File paths generated by git diff are relative to the working tree. Therefore, iregex should only contain paths relative to the working tree.
|
|
- if [[ $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH ]] || (grep -q ".clang-tidy" $FILES_CHANGED) ; then
|
|
echo "Running full clang-tidy" ;
|
|
run-clang-tidy-17 -p cmake-cache/ -quiet
|
|
1> $CLANG_TIDY_OUTPUT
|
|
2> /dev/null ;
|
|
else
|
|
echo "Running clang-tidy-diff" ;
|
|
git diff -U0 upstream/$CI_DEFAULT_BRANCH |
|
|
clang-tidy-diff-17.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 ;
|
|
fi
|
|
|
|
# Check job results
|
|
- (! egrep -v "file not found \[clang-diagnostic-error\]" $CLANG_TIDY_OUTPUT | egrep -A3 "error:|warning:|note:")
|
|
- echo "No clang-tidy errors found"
|
|
dependencies: []
|
|
artifacts:
|
|
paths:
|
|
- $CLANG_TIDY_OUTPUT
|
|
when: on_failure
|
|
interruptible: true
|
|
timeout: 3h
|
|
|
|
# Emacs line
|
|
emacs-line:
|
|
stage: .pre
|
|
image: ubuntu:latest
|
|
script:
|
|
- if ( egrep -rn --include="*.h" --include="*.cc" --include="*.c" --include="*.py" --include="*.rst" "c-file-style:|py-indent-offset:" ) ; then
|
|
echo "Found Emacs lines on the above C/C++, Python and RST files" ;
|
|
exit 1 ;
|
|
else
|
|
echo "No Emacs lines found on C/C++, Python and RST files" ;
|
|
exit 0 ;
|
|
fi
|
|
timeout: 1h
|
|
|
|
# Spell checking
|
|
spell-check:
|
|
stage: .pre
|
|
image: python:latest
|
|
before_script:
|
|
- pip install codespell
|
|
script:
|
|
# Get commit messages
|
|
- if (git remote | grep -qw upstream) ; then
|
|
git remote remove upstream ;
|
|
fi
|
|
- git remote add -t $CI_DEFAULT_BRANCH --no-tags -f upstream https://gitlab.com/nsnam/ns-3-dev.git
|
|
|
|
- git log --pretty=%B HEAD...upstream/$CI_DEFAULT_BRANCH ^upstream/$CI_DEFAULT_BRANCH > git_messages.txt
|
|
# Check source code and commit messages
|
|
- codespell -f -C0 ./
|
|
timeout: 1h
|
|
|
|
# Check cmake format
|
|
cmake-format:
|
|
stage: .pre
|
|
image: python:latest
|
|
before_script:
|
|
- pip install pyyaml cmake cmake-format ninja
|
|
script:
|
|
- ./ns3 configure --enable-modules=core
|
|
- ./ns3 build cmake-format-check
|
|
timeout: 1h
|