Make sure CI script can call /bin/env python`
[alexxy/gromacs.git] / admin / gitlab-ci / lint.gitlab-ci.yml
1 # Repository cleanliness. Source tidiness, linting, and policy compliance.
2
3 clang-tidy:configure-push:
4   extends:
5     - .gromacs:base:configure
6     - .use-clang:base
7     - .rules:basic-push
8   image: gromacs/cmake-3.15.7-llvm-9-openmpi:master
9   variables:
10     COMPILER_MAJOR_VERSION: 9
11     BUILD_DIR: build-clang-tidy
12     CMAKE_EXTRA_OPTIONS: -DCLANG_TIDY=clang-tidy-$COMPILER_MAJOR_VERSION -DGMX_CLANG_TIDY=ON -DGMX_COMPILER_WARNINGS=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
13
14 clang-tidy:configure-schedule:
15   extends:
16     - .gromacs:base:configure
17     - .use-clang:base
18     - .rules:nightly-not-for-release
19   image: gromacs/cmake-3.15.7-llvm-9-openmpi:master
20   variables:
21     COMPILER_MAJOR_VERSION: 9
22     BUILD_DIR: build-clang-tidy
23     CMAKE_EXTRA_OPTIONS: -DCLANG_TIDY=clang-tidy-$COMPILER_MAJOR_VERSION -DGMX_CLANG_TIDY=ON -DGMX_COMPILER_WARNINGS=ON
24
25 clang-tidy:build:
26   extends:
27     - .gromacs:base:build
28     - .use-ccache
29     - .variables:default
30     - .rules:nightly-not-for-release
31   stage: source-check
32   image: gromacs/cmake-3.15.7-llvm-9-openmpi:master
33   needs:
34     - job: clang-tidy:configure-schedule
35   variables:
36     BUILD_DIR: build-clang-tidy
37
38 clang-tidy:test:
39   extends:
40     - .gromacs:base:build
41     - .variables:default
42     - .rules:basic-push
43   stage: source-check
44   image: gromacs/cmake-3.15.7-llvm-9-openmpi:master
45   needs:
46     - job: clang-tidy:configure-push
47   variables:
48     COMPILER_MAJOR_VERSION: 9
49     BUILD_DIR: build-clang-tidy
50     EXTRA_INSTALLS: clang-tidy-$COMPILER_MAJOR_VERSION
51     KUBERNETES_CPU_LIMIT: 4
52     KUBERNETES_CPU_REQUEST: 2
53     KUBERNETES_MEMORY_REQUEST: 4Gi
54   script:
55     # Make sure that a Python interpreter can be found for `/bin/env python`
56     - test -x /usr/bin/python || update-alternatives --install /usr/bin/python python /usr/bin/python3 1
57     # TODO (issue #3272) `master` is not appropriate for use on release-xxxx branches, how should we handle that?
58     - REV=$(git fetch -q https://gitlab.com/gromacs/gromacs.git master && git show -s --pretty=format:"%h" `git merge-base FETCH_HEAD HEAD`)
59     - HEAD_REV=$(git show -s --pretty=format:"%h" HEAD)
60     - if [[ "$REV" == "$HEAD_REV" ]] ; then
61         REV="HEAD~1" ;
62       fi
63     - echo "Revision used for branch point is $REV"
64     - git show -s $REV
65     - RUN_CLANG_TIDY=run-clang-tidy-$COMPILER_MAJOR_VERSION bash admin/clang-tidy.sh check --parallel=$KUBERNETES_CPU_LIMIT --warnings=clang-tidy.log --rev=$REV -B=$BUILD_DIR
66     - grep -i "found code issues" clang-tidy.log | tee code-lint.txt || true
67     - if [ -s code-lint.txt ] ; then echo "clang-tidy.sh found issues"; exit 1; fi
68   artifacts:
69     when: on_failure
70     paths:
71       - clang-tidy.log
72       - code-lint.txt
73
74 clang-format:
75   extends:
76     - .variables:default
77     - .rules:basic-push
78   cache: {}
79   stage: pre-build
80   image: gromacs/ci-docs-llvm:master
81   variables:
82     COMPILER_MAJOR_VERSION: 7
83     KUBERNETES_CPU_LIMIT: 1
84     KUBERNETES_CPU_REQUEST: 1
85     KUBERNETES_MEMORY_REQUEST: 2Gi
86     EXTRA_INSTALLS: clang-format-$COMPILER_MAJOR_VERSION
87   script:
88     # TODO (issue #3272) `master` is not appropriate for use on release-xxxx branches, how should we handle that?
89     - REV=$(git fetch -q https://gitlab.com/gromacs/gromacs.git master && git show -s --pretty=format:"%h" `git merge-base FETCH_HEAD HEAD`)
90     - HEAD_REV=$(git show -s --pretty=format:"%h" HEAD)
91     - if [[ "$REV" == "$HEAD_REV" ]] ; then
92         REV="HEAD~1" ;
93       fi
94     - echo "Revision used for branch point is $REV"
95     - git show -s $REV
96     - CLANG_FORMAT=clang-format-$COMPILER_MAJOR_VERSION admin/clang-format.sh check --rev=$REV --warnings=clang-format.log
97     - grep -i "needs formatting" clang-format.log | tee formatting.txt || true
98     - if [ -s formatting.txt ] ; then echo "clang-format.sh found issues"; exit 1; fi
99   artifacts:
100     when: on_failure
101     paths:
102       - clang-format.log
103       - formatting.txt
104
105 copyright-check:
106   extends:
107     - .variables:default
108     - .rules:basic-push
109   cache: {}
110   stage: pre-build
111   image: gromacs/ci-docs-llvm:master
112   variables:
113     KUBERNETES_CPU_LIMIT: 1
114     KUBERNETES_CPU_REQUEST: 1
115     KUBERNETES_MEMORY_REQUEST: 2Gi
116   script:
117     # TODO (issue #3272) `master` is not appropriate for use on release-xxxx branches, how should we handle that?
118     - REV=$(git fetch -q https://gitlab.com/gromacs/gromacs.git master && git show -s --pretty=format:"%h" `git merge-base FETCH_HEAD HEAD`)
119     - HEAD_REV=$(git show -s --pretty=format:"%h" HEAD)
120     - if [[ "$REV" == "$HEAD_REV" ]] ; then
121         REV="HEAD~1" ;
122       fi
123     - echo "Revision used for branch point is $REV"
124     - git show -s $REV
125     - admin/copyright.sh check --rev=$REV --warnings=copyright.log
126     - grep -i "copyright year" copyright.log | tee years.log || true
127     - grep -i "copyright header" copyright.log | tee headers.log || true
128     - if [[ -s years.log || -s headers.log ]] ; then
129       echo "Copyright information needs updating" ;
130       exit 1 ;
131       fi
132   artifacts:
133     when: on_failure
134     paths:
135       - copyright.log
136       - years.log
137       - headers.log
138
139 check-source:
140   extends:
141     - .variables:default
142     - .docs:build
143     - .before_script:default
144     - .rules:basic-push
145   cache: {}
146   stage: source-check
147   needs:
148     - job: docs:build
149       artifacts: true
150   variables:
151     KUBERNETES_CPU_LIMIT: 1
152     KUBERNETES_CPU_REQUEST: 1
153     KUBERNETES_MEMORY_REQUEST: 2Gi
154     BUILD_DIR: build-docs
155   script:
156     - cd $BUILD_DIR
157     - cmake --build . --target check-source
158     - awk '/warning.*include style.*order/,/You can use.*rst|^$/' docs/doxygen/check-source.log | tee doxygenError.txt || true
159     - awk '/warning:.*includes/,/unnecessarily|^$/' docs/doxygen/check-source.log | tee -a doxygenError.txt || true
160     - awk '/Traceback/,/.*rror|^$/' docs/doxygen/doxygen*log docs/doxygen/check-source.log | tee -a doxygenError.txt || true
161     - awk '/warning:/,/in doxygen.*|^$/' docs/doxygen/doxygen*log | tee -a doxygenError.txt || true
162     - grep -i "unused cycle suppression" docs/doxygen/check-source.log | tee -a doxygenError.txt || true
163     - if [ -s doxygenError.txt ] ; then echo "Found errors while running doxygen"; exit 1; fi
164   artifacts:
165     name: docs-artifacts-$CI_COMMIT_REF_SLUG
166     when: always
167     expire_in: 1 week
168     paths:
169       - $BUILD_DIR/docs/doxygen/doxygen-xml.log
170       - $BUILD_DIR/docs/doxygen/check-source.log
171
172 linkchecker:
173   extends:
174     - .webpage:build
175     - .rules:nightly-not-for-release
176   stage: nightly-build
177   dependencies:
178     - webpage:build
179   variables:
180     KUBERNETES_CPU_LIMIT: 1
181     KUBERNETES_CPU_REQUEST: 1
182     KUBERNETES_MEMORY_REQUEST: 2Gi
183     BUILD_DIR: build-docs
184   script:
185     - cd $BUILD_DIR
186     - linkchecker docs/html/index.html -f $CI_PROJECT_DIR/docs/linkcheckerrc -Fxml --ignore-url html-full
187       --ignore-url html-user --ignore-url html-lib --ignore-url .tar.gz --ignore-url _sources
188       -o xml
189   artifacts:
190     reports:
191       junit: $BUILD_DIR/linkchecker-out.xml