Add clang-tidy script
[alexxy/gromacs.git] / admin / gitlab-ci / lint.gitlab-ci.yml
1 # Repository cleanliness. Source tidiness, linting, and policy compliance.
2
3 clang-tidy:configure:
4   extends:
5     - .gromacs:base:configure
6     - .use-clang7
7     - .rules:not-for-release
8   dependencies: []
9   variables:
10     BUILD_DIR: build-clang-tidy
11     CMAKE_EXTRA_OPTIONS: -DCLANG_TIDY=clang-tidy-$COMPILER_MAJOR_VERSION -DGMX_CLANG_TIDY=ON -DGMX_COMPILER_WARNINGS=ON
12     EXTRA_INSTALLS: clang-tidy-$COMPILER_MAJOR_VERSION
13     CMAKE_GMXAPI_OPTIONS: "-DGMX_PYTHON_PACKAGE=OFF"
14   # TODO: Enable GMX_PYTHON_PACKAGE for clang-tidy when dependencies are in Docker image.
15
16 clang-tidy:build:
17   extends:
18     - .gromacs:base:build
19     - .use-ccache
20     - .variables:default
21     - .use-clang7
22     - .rules:nightly-not-for-release
23   stage: source-check
24   needs:
25     - job: clang-tidy:configure
26   variables:
27     BUILD_DIR: build-clang-tidy
28     EXTRA_INSTALLS: clang-tidy-$COMPILER_MAJOR_VERSION
29
30 clang-tidy:test:
31   extends:
32     - .gromacs:base:build
33     - .use-ccache
34     - .variables:default
35     - .use-clang7
36     - .rules:not-for-release
37   stage: source-check
38   needs:
39     - job: clang-tidy:configure
40   variables:
41     BUILD_DIR: build-clang-tidy
42     EXTRA_INSTALLS: clang-tidy-$COMPILER_MAJOR_VERSION
43     KUBERNETES_CPU_LIMIT: 4
44     KUBERNETES_CPU_REQUEST: 2
45     KUBERNETES_MEMORY_LIMIT: 4Gi
46   script:
47     - RUN_CLANG_TIDY=run-clang-tidy-$COMPILER_MAJOR_VERSION bash admin/clang-tidy.sh check --parallel=$KUBERNETES_CPU_LIMIT --warnings=clang-tidy.log --rev=origin/master -B=$BUILD_DIR
48     - grep -iq "found code issues" clang-tidy.log | tee code-lint.txt || true
49     - if [ -s code-lint.txt ] ; then echo "clang-tidy.sh found issues"; exit 1; fi
50   artifacts:
51     when: on_failure
52     paths:
53       - clang-tidy.log
54       - code-lint.txt
55
56 clang-format:
57   extends:
58     - .variables:default
59     - .use-clang7
60     - .rules:basic
61   cache: {}
62   stage: pre-build
63   tags: []
64   variables:
65     KUBERNETES_CPU_LIMIT: 1
66     KUBERNETES_CPU_REQUEST: 1
67     KUBERNETES_MEMORY_LIMIT: 2Gi
68     EXTRA_INSTALLS: clang-format-$COMPILER_MAJOR_VERSION
69   script:
70     - export CLANG_FORMAT=clang-format-$COMPILER_MAJOR_VERSION
71     - admin/clang-format.sh check --rev=HEAD^ --warnings=clang-format.log
72     - grep -iq "needs formatting" clang-format.log | tee formatting.txt || true
73     - if [ -s formatting.txt ] ; then echo "clang-format.sh found issues"; exit 1; fi
74   artifacts:
75     when: on_failure
76     paths:
77       - clang-format.log
78       - formatting.txt
79
80 copyright-check:
81   extends:
82     - .variables:default
83     - .use-clang7
84     - .rules:basic
85   cache: {}
86   stage: pre-build
87   tags: []
88   variables:
89     KUBERNETES_CPU_LIMIT: 1
90     KUBERNETES_CPU_REQUEST: 1
91     KUBERNETES_MEMORY_LIMIT: 2Gi
92   script:
93     - admin/copyright.sh check --rev=HEAD^ --warnings=copyright.log
94     - grep -iq "copyright year" copyright.log | tee years.log || true
95     - grep -iq "copyright header" copyright.log | tee headers.log || true
96     - if [[ -s years.log || -s headers.log ]] ; then
97       echo "Copyright information needs updating" ;
98       exit 1 ;
99       fi
100   artifacts:
101     when: on_failure
102     paths:
103       - copyright.log
104       - years.log
105       - headers.log
106
107 check-source:
108   extends:
109     - .variables:default
110     - .docs:build
111     - .before_script:default
112     - .rules:not-for-release
113   cache: {}
114   stage: source-check
115   needs:
116     - job: docs:build
117       artifacts: true
118   variables:
119     KUBERNETES_CPU_LIMIT: 1
120     KUBERNETES_CPU_REQUEST: 1
121     KUBERNETES_MEMORY_LIMIT: 2Gi
122     BUILD_DIR: build-docs
123   script:
124     - cd $BUILD_DIR
125     - cmake --build . --target check-source
126     - grep -qi "error" docs/doxygen/doxygen*log docs/doxygen/check-source.log | tee doxygenError.txt || true
127     - grep -qi "warning" docs/doxygen/doxygen*log docs/doxygen/check-source.log | tee -a doxygenError.txt || true
128     - if [ -s doxygenError.txt ] ; then echo "Found errors while running doxygen"; exit 1; fi
129   artifacts:
130     name: docs-artifacts-$CI_COMMIT_REF_SLUG
131     when: always
132     expire_in: 1 week
133     paths:
134       - $BUILD_DIR/docs/doxygen/doxygen-xml.log
135       - $BUILD_DIR/docs/doxygen/check-source.log
136
137 linkchecker:
138   extends:
139     - .webpage:build
140     - .rules:nightly-not-for-release
141   stage: nightly-build
142   dependencies:
143     - webpage:build
144   variables:
145     KUBERNETES_CPU_LIMIT: 1
146     KUBERNETES_CPU_REQUEST: 1
147     KUBERNETES_MEMORY_LIMIT: 2Gi
148     BUILD_DIR: build-docs
149   script:
150     - cd $BUILD_DIR
151     - linkchecker docs/html/index.html -f $CI_PROJECT_DIR/docs/linkcheckerrc -Fxml --ignore-url html-full
152       --ignore-url html-user --ignore-url html-lib --ignore-url .tar.gz --ignore-url _sources
153       -o xml
154   artifacts:
155     reports:
156       junit: $BUILD_DIR/linkchecker-out.xml