-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
298 lines (282 loc) · 10.5 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# SPDX-FileCopyrightText: 2020 W. Traylor <wolfgang.traylor@senckenberg.de>
#
# SPDX-License-Identifier: LGPL-3.0-or-later
stages:
- lint
- build
- test
- postprocess
variables:
# Install packages without user interaction.
DEBIAN_FRONTEND: "noninteractive"
# The documentation and the source code are compiled separately so that the
# pipeline can continue with the unit tests even if doxygen fails.
# Check whether the project is REUSE compliant (https://reuse.software).
check_license:
image:
name: fsfe/reuse:latest
entrypoint: [""]
stage: lint
script:
- reuse lint
# The develop branch should reset the version to "0.0.0" so that there can
# never be a confusion with a released version. Compare CONTRIBUTING.md.
check_develop_version:
image: debian:stable-slim
stage: lint
rules:
# Only execute on tags that look like a version, e.g.: "0.5.1"
- if: '$CI_COMMIT_BRANCH == "develop"'
when: always
script:
- test "0.0.0" == $(grep "^version\s*:" CITATION.cff | grep -oP '\d+\.\d+\.\d+.*')
- grep --silent "^date-released\s*:\s*$" CITATION.cff
- test "0.0.0" == $(grep '"version"' codemeta.json | grep -oP '\d+\.\d+\.\d+')
- grep --silent '"dateModified":\s*""' codemeta.json
- test "0.0.0" == $(grep "^\s*VERSION" CMakeLists.txt | grep -oP '\d+\.\d+\.\d+.*')
# Check that the tag matches the version in the CMakeLists.txt file.
# If the tag doesn’t match, you will need to change CMakeLists.txt and
# forcefully move the tag to the corrected commit.
check_release_version:
image: debian:stable-slim
stage: lint
rules:
# Only execute on tags that look like a release version, e.g., "0.5.1".
# Prerelease versions (e.g., "1.2.0-alpha.1" or "1.2.0-beta.3") are not
# required to have the version as metadata.
- if: '$CI_COMMIT_TAG =~ /^\d+\.\d+\.\d+/'
when: always
script:
- echo "If this fails, check that the Git tag matches VERSION in CMakeLists.txt."
- test "$CI_COMMIT_TAG" == $(grep "^\s*VERSION" CMakeLists.txt | grep -oP '\d+\.\d+\.\d+.*')
- echo "If this fails, check that the Git tag matches version in CITATION.cff"
- test "$CI_COMMIT_TAG" == $(grep "^version\s*:" CITATION.cff | grep -oP '\d+\.\d+\.\d+.*')
- echo "If this fails, check that the Git tag matches version in codemeta.json."
- test "$CI_COMMIT_TAG" == $(grep '"version"' codemeta.json | grep -oP '(?<=")\d+\.\d+\.\d+.*(?=")')
# Check that all files are correctly formatted according to ".clang-format".
# Exclude the "external/" directory because they will use different formatting.
clang-format:
image:
name: mikedld/clang-format:12-latest # Update this to later clang versions as necessary.
entrypoint: [""]
stage: lint
script:
# We need to use simple BusyBox `find` syntax here.
- >
clang-format --dry-run --Werror
$(find src/ -iname '*.cpp' -or -iname '*.h')
$(find docs/ -iname '*.cpp' -or -iname '*.h')
$(find include/ -iname '*.cpp' -or -iname '*.h')
$(find tests/ -iname '*.cpp' -or -iname '*.h')
$(find tools/ -iname '*.cpp' -or -iname '*.h')
compile:
image: gcc:latest
stage: build
before_script:
- apt-get update -qq
- apt-get install -y -qq cmake
script:
- mkdir --parents build
- cp examples/demo_simulation.toml build/
- cd build
- cmake
-DBUILD_TESTING=ON
-DBUILD_DEMO_SIMULATOR=ON
-DBUILD_DOC=OFF ..
- make --jobs=6
megafauna_demo_simulator
megafauna_insfile_linter
megafauna_unit_tests
artifacts:
paths:
- build/demo_results.Rmd
- build/demo_simulation.toml
- build/megafauna.toml
- build/megafauna_demo_simulator
- build/megafauna_insfile_linter
- build/megafauna_unit_tests
expire_in: 20 minutes
# Compare the Sphinx instructions in "docs/sphinx/conf.py".
doxygen:
image: readthedocs/build:latest
stage: build
before_script:
- conda install --yes cmake
- conda install --yes --channel conda-forge doxygen
- PATH=$HOME/.conda/bin:$PATH
script:
- mkdir --parents build
- cd build
- cmake
-DSTOP_DOXYGEN_ON_WARNING=ON
-DBUILD_TESTING=OFF
-DBUILD_DEMO_SIMULATOR=OFF
-DBUILD_DOC=ON ..
- make --jobs=6 megafauna_docs
artifacts:
paths:
- build/docs/html/
unit_tests:
image: gcc:latest
stage: test
needs: ["compile"]
script:
- cd build
- ./megafauna_unit_tests
# Test coverage for codecov.io
# The environment variable "CODECOV_TOKEN" must be provided. Compare:
# <https://docs.codecov.io/docs/about-the-codecov-bash-uploader#upload-token>
# <https://docs.gitlab.com/ce/ci/variables/README.html#project-cicd-variables>
code_coverage:
image: gcc:latest
stage: test
needs: ["compile"]
before_script:
- apt-get update -qq
- apt-get install -y -qq cmake gcovr
script:
- mkdir --parents build
- cd build
- cmake -DBUILD_TESTING=ON -DENABLE_COVERAGE=ON -DBUILD_DOC=OFF ..
- make --jobs=6 megafauna_unit_tests
- ./megafauna_unit_tests
- make --jobs=6 gcov
- bash <(curl -s https://codecov.io/bash) -X gcov
# Check that the linter works and that the example instruction files are
# correct.
linter:
image: gcc:latest
stage: test
needs: ["compile"]
script:
# Create a symbolic link in order to shorten instructions.
- ln -s ./build/megafauna_insfile_linter lint
# GOOD FILES:
- ./lint examples/megafauna.toml
- for f in tests/good_insfiles/*.toml; do ./lint $f; done
- ./lint tests/good_insfiles/legacy_massdensity_per_hft.toml 2>&1 | grep -i 'mass_density_per_hft.*deprecated'
# BAD FILES:
# These checks could be done with the catch framework, too
# (CHECK_THROWS_AS). That would be more flexible than checking for a
# specific error message in STDERR.
# Check *all* bad instruction files:
- for f in tests/bad_insfiles/*.toml; do
echo;
echo $f;
(! ./lint $f);
done
# Check for specific error messages:
# Note that commands that expected to fail need to be executed in a
# subshell like this: `(command || true)`
- (./lint tests/bad_insfiles/breeding_start_ambiguous.toml 2>&1 || true) | grep -iq 'breeding_season\.start.*ambiguous'
- (./lint tests/bad_insfiles/wrong_type_01.toml 2>&1 || true) | grep -iq 'body_mass\.female.*wrong type'
- (./lint tests/bad_insfiles/wrong_type_02.toml 2>&1 || true) | grep -iq 'body_mass\.female.*wrong type'
- (./lint tests/bad_insfiles/wrong_type_03.toml 2>&1 || true) | grep -iq 'output\.text_tables\.tables.*wrong type.*expected array of string'
- (./lint tests/bad_insfiles/wrong_type_04.toml 2>&1 || true) | grep -iq 'expenditure\.components.*wrong type'
- (./lint tests/bad_insfiles/wrong_type_05.toml 2>&1 || true) | grep -iq 'mortality\.factors.*wrong type'
- (./lint tests/bad_insfiles/wrong_type_06.toml 2>&1 || true) | grep -iq 'simulation\.establishment_interval.*wrong type'
- (./lint tests/bad_insfiles/wrong_type_07.toml 2>&1 || true) | grep -iq 'output\.text_tables\.precision.*wrong type'
- (./lint tests/bad_insfiles/wrong_type_08.toml 2>&1 || true) | grep -iq 'body_mass\.female.*wrong type'
- (./lint tests/bad_insfiles/two_groups_with_same_name.toml 2>&1 || true) | grep -iq 'group.*is defined twice'
- (./lint tests/bad_insfiles/two_hfts_with_same_name.toml 2>&1 || true) | grep -iq 'HFT.*is defined twice'
memcheck:
image: gcc:latest
stage: test
needs: ["compile"]
before_script:
- apt-get update -qq
- apt-get install -y -qq valgrind
script:
- cd build
# Only run two years:
- sed -e 's/^\s*years\s*=.*/years = 2/' --in-place
demo_simulation.toml
# The following command needs to be quoted as a whole so that the YAML
# parser does not interpret the "|" special character.
- "valgrind
--leak-check=full
--show-leak-kinds=all
--track-origins=yes
--verbose
./megafauna_demo_simulator
megafauna.toml
demo_simulation.toml
| tee memcheck.log"
# If the error summary has not zero errors, the grep command will fail.
# Note that the "!" doesn’t work without starting a subshell with
# parentheses. Compare <https://stackoverflow.com/a/53753605>.
- "(! grep --silent 'ERROR SUMMARY: 0 errors' memcheck.log)"
artifacts:
paths:
- build/memcheck.log
demo_toml_files:
image: gcc:latest
stage: test
needs: ["compile"]
script:
- (! ./build/megafauna_demo_simulator
"tests/good_insfiles/two_hfts_01.toml"
"tests/bad_demosim_insfiles/habitats_not_multiple_of_hfts_01.toml");
- "rm -f *.tsv"
# Without HFTs, the option "one_hft_per_habitat" has no effect.
- ./build/megafauna_demo_simulator
"tests/good_insfiles/no_hfts_02.toml"
"tests/bad_demosim_insfiles/habitats_not_multiple_of_hfts_01.toml";
- "rm -f *.tsv"
- (! ./build/megafauna_demo_simulator
"good_insfiles/two_hfts_01.toml"
"tests/bad_demosim_insfiles/habitats_not_multiple_of_hfts_02.toml");
- "rm -f *.tsv"
- ./build/megafauna_demo_simulator
"tests/good_insfiles/two_hfts_01.toml"
"tests/good_demosim_insfiles/habitats_is_multiple_of_hfts_01.toml";
- "rm -f *.tsv"
# A simulation should run without HFTs and still produce (non-herbivore)
# output.
- ./build/megafauna_demo_simulator
"tests/good_insfiles/no_hfts_01.toml"
"tests/good_demosim_insfiles/minimal.toml";
- test -f available_forage.tsv
- test -f digestibility.tsv
- (! test -f body_fat.tsv)
- (! test -f eaten_forage_per_ind.tsv)
- (! test -f eaten_nitrogen_per_ind.tsv)
- (! test -f individual_density.tsv)
- (! test -f mass_density.tsv)
demo_simulation:
image: gcc:latest
stage: test
needs: ["compile"]
script:
- cd build
- ./megafauna_demo_simulator
"megafauna.toml"
"demo_simulation.toml"
artifacts:
paths:
- build/demo_results.Rmd
# All output files necessary for plotting demo results:
- build/available_forage.tsv
- build/body_fat.tsv
- build/digestibility.tsv
- build/eaten_forage_per_ind.tsv
- build/eaten_nitrogen_per_ind.tsv
- build/individual_density.tsv
- build/mass_density.tsv
expire_in: 20 minutes
plot_demo_results:
# This job should match the quickstart guide in the README.md.
image: r-base:latest
stage: postprocess
needs: ["demo_simulation"]
before_script:
- apt-get update -qq
- apt-get install -y -qq pandoc
- Rscript -e 'install.packages("rmarkdown")'
script:
- cd build
- Rscript -e "rmarkdown::render('demo_results.Rmd')"
- test -f "demo_results.html"
artifacts:
paths:
- build/demo_results.html