-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
226 lines (206 loc) · 6.89 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
# SPDX-FileCopyrightText: 2023 Dennis Gläser <dennis.glaeser@iws.uni-stuttgart.de>
# SPDX-License-Identifier: GPL-3.0-or-later
stages:
- checks
- test
- reporting
- coverage
- documentation
- pages
- deploy
- release
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: '$CI_COMMIT_BRANCH =~ /^(main|releases\/)/'
default:
image: python:3.10
cache:
paths:
- .cache/pip
.regular_job_rules:
rules:
- if: $FIELDCOMPARE_RELEASE_VERSION
when: never
- when: on_success
.deploy_job_rules:
rules:
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $FIELDCOMPARE_RELEASE_VERSION == null'
.release_job_rules:
rules:
- if: '$FIELDCOMPARE_RELEASE_VERSION =~ /^([0-9]{1,2}.)?([0-9]{1,2}.)?([0-9]+)?(-.*)?$/ && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && ( $CI_PIPELINE_SOURCE == "pipeline" || $CI_PIPELINE_SOURCE == "trigger" )'
.install_dependencies:
extends: .regular_job_rules
before_script:
- python --version
- pip install --upgrade pip
- pip install tox
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
PY_VERSION: "3.10"
checks:
stage: checks
image: python:$PY_VERSION
script:
- py_fieldcompare_version=$(grep -m 1 "version" pyproject.toml | tr -s ' ' | tr -d '"' | tr -d "'" | cut -d' ' -f3)
- cff_fieldcompare_version=$(grep -m 1 "^version" CITATION.cff | tr -s ' ' | tr -d '"' | tr -d "'" | cut -d' ' -f2)
- docs_fieldcompare_version=$(python3 -c "import sys, os; sys.path.insert(0, os.path.abspath('docs/source')); import conf; print(conf.release)")
- |
if [[ "$py_fieldcompare_version" != "$cff_fieldcompare_version" ]]; then
echo "Version string in pyproject.toml and CITATION.cff is not matching. Did you forget updating?"
exit 1
fi
if [[ "$py_fieldcompare_version" != "$docs_fieldcompare_version" ]]; then
echo "Version string in pyproject.toml and docs/source/conf.py is not matching. Did you forget updating?"
exit 1
fi
check-reuse-compliance:
stage: checks
image: python:$PY_VERSION
script:
- pip install reuse
- reuse lint
test:
stage: test
extends: .install_dependencies
image: python:$PY_VERSION
artifacts:
reports:
junit: test_report.xml
script:
- env=${PY_VERSION//./}
- tox -e py${env:0:3}
parallel:
matrix:
- PY_VERSION: ["3.8", "3.9", "3.10", "3.11", "3.12"]
file_mode_junit_report:
stage: reporting
extends: .install_dependencies
image: python:3.10
script:
- pip install -r requirements.txt
- pip install .
- fieldcompare file test/data/test_mesh.vtu test/data/test_mesh.vtu --exclude-fields "function" --junit-xml file_mode_junit.xml
artifacts:
reports:
junit: file_mode_junit.xml
dir_mode_junit_report:
stage: reporting
extends: .install_dependencies
image: python:3.10
script:
- pip install -r requirements.txt
- pip install .
- fieldcompare dir test/data/ test/data/ --include-files "*.vtu" --junit-xml dir_mode_junit.xml
artifacts:
reports:
junit: dir_mode_junit.xml
test_coverage_report:
stage: coverage
extends: .install_dependencies
script:
- tox -e coverage
coverage: '/TOTAL.*\s([.\d]+)%/'
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
paths:
- cov_report
expire_in: 30 minutes
build_docs:
stage: documentation
extends: .install_dependencies
script:
- pip install sphinx==7.1.2 myst_parser pydata-sphinx-theme -r requirements.txt
- cd docs
- sphinx-apidoc -f -o build ../
- make html
artifacts:
paths:
- docs/build
expire_in: 30 minutes
pages:
stage: pages
extends: .deploy_job_rules
needs:
- job: test_coverage_report
artifacts: true
- job: build_docs
artifacts: true
script:
- mkdir -p public/coverage
- mv cov_report/* public/coverage/
- mv docs/build/html/* public/
artifacts:
paths:
- public
expire_in: 30 minutes
pypi:
stage: deploy
extends: .deploy_job_rules
script:
- echo "Check if fieldcompare version increased since the last release tag..."
- |
python -m pip install .
python -c "import fieldcompare; print(fieldcompare.__version__)" > current_fieldcompare_version.txt
echo "Current version: $(cat current_fieldcompare_version.txt)"
python -m pip uninstall --yes fieldcompare
- git fetch --tags
- git checkout $(git describe --tags $(git rev-list --tags --max-count=1))
- git status
- |
python -m pip install .
python -c "import fieldcompare; print(fieldcompare.__version__)" > old_fieldcompare_version.txt
echo "Last tag: $(cat old_fieldcompare_version.txt)"
python -m pip uninstall --yes fieldcompare
- git checkout $CI_COMMIT_SHA
- |
if ! cmp -s current_fieldcompare_version.txt old_fieldcompare_version.txt; then
FIELDCOMPARE_RELEASE_VERSION=$(cat current_fieldcompare_version.txt | xargs echo)
if [[ "$FIELDCOMPARE_RELEASE_VERSION" =~ ^([0-9]{1,2}.)?([0-9]{1,2}.)?([0-9]+)?(-.*)?$ ]]; then
echo "Build fieldcompare package and upload to PyPI..."
python -m pip install --upgrade build twine
python -m build
python -m twine upload dist/*
echo "Trigger release tag $FIELDCOMPARE_RELEASE_VERSION"
curl --request POST --retry 2 \
--form "token=$CI_JOB_TOKEN" \
--form "ref=$CI_COMMIT_BRANCH" \
--form "variables[FIELDCOMPARE_RELEASE_VERSION]=$FIELDCOMPARE_RELEASE_VERSION" \
"https://gitlab.com/api/v4/projects/32838547/trigger/pipeline"
else
echo "Version string $FIELDCOMPARE_RELEASE_VERSION is not a valid version. Refusing to deploy."
fi
else
echo "Version is still the same. Skipping deployment."
fi
when: on_success
release_check:
stage: release
extends: .release_job_rules
script:
- echo $FIELDCOMPARE_RELEASE_VERSION > release_version.txt
- python -m pip install -e .
- python -c "import fieldcompare; print(fieldcompare.__version__)" > fieldcompare_version.txt
- |
if ! cmp -s fieldcompare_version.txt release_version.txt; then
echo "Release version does not match fieldcompare version. Aborting release."
exit 1
fi
release:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
extends: .release_job_rules
needs: ["release_check"]
script:
- echo "Releasing fieldcompare version $FIELDCOMPARE_RELEASE_VERSION"
release:
tag_name: "$FIELDCOMPARE_RELEASE_VERSION"
description: "fieldcompare release $FIELDCOMPARE_RELEASE_VERSION"
ref: "$CI_COMMIT_SHA"
assets:
links:
- name: 'Python package on PyPI'
url: 'https://pypi.org/project/fieldcompare/$FIELDCOMPARE_RELEASE_VERSION/'