-
Notifications
You must be signed in to change notification settings - Fork 40
/
.gitlab-ci.yml
256 lines (231 loc) · 8.08 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
image: mambaorg/micromamba
stages:
- test
- deploy
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
# Templates
# NOTE on rules: Rules are evaluated in order until the first match. When a match is
# found, the job is either included or excluded from the pipeline, depending on
# the configuration.
.test_template:
stage: test
variables:
CONDA_PKGS_DIRS: "$CI_PROJECT_DIR/.cache/pkgs"
cache:
key:
files:
- requirements_dev.yml
- .gitlab-ci.yml
prefix: ${CI_JOB_NAME}
paths:
# Cache dir needs to be in project dir
- ".cache/pkgs"
policy: pull
before_script:
- micromamba install -n base -y --file=requirements_dev.yml
- python -m pip install --no-deps .
rules:
# Switch from branch pipeline to merge pipeline once a merge request has
# been created on the branch.
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == "push"
when: never
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_COMMIT_TAG
when: never
retry: 1
.test_docker_template_noupdate:
stage: test
image: jugit-registry.fz-juelich.de/iek-3/shared-code/fine/fine-dev:latest
before_script:
- python -m pip install --no-deps -e .
rules:
# Do not run for pushes to master or develop and for merge requests to master
- if: $CI_COMMIT_BRANCH == "master"
when: never
- if: $CI_COMMIT_BRANCH == "develop"
when: never
- if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"
when: never
# Switch from branch pipeline to merge pipeline once a merge request has
# been created on the branch.
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == "push"
when: never
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- changes:
- pyproject.toml
- requirements.yml
- requirements_dev.yml
when: never
- if: $CI_COMMIT_TAG
when: never
- when: on_success
.test_docker_template:
stage: test
image: jugit-registry.fz-juelich.de/iek-3/shared-code/fine/fine-dev:latest
variables:
CONDA_PKGS_DIRS: "$CI_PROJECT_DIR/.cache/pkgs"
cache:
key:
files:
- requirements_dev.yml
- .gitlab-ci.yml
prefix: ${CI_JOB_NAME}
paths:
# Cache dir needs to be in project dir
- ".cache/pkgs"
policy: pull
before_script:
- micromamba install -n base -y --file=requirements_dev.yml
- python -m pip install --no-deps .
rules:
# Do not run for pushes to master or develop and for merge requests to master
- if: $CI_COMMIT_BRANCH == "master"
when: never
- if: $CI_COMMIT_BRANCH == "develop"
when: never
- if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"
when: never
# Switch from branch pipeline to merge pipeline once a merge request has
# been created on the branch.
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == "push"
when: never
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_COMMIT_TAG
when: never
- changes:
- pyproject.toml
- requirements.yml
- requirements_dev.yml
when: on_success
.build_template:
stage: deploy
image: docker@sha256:c8bb6fa5388b56304dd770c4bc0478de81ce18540173b1a589178c0d31bfce90
services:
- docker:dind@sha256:c8bb6fa5388b56304dd770c4bc0478de81ce18540173b1a589178c0d31bfce90
# Tests
test-pypi:
stage: test
script:
- micromamba install -c conda-forge -n base -y python=3.10 glpk gdal
- python -m pip install .[develop]
- python -m pytest -n auto test/
rules:
- if: $CI_COMMIT_TAG
when: never
- if: '$CI_COMMIT_BRANCH == "master"'
- if: '$CI_COMMIT_BRANCH == "develop"'
- if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
- if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "develop"'
test-code:
extends: .test_template
script:
- python -m pytest -n auto --cov=fine test/
rules:
# Run only for pushes to master or develop and for merge requests to master.
# Do not run for scheduled pushes to master (runs `test-code-push-cache` instead).
- if: '$CI_PIPELINE_SOURCE == "schedule" && $CI_COMMIT_BRANCH == "master"'
when: never
- if: '$CI_COMMIT_BRANCH == "master"'
- if: '$CI_COMMIT_BRANCH == "develop"'
- if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
test-code-push-cache:
extends: .test_template
cache:
policy: push
script:
- python -m pytest -n auto --cov=fine test/
rules:
# Run only for scheduled pushes to master.
- if: '$CI_PIPELINE_SOURCE == "schedule" && $CI_COMMIT_BRANCH == "master"'
test-code-docker:
extends: .test_docker_template
script:
- python -m pytest -n auto --cov=fine test/
test-code-docker-noupdate:
extends: .test_docker_template_noupdate
script:
- python -m pytest -n auto --cov=fine test/
test-notebooks:
extends: .test_template
script:
# Run nbval to test all notebooks in examples folder and show 20 longest
# cell executing durations. With 'nbval-lax', notebooks are only tested for
# execution errors Cells tagged 'nbval-check-output' are checked for
# consistent output Cells tagged 'nbval-skip' are skipped.
- python -m pytest -n auto --dist loadscope --nbval-lax --nbval-current-env --durations=20 examples/
rules:
# Run only for pushes to master or develop and for merge requests to master.
- if: '$CI_COMMIT_BRANCH == "master"'
- if: '$CI_COMMIT_BRANCH == "develop"'
- if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"'
test-notebooks-docker:
extends: .test_docker_template
script:
- python -m pytest -n auto --dist loadscope --nbval-lax --nbval-current-env --durations=20 examples/
test-notebooks-docker-noupdate:
extends: .test_docker_template_noupdate
script:
- python -m pytest -n auto --dist loadscope --nbval-lax --nbval-current-env --durations=20 examples/
test-codestyle:
stage: test
image: registry.gitlab.com/pipeline-components/ruff:latest
script:
# Run ruff check. If the code needs reformatting this test will fail.
- ruff version
- ruff check --output-format=gitlab fine
- ruff check --output-format=gitlab test
# - ruff check --output-format=gitlab examples
rules:
# Switch from branch pipeline to merge pipeline once a merge request has
# been created on the branch.
- if: $CI_COMMIT_TAG
when: never
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == "push"
when: never
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- when: on_success
# Deployment
build-tag:
extends: .build_template
script:
- docker login -u fzjiek3 -p $DOCKER_AT
- docker build -t fzjiek3/fine:${CI_COMMIT_TAG} -t fzjiek3/fine:latest .
- docker push fzjiek3/fine --all-tags
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_COMMIT_TAG
# Push develop build to local jugit registry
build-dev:
extends: .build_template
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- export DEV_TAG=jugit-registry.fz-juelich.de/iek-3/shared-code/fine/fine-dev:${CI_COMMIT_SHA}
- docker build -t $DEV_TAG -t "jugit-registry.fz-juelich.de/iek-3/shared-code/fine/fine-dev:latest" .
- docker push $DEV_TAG
- docker push jugit-registry.fz-juelich.de/iek-3/shared-code/fine/fine-dev:latest
rules:
- if: $CI_COMMIT_BRANCH == "develop"
pypi-upload:
stage: deploy
image: python:3.12
before_script:
- python3 -m pip install --upgrade build
- python3 -m pip install --upgrade twine
script:
# Test if the version defined in `pyproject.toml` is the same as the tag
- PYPROJECT_VERSION=$(grep -m 1 version pyproject.toml | tr -s ' ' | tr -d '"' | tr -d "'" | cut -d' ' -f3)
- echo v${PYPROJECT_VERSION}
- echo ${CI_COMMIT_TAG}
- test v${PYPROJECT_VERSION} = ${CI_COMMIT_TAG}
# Build and push to pypi
- python3 -m build
- python3 -m twine upload --repository pypi --non-interactive --verbose --disable-progress-bar dist/*
rules:
- if: $CI_COMMIT_TAG