-
Notifications
You must be signed in to change notification settings - Fork 36
/
.gitlab-ci.yml
234 lines (211 loc) · 6.26 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"
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:=py${PYTHON_VERSION:0:1}${PYTHON_VERSION:2:2}-cov-xdist}"'
- python -m tox --colored yes -e ${CI_TOX_ENV}
### Linux jobs ###
.linux-image:
services:
- image:all-pythons
before_script:
- source /it/activate-py${PYTHON_VERSION:0:1}${PYTHON_VERSION:2:2}
- python -m pip install -U pip
.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+)?\%)$/'
parallel:
matrix:
- PYTHON_VERSION: ["3.9", "3.10", "3.11", "3.12", "3.13"]
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:
- source /it/activate-python ${PYTHON_VERSION}
- mkdir -p "C:/tmp/Trash"
- python -m pip install -U pip
.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
parallel:
matrix:
- PYTHON_VERSION: ["3.9", "3.10", "3.11", "3.12", "3.13"]
# Stage: Tests
windows python:
extends: .test-windows
needs: ["check"]
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
# 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-core" && $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.
documentations:
stage: checks
needs: ["check"]
extends: .linux-common
variables:
PYTHON_VERSION: ${LATEST_PYTHON}
CI_TOX_ENV: docs
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
upload-python-registry:
extends: .linux-image
stage: upload
before_script:
- !reference [.linux-image, before_script]
- python -m pip install twine
script:
- CURRENT_DATE=$(date +"%Y%m%d%H%M")
- sed -i "s|[0-9][0-9.]*|&.${CURRENT_DATE}|" VERSION
- python -m pip wheel . -q --no-deps -C--python-tag=py3 -w build
- 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:
PYTHON_VERSION: "3.11"
TWINE_PASSWORD: $CI_JOB_TOKEN
TWINE_USERNAME: gitlab-ci-token