-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy path.gitlab-ci.yml
323 lines (288 loc) · 9.67 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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# Change pip's cache directory to be inside the project directory since we can
# only cache local items.
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
PIP_DEPENDENCIES: "sphinx ruamel.yaml"
GIT_DEPTH: 1 # Create a shallow copy
BOT_NAME: "GitLab Runner Bot" # Bot's name that appears in the commit log
BOT_EMAIL: "[email protected]" # Bot's email, not important
# Pip's cache doesn't store the python packages
# https://pip.pypa.io/en/stable/reference/pip_install/#caching
#
# If you want to also cache the installed packages, you have to install
# them in a virtualenv and cache it as well.
cache:
paths:
- .cache/pip
stages:
- prepare
- build
- tests
- deploy
dependencies:
stage: prepare
script:
- python3.11 -V # Print out python version for debugging
# Dependencies:
- pip3 install $PIP_DEPENDENCIES
# Checking installed packages and their versions
- pip3 list
# PATH required for tests
- export PYTHONPATH=${CI_PROJECT_DIR}/jube:${PYTHONPATH}
.clone_repo: &clone_repo
before_script:
# Cloning to a new folder to avoid caching issues
- rm -r "${CI_PROJECT_DIR}/${CI_JOB_NAME#*:}" || true
- cd ${CI_PROJECT_DIR}
- git clone https://gitlab-ci-token:${GIT_PUSH_TOKEN}@${CI_REPOSITORY_URL#*@} "${CI_JOB_NAME#*:}"
# Using bot information
- git config pull.rebase false
- git config --global user.name "${BOT_NAME}"
- git config --global user.email "${BOT_EMAIL}"
# Changing cloned repo to current branch
- cd "${CI_JOB_NAME#*:}"
- git checkout ${CI_COMMIT_BRANCH}
.push_files: &push_files
<<: *clone_repo
after_script:
- cd "${CI_PROJECT_DIR}/${CI_JOB_NAME#*:}"
- git status
# Add list of files and commit, if there are changes
- |
if [[ -z $(git status --untracked-files=no --porcelain) ]]
then
echo "Nothing to commit"
else
git diff
git add ${FILE_LIST}
git commit -m "${COMMIT_MESSAGE} (Runner ID:${CI_RUNNER_ID})"
git push -o ci.skip https://gitlab-ci-token:${GIT_PUSH_TOKEN}@${CI_REPOSITORY_URL#*@}
fi
# Cleaning up
- cd ${CI_PROJECT_DIR}
- rm -r "${CI_PROJECT_DIR}/${CI_JOB_NAME#*:}"
build:year:
variables:
FILE_LIST: -u
COMMIT_MESSAGE: "Updating Year"
stage: build
script:
# Updating all Copyright years
- find ${CI_PROJECT_DIR}/${CI_JOB_NAME#*:} -type f -exec sed -i "s/Copyright (C) 2008-[0-9]\{4\}/Copyright (C) 2008-`date +%Y`/g" {} \;
# Updating years on documentation
- sed -i "s/[0-9]\{4\}, JUBE Developer Team/`date +%Y`, JUBE Developer Team/g" ${CI_PROJECT_DIR}/${CI_JOB_NAME#*:}/docs/conf.py
<<: *push_files
rules:
- if: '$CI_COMMIT_BRANCH == "master"' # Only on the master branch
resource_group: gitpush
build:version:
variables:
FILE_LIST: jube/conf.py docs/conf.py setup.py
COMMIT_MESSAGE: "Updating Version"
stage: build
script:
- export RELEASE=`grep -o -m1 -P "Version \d.\d.\d(-[^ ]+)?" docs/release_notes.rst | cut -d " " -f2`
- export VERSION=${RELEASE%.*}
- |
echo "Last version on docs/release_notes.rst: ${RELEASE}"
# Updating version in files
- |
sed -i "s/'version': '.*'/'version': '${RELEASE}'/g" ${CI_PROJECT_DIR}/${CI_JOB_NAME#*:}/setup.py
- sed -i "s/JUBE_VERSION = \".*\"/JUBE_VERSION = \"${RELEASE}\"/g" ${CI_PROJECT_DIR}/${CI_JOB_NAME#*:}/jube/conf.py
- sed -i "s/version = '.*'/version = '${VERSION}'/g" ${CI_PROJECT_DIR}/${CI_JOB_NAME#*:}/docs/conf.py
- sed -i "s/release = '.*'/release = '${RELEASE}'/g" ${CI_PROJECT_DIR}/${CI_JOB_NAME#*:}/docs/conf.py
<<: *push_files
rules:
- if: '$CI_COMMIT_BRANCH == "master"' # Only on the master branch
changes:
- docs/release_notes.rst
resource_group: gitpush
build:release_notes:
variables:
FILE_LIST: RELEASE_NOTES
COMMIT_MESSAGE: "Updating $FILE_LIST"
stage: build
script:
- cd "${CI_PROJECT_DIR}/${CI_JOB_NAME#*:}/docs"
- make update_release
<<: *push_files
rules:
- if: '$CI_COMMIT_BRANCH == "master"' # Only on the master branch
changes:
- docs/release_notes.rst
resource_group: gitpush
build:help:
variables:
FILE_LIST: jube/help.txt
COMMIT_MESSAGE: "Updating $FILE_LIST"
stage: build
script:
- cd "${CI_PROJECT_DIR}/${CI_JOB_NAME#*:}/docs"
- make update_help
<<: *push_files
rules:
- if: '$CI_COMMIT_BRANCH == "master"' # Only on the master branch
changes:
- docs/glossar.rst
resource_group: gitpush
build:pdf:
variables:
FILE_LIST: docs/JUBE.pdf
COMMIT_MESSAGE: "Updating $FILE_LIST"
stage: build
script:
- cd "${CI_PROJECT_DIR}/${CI_JOB_NAME#*:}/docs"
- make latexpdf
<<: *push_files
rules:
- if: '$CI_COMMIT_BRANCH == "master"' # Only on the master branch
changes:
- docs/**/* # all files under folder 'docs'
resource_group: gitpush
build:site:
stage: build
script:
- cd docs
- make html
artifacts:
paths:
- docs/_build/html
rules:
- if: $CI_PIPELINE_SOURCE != 'merge_request_event'
changes:
- docs/**/* # all files under folder 'docs'
.test_make: &test_make
stage: tests
script:
- cd "${CI_PROJECT_DIR}/docs"
- make ${COMMAND} 2>&1 | tee output
- if [[ ! -z $(grep "ERROR" output) ]] ; then echo "Errors in the output" ; exit 21 ; fi
tests:release_notes:
variables:
COMMAND: update_release
<<: *test_make
rules:
- changes:
- docs/release_notes.rst
tests:help:
variables:
COMMAND: update_help
<<: *test_make
rules:
- changes:
- docs/glossar.rst
tests:pdf:
variables:
COMMAND: latexpdf
<<: *test_make
rules:
- changes:
- docs/**/* # all files under folder 'docs'
tests:site:
variables:
COMMAND: html
<<: *test_make
rules:
- changes:
- docs/**/* # all files under folder 'docs'
.run_test: &run_test
stage: tests
script:
- cd ${CI_PROJECT_DIR}/tests/
- export PYTHONPATH=${CI_PROJECT_DIR}:${PYTHONPATH}
- python3.11 ${CI_JOB_NAME#*:}.py 2>&1 | tee output
- if [[ ! -z $(grep "Warning\|warning" output) ]] ; then echo "Warnings in the output" ; exit 21 ; fi
allow_failure:
exit_codes: 21
tests:parameter_tests:
<<: *run_test
tests:multiprocessing_tests:
<<: *run_test
tests:pattern_tests:
<<: *run_test
tests:benchmark_tests:
<<: *run_test
tests:result_database_tests:
<<: *run_test
tests:examples_tests:
<<: *run_test
tests:yaml_tests:
<<: *run_test
tests:xml_tests:
<<: *run_test
tests:step_tests:
<<: *run_test
tests:util_tests:
<<: *run_test
tests:conf_tests:
<<: *run_test
tests:substitute_tests:
<<: *run_test
deploy:dist_package:
stage: deploy
<<: *clone_repo
script:
- cd "${CI_PROJECT_DIR}/${CI_JOB_NAME#*:}"
- git status
# Creating distribution package tarball
- python3.11 setup.py sdist
after_script:
- echo "Copying distribution package to web server"
- cd "${CI_PROJECT_DIR}/${CI_JOB_NAME#*:}"
- "sshpass -e -P 'passphrase for key' rsync -rlgoDzP --del dist/* apps_jube_docu:software/"
# Cleaning up
- cd ${CI_PROJECT_DIR}
- rm -r "${CI_PROJECT_DIR}/${CI_JOB_NAME#*:}"
artifacts:
paths:
- ${CI_PROJECT_DIR}/${CI_JOB_NAME#*:}/dist/*
rules:
- if: $CI_COMMIT_TAG =~ /^REL-.*/
deploy:download_page:
stage: deploy
needs:
- deploy:dist_package
before_script:
- echo "Getting 'download.php' from web server"
- "sshpass -e -P 'passphrase for key' rsync -rlgoDzP apps_jube_get_download_file:download.php ./"
script:
- export RELEASE=${CI_COMMIT_TAG#*-}
- sed -i "s/^\$current_version = \"[0-9].[0-9].[0-9]\";/\$current_version = \"${RELEASE}\";/" download.php
- sed -i "s/^\$versions = array(\(.*\));$/\$versions = array(\1,\"${RELEASE}\");/" download.php
- sed -i "s/^\$published_versions = array(/\$published_versions = array(\"${RELEASE}\",/" download.php
- echo ${RELEASE} > version
after_script:
- echo "Copying distribution package to web server"
- "sshpass -e -P 'passphrase for key' rsync -rlgoDzP --del download.php version apps_jube_docu:"
rules:
- if: $CI_COMMIT_TAG =~ /^REL-.*/
pages:
stage: deploy
needs:
- build:site
script:
- mkdir -p public
- cp -r docs/_build/html/* public/
artifacts:
paths:
- public
rules:
- if: $CI_PIPELINE_SOURCE != 'merge_request_event'
changes:
- docs/**/* # all files under folder 'docs'
pages:production:
stage: deploy
needs:
- build:site
rules:
- if: '$CI_COMMIT_BRANCH == "master"' # Only on the master branch
when: manual # Manually triggered
changes:
- docs/**/* # all files under folder 'docs'
- if: $CI_COMMIT_TAG =~ /^REL-.*/
script:
- echo "Deploying to production"
- "sshpass -e -P 'passphrase for key' rsync -rlgoDzP --del docs/_build/html/* apps_jube_docu:docu/"
environment:
name: production
url: https://apps.fz-juelich.de/jsc/jube/docu/