-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.gitlab-ci-fortran-lib.yml
270 lines (253 loc) · 8.94 KB
/
.gitlab-ci-fortran-lib.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
# { "version": "1.0.0" }
###############################################################################
# Generic GitLab Pipeline for Fortran libraries
#
# To use this template, save in the repo root as .gitlab-ci-fortran-lib.yml and
# create a file .gitlab-ci.yml with the following content (adjust variable values to fit):
#
# variables:
# # Configuration of which OS/compiler combinations should be used
# # Note: Enabled options must explicitly be set to the exact string "On".
# BUILD_INTEL_WINDOWS: "On"
# BUILD_INTEL_LINUX: "On"
# BUILD_NVIDIA_LINUX: "On"
# BUILD_LINUX_GCC: "On"
# # Perform code coverage with Intel compiler? To enable, set to the exact string "On"
# INTEL_CODE_COVERAGE: "On"
#
# include: .gitlab-ci-fortran-lib.yml
#
###############################################################################
# Define stages
stages:
# This stage will build the library and run tests for different OS/compiler combinations
- build-test
# This stage can be run manually for the main branch or release-branches in order to tag
# a release with the version number specified in CMake
- deploy
workflow:
rules:
# Don't run CI for tags (jobs should already have been run for the branch with the commit)
- if: $CI_COMMIT_TAG
when: never
# Run pipeline for branches
- if: $CI_COMMIT_BRANCH
#
# Script components used in multiple jobs
#
.base-setup: &base-setup
# Define bash functions to make sections in the log shown on GitLab
# https://docs.gitlab.com/ee/ci/jobs/#custom-collapsible-sections
- ci_section_start() { echo -e "\e[0Ksection_start:`date +%s`:$1[collapsed=true]\r\e[0K" $2; }
- ci_section_end() { echo -e "\e[0Ksection_end:`date +%s`:$1\r\e[0K"; }
# Replace git urls when cloning dependencies
# Variables SIMA_ACCESS_USER and SIMA_ACCESS_TOKEN is defined CI variables at the group level:
# https://gitlab.sintef.no/groups/sima/-/settings/ci_cd
- git config --global url."https://${SIMA_ACCESS_USER}:${SIMA_ACCESS_TOKEN}@gitlab.sintef.no/".insteadOf "https://gitlab.sintef.no/"
- git config --global url."https://${SIMA_ACCESS_USER}:${SIMA_ACCESS_TOKEN}@gitlab.sintef.no/".insteadOf "[email protected]:"
# Default extra args to CMake configuration (empty)
- export CMAKE_ARGS=""
.intel-linux-setup: &intel-linux-setup
- *base-setup
- export PYTHON=python3.9
- export CODECOV_TO_COBERTURA=/tools/codecov-to-cobertura.py
- |
if [[ $INTEL_CODE_COVERAGE == "On" ]]; then
export CMAKE_ARGS="$CMAKE_ARGS -DCODE_COVERAGE=On"
fi
# Commands to setup environment on Windows with Intel compiler
.intel-windows-setup: &intel-windows-setup
- *base-setup
- ci_section_start setup_env "Setup Build Environment"
# These lines create a batch file which we will run in order to obtain the Intel OneAPI
# environment variables which in turn is written to a file. Then we source this file
# to get the variables into the runner script environment
- |
cat <<EOT > getvars.bat
echo "Load vcvars64"^
&& call "C:/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/VC/Auxiliary/Build/vcvars64.bat"^
&& echo "Load Intel compiler vars"^
&& call "C:/Program Files (x86)/Intel/oneAPI/compiler/2023.1.0/env/vars.bat"^
&& echo "Load Intel MKL vars"^
&& call "C:/Program Files (x86)/Intel/oneAPI/mkl/2023.1.0/env/vars.bat"^
&& echo "Store environment"^
&& bash.exe -c "env > vars.env"
EOT
- cmd.exe //c getvars.bat
# Filter out empty lines, names illegal in bash, GitLab CI variables (they are untouched
# by the above script) and lines from variables containing a newline
- source <(cat vars.env | grep '^[a-zA-Z0-9_]*=.*' | grep -v "^CI_" | sed -e 's:\\:\\\\:g' -e 's:\(.*\):export "\1":')
# - export FC=ifx; export CC=cl; export CXX=cl
- export FC=ifort; export CC=cl; export CXX=cl
- export PYTHON=python.exe
- export CODECOV_TO_COBERTURA=c:/bin/codecov-to-cobertura.py
- |
if [[ $INTEL_CODE_COVERAGE == "On" ]]; then
export CMAKE_ARGS="$CMAKE_ARGS -DCODE_COVERAGE=On"
fi
- ci_section_end setup_env
# Commands to perform code coverage analysis when using the Intel compiler
.intel-codecov: &intel-codecov
- |
cd build/ci/
if [[ $INTEL_CODE_COVERAGE == "On" ]]; then
ci_section_start codecov "Code Coverage Analysis"
cd code-coverage
profmerge
codecov -prj ${CI_PROJECT_NAME} -dpi pgopti.dpi -spi pgopti.spi -xmlbcvrg codecov.xml
$PYTHON $CODECOV_TO_COBERTURA codecov.xml ../../../ ../ code-coverage.xml
cd ../
ci_section_end codecov
else
# Make a dummy code-coverage.xml to avoid that artifact upload fails
mkdir code-coverage
cd code-coverage
touch code-coverage.xml
cd ../
fi
cd ../../
# Commands to build library and run tests
.build-test: &build-test
- ci_section_start configure "Configure build"
- rm -rf build/
- mkdir -p build/ci/ && cd build/ci
- cmake ../../ -DCMAKE_BUILD_TYPE=$BUILD_TYPE $CMAKE_ARGS -G"$GENERATOR"
- ci_section_end configure
- ci_section_start build "Build"
- cmake --build .
- ci_section_end build
- ci_section_start test "Run Tests"
- ctest . -j $(nproc) --output-junit test-report.xml --test-output-size-failed 5242880 --test-output-truncation head
- ci_section_end test
# Commands to process test results after a run of .build-test
.process-tests: &process-tests
- cd build/ci
- |
if [[ -f test-report.xml ]]; then
# Tests have been run
echo "Test report found"
# Monkey-patch CTest's JUnit report to match GitLab expectations. See https://gitlab.kitware.com/cmake/cmake/-/issues/22478#note_1406956
sed -i -e 's:message=""::g' -e 's:message="Failed"::g' -e 's:<system-out>:<system-err>:g' -e 's:</system-out>:</system-err>:g' test-report.xml
fi
- cd ../../
# Commands to extract the version number from a CMake build folder
.get-version-from-cmake: &get-version-from-cmake
- ci_section_start version "Parse version number"
- sed -n 's/^CMAKE_PROJECT_VERSION:.*=\(.*\)$/\1/p' CMakeCache.txt > version.txt
- echo "Library version is $(cat version.txt)"
- ci_section_end version
#
# Define the different pipeline jobs
#
Build & Test Intel Windows:
rules:
- if: $BUILD_INTEL_WINDOWS == "On"
stage: build-test
tags:
- windows
- bash
- intel-fortran
variables:
BUILD_TYPE: RelWithChecks
# Until bug in ifort is fixed, then use Ninja
GENERATOR: NMake Makefiles JOM
script:
- *intel-windows-setup
- *build-test
- *get-version-from-cmake
after_script:
- *intel-windows-setup
- *intel-codecov
- *process-tests
coverage: '/^Code coverage: \d+\.\d+%$/'
artifacts:
paths:
- build/ci/version.txt
reports:
coverage_report:
coverage_format: cobertura
path: build/ci/code-coverage/code-coverage.xml
junit: build/ci/test-report.xml
Build & Test Intel Linux:
rules:
- if: $BUILD_INTEL_LINUX == "On"
stage: build-test
tags:
- linux
image: gitlab.sintef.no:5050/sima/ssrv-operations/intel-compilers:2023.0.0-1
variables:
BUILD_TYPE: RelWithChecks
# Until bug in ifort is fixed, then use Ninja
GENERATOR: Unix Makefiles
script:
- *intel-linux-setup
- *build-test
after_script:
- *intel-linux-setup
- *intel-codecov
- *process-tests
coverage: '/^Code coverage: \d+\.\d+%$/'
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: build/ci/code-coverage/code-coverage.xml
junit: build/ci/test-report.xml
Build & Test NVidia Linux:
rules:
- if: $BUILD_NVIDIA_LINUX == "On"
stage: build-test
tags:
- linux
image: gitlab.sintef.no:5050/sima/ssrv-operations/nvhpc-compilers:22.11-1
variables:
BUILD_TYPE: RelWithChecks
GENERATOR: Ninja
script:
- *base-setup
- *build-test
after_script:
- *base-setup
- *process-tests
artifacts:
reports:
junit: build/ci/test-report.xml
Build & Test Linux GCC:
rules:
- if: $BUILD_LINUX_GCC == "On"
stage: build-test
tags:
- linux
image: gitlab.sintef.no:5050/sima/ssrv-operations/gcc-compilers:13.2.0-1
variables:
BUILD_TYPE: RelWithChecks
GENERATOR: Ninja
script:
- *base-setup
- *build-test
after_script:
- *base-setup
- *process-tests
artifacts:
reports:
junit: build/ci/test-report.xml
Deploy Release:
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_COMMIT_BRANCH =~ /^release\/.*/
stage: deploy
when: manual
tags:
- linux
needs:
- job: Build & Test Intel Windows
artifacts: true
image: registry.gitlab.com/gitlab-org/release-cli:v0.9.0
script:
# Read version information retrieved from CMake and stored in an artifact
- version=$(cat build/ci/version.txt)
- echo "Version is $version"
# This doesn't seem to be used, but just to be sure
- export CI_COMMIT_TAG=$version
# Create release and corresponding git tag
- release-cli create --name "${CI_PROJECT_NAME} $version" --description "Release version $version" --tag-name "v${version}"