-
Notifications
You must be signed in to change notification settings - Fork 14
/
.gitlab-ci.yml
234 lines (214 loc) · 6.4 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
variables:
GITLAB_REMOTE:
description: "The remote gitlab URL used."
value: "https://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/"
LATEST_PYTHON:
description: "The latest python version used to test this project."
options:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "3.13"
value: "3.13"
LINUX_CI_TOX_ENV:
# Run coverage only with one Python version as this is costly.
description: "Tox environments to run on Linux."
value: "py39-cov-xdist,py310-xdist,py311-xdist,py312-xdist,py313-xdist"
WINDOWS_CI_TOX_ENV:
description: "Tox environments to run on Windows."
value: "py312-xdist"
stages:
- checks
- tests linux
- tests windows
- upload
default:
services:
- run_as_root:false
interruptible: true
# Common
.tox-common:
before_script:
- python -m pip install --force tox
script:
# Should be quoted using \' to deal with ':' in the command
- 'echo "Tox run environment: ${CI_TOX_ENV}"'
- python -m tox --colored yes -e ${CI_TOX_ENV}
### Linux jobs ###
.linux-image:
services:
- image:all-pythons
before_script:
- |
if [ -z "$PYTHON_VERSION" ]; then
versions=$(echo "$LINUX_CI_TOX_ENV" | sed -E 's/py([0-9]+)-[^,]+/\1/g' | tr ',' ' ')
for pyversion in $versions; do
source /it/activate-py$pyversion
done
else
source /it/activate-py${PYTHON_VERSION:0:1}${PYTHON_VERSION:2}
fi
.linux-common:
extends:
- .linux-image
- .tox-common
before_script:
- !reference [.linux-image, before_script]
- !reference [.tox-common, before_script]
# Stage: Checks
check:
stage: checks
extends: .linux-common
needs: []
before_script:
- !reference [.linux-common, before_script]
- git config --global --add
url."${GITLAB_REMOTE}/it/black.git".insteadOf
https://github.com/ambv/black
- git config --global --add
url."${GITLAB_REMOTE}/it/flake8.git".insteadOf
https://github.com/pycqa/flake8
- python -m pip install pre-commit
- pre-commit install
script:
- pre-commit run -a --show-diff-on-failure
- !reference [.linux-common, script]
variables:
PYTHON_VERSION: ${LATEST_PYTHON}
CI_TOX_ENV: check
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
.test-linux:
stage: tests linux
extends: .linux-common
services:
- !reference [.linux-common, services]
- cpu:4
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
variables:
CI_TOX_ENV: $LINUX_CI_TOX_ENV
artifacts:
when: always
paths:
- pytest-report.xml
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
junit: pytest-report.xml
linux python:
extends: .test-linux
needs: ["check"]
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
# A job triggered by 'run linux tests'. This jobs will run without waiting any others
# jobs.
linux python (always):
extends: .test-linux
needs: []
rules:
- if: $CI_PIPELINE_SOURCE == "parent_pipeline" && $CI_MERGE_REQUEST_ID && $CI_PROJECT_NAME == "e3-core" && $ALWAYS_LINUX_TESTS == "y"
# A manual job to run Linux tests even if "check" job has failed
run linux tests:
stage: tests linux
needs: []
trigger:
include: .gitlab-ci.yml
strategy: depend
variables:
ALWAYS_LINUX_TESTS: "y"
ALWAYS_WINDOWS_TESTS: "n"
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: manual
allow_failure: true
# Contrary to what the documentation might suggest, manual_confirmation
# is not currently usable with our gitlab.
# However, when it is, adding a manual confirmation to warn the user that
# this job should only be used when previous steps have failed seems
# useful. Something like:
#
# manual_confirmation: |-
# Are you sure you want to run Linux tests?
#
# This is only useful if the previous stages have failed and you still want to run the tests.
### Windows jobs ###
.windows-image:
services:
- image:e3-windows-2022
- platform:x86_64-windows-2022
- cpu:2
- mem:4
before_script:
- |
if [ -z "$PYTHON_VERSION" ]; then
versions=$(echo "$WINDOWS_CI_TOX_ENV" | sed -E 's/py([0-9])([0-9]+)-[^,]+/\1.\2/g' | tr ',' ' ')
for pyversion in $versions; do
if [ -d /it/python/$pyversion ]; then
source /it/activate-python $pyversion
fi
done
else
source /it/activate-python $PYTHON_VERSION
fi
- mkdir -p "C:/tmp/Trash"
.windows-common:
extends:
- .windows-image
- .tox-common
before_script:
- !reference [.windows-image, before_script]
- !reference [.tox-common, before_script]
.test-windows:
stage: tests windows
extends: .windows-common
variables:
CI_TOX_ENV: $WINDOWS_CI_TOX_ENV
# A job tiggered by 'Run Windows tests'. This jobs will run without waiting any others
# jobs.
windows python (always):
extends: .test-windows
needs: []
rules:
- if: $CI_PIPELINE_SOURCE == "parent_pipeline" && $CI_MERGE_REQUEST_ID && $CI_PROJECT_NAME == "e3-aws" && $ALWAYS_WINDOWS_TESTS == "y"
# A manual job to run Windows tests even if previous jobs have failed
run windows tests:
stage: tests windows
needs: []
trigger:
include: .gitlab-ci.yml
strategy: depend
variables:
ALWAYS_LINUX_TESTS: "n"
ALWAYS_WINDOWS_TESTS: "y"
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
when: manual
allow_failure: true
# Contrary to what the documentation might suggest, manual_confirmation
# is not currently usable with our gitlab.
# However, when it is, adding a manual confirmation to warn the user that
# this job should only be used when previous steps have failed seems
# useful. Something like:
#
# manual_confirmation: |-
# Are you sure you want to run Windows tests?
#
# This is only useful if the previous stages have failed and you still want to run the tests.
upload-python-registry:
stage: upload
services:
- image:e3
before_script:
- python -m pip install twine
script:
- python build_wheel.py
- python -m twine upload --skip-existing
--repository-url https://${CI_SERVER_HOST}:${CI_SERVER_PORT}/api/v4/projects/202/packages/pypi
build/*.whl
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
variables:
TWINE_PASSWORD: $CI_JOB_TOKEN
TWINE_USERNAME: gitlab-ci-token