-
Notifications
You must be signed in to change notification settings - Fork 79
/
.gitlab-ci.yml
277 lines (241 loc) · 6.93 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
# Note: This GitLab CI configuration is used for internal testing, users can ignore it.
include:
- project: '${CI_PROJECT_NAMESPACE}/ci-libs-for-client-libraries'
file:
- '/${CI_PROJECT_NAME}/.gitlab-ci.yml'
- project: 'deepl/ops/ci-cd-infrastructure/gitlab-ci-lib'
file:
- '/templates/.buildkit.yml'
- '/templates/.secret-detection.yml'
# Global --------------------------
image: python:3.11
variables:
PIP_CACHE_DIR: "${CI_PROJECT_DIR}/.cache/pip"
XDG_CACHE_HOME: "${CI_PROJECT_DIR}/.cache"
POETRY_VIRTUALENVS_IN_PROJECT: "true"
REQUESTS_CA_BUNDLE: "/etc/ssl/certs/ca-certificates.crt"
cache:
key:
prefix: ${CI_JOB_IMAGE}
files:
- pyproject.toml
- poetry.lock
paths:
- .cache/pip
- .venv
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_TAG
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
stages:
- check
- build
- test
- publish
before_script:
- python3 -m venv .venv
- source .venv/bin/activate
- pip install --upgrade pip
# For py3.6, stick to Poetry 1.1.15, because with Poetry 1.2.0 there is a build issue on Python 3.6:
# "pydantic-1.9.0-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl is not a supported wheel on this platform."
# Note: Poetry and the project dependencies should also be installed in separate virtual-envs (that is not done here)
- >
if [[ ! -z "${USE_OLD_POETRY_VERSION}" ]]; then
echo "Installing old poetry version"
pip install poetry==1.1.15
else
echo "Installing newer poetry version"
pip install poetry==1.4.2
fi
- poetry --version
- poetry install -vv -E keyring
# stage: check ----------------------
.black_base:
stage: check
script: poetry run black --check .
black_scheduled:
extends: .black_base
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
retry: 2
black_manual:
extends: .black_base
rules:
- if: $CI_PIPELINE_SOURCE != "schedule"
.flake8_base:
stage: check
script: poetry run flake8 deepl tests
flake8_scheduled:
extends: .flake8_base
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
retry: 2
flake8_manual:
extends: .flake8_base
rules:
- if: $CI_PIPELINE_SOURCE != "schedule"
.license_check_base:
stage: check
script:
- ./license_checker.sh '*.py' | tee license_check_output.txt
- '[ ! -s license_check_output.txt ]'
license_check_scheduled:
extends: .license_check_base
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
retry: 2
license_check_manual:
extends: .license_check_base
rules:
- if: $CI_PIPELINE_SOURCE != "schedule"
secret_detection:
extends: .secret-detection
stage: check
image: !reference [.secret-detection, image]
before_script:
- echo "overriding default before_script..."
rules:
- if: $CI_MERGE_REQUEST_ID
.mypy_base:
stage: check
script: poetry run mypy --exclude 'examples/' .
mypy_scheduled:
extends: .mypy_base
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
retry: 2
mypy_manual:
extends: .mypy_base
rules:
- if: $CI_PIPELINE_SOURCE != "schedule"
# stage: build ----------------------
package:
stage: build
script:
- poetry build --verbose --no-interaction
artifacts:
paths:
- dist/
# stage: test -------------------------
.test_base:
stage: test
extends: .test
parallel:
matrix:
- DOCKER_IMAGE: "python:3.11"
- DOCKER_IMAGE: "python:3.6"
USE_MOCK_SERVER: "use mock server"
USE_OLD_POETRY_VERSION: "use old poetry version"
- DOCKER_IMAGE: "python:3.7"
USE_MOCK_SERVER: "use mock server"
- DOCKER_IMAGE: "python:3.8"
USE_MOCK_SERVER: "use mock server"
- DOCKER_IMAGE: "python:3.9"
USE_MOCK_SERVER: "use mock server"
- DOCKER_IMAGE: "python:3.10"
USE_MOCK_SERVER: "use mock server"
- DOCKER_IMAGE: "python:3.11"
USE_MOCK_SERVER: "use mock server"
- DOCKER_IMAGE: "python:3.6"
EXTRA_POETRY_ADD_ARGUMENT: "[email protected]"
USE_MOCK_SERVER: "use mock server"
USE_OLD_POETRY_VERSION: "use old poetry version"
- DOCKER_IMAGE: "python:3.9"
EXTRA_POETRY_ADD_ARGUMENT: "[email protected]"
USE_MOCK_SERVER: "use mock server"
- DOCKER_IMAGE: "python:3.11"
# Set minimum possible requests and urllib3 versions to work with Python 3.11
EXTRA_POETRY_ADD_ARGUMENT: "[email protected] [email protected]"
USE_MOCK_SERVER: "use mock server"
image: ${DOCKER_IMAGE}
script:
- >
if [[ ! -z "${EXTRA_POETRY_ADD_ARGUMENT}" ]]; then
echo "Running poetry add ${EXTRA_POETRY_ADD_ARGUMENT}"
poetry add ${EXTRA_POETRY_ADD_ARGUMENT}
fi
- >
if [[ ! -z "${USE_MOCK_SERVER}" ]]; then
echo "Using mock server"
export DEEPL_SERVER_URL=http://deepl-mock:3000
export DEEPL_MOCK_SERVER_PORT=3000
export DEEPL_PROXY_URL=http://deepl-mock:3001
export DEEPL_MOCK_PROXY_SERVER_PORT=3001
fi
- poetry run coverage run -m pytest --junit-xml test_report.xml
- poetry run coverage report
- poetry run coverage xml
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
junit:
- test_report.xml
when: always
test_scheduled:
extends: .test_base
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
retry: 2
test_manual:
stage: test
extends: .test_base
rules:
- if: $CI_PIPELINE_SOURCE != "schedule"
.mustache_example_base:
stage: test
extends: .test
script:
- cd examples/mustache
- pip install deepl
- python . --help
- python . --from en --to de "Hello {{user}}, your balance is {{{balance}}} dollars." > mustache_result.txt
- cat mustache_result.txt
- grep -q "{{user}}" mustache_result.txt
- grep -q "{{{balance}}}" mustache_result.txt
mustache_example_scheduled:
extends: .mustache_example_base
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
retry: 2
mustache_example_manual:
stage: test
extends: .mustache_example_base
rules:
- if: $CI_PIPELINE_SOURCE != "schedule"
.basic_usage_example_base:
stage: test
extends: .test
script:
- poetry build --verbose --no-interaction
- cd examples/basic_usage
- python3 -m venv .examplevenv
- source .examplevenv/bin/activate
- pip install ../../dist/deepl-*.tar.gz
- set -o pipefail
- python . 2>&1 | tee basic_usage_result.txt
- grep -q "Success" basic_usage_result.txt
- pip install mypy
- mypy .
basic_usage_example_scheduled:
extends: .basic_usage_example_base
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
retry: 2
basic_usage_example_manual:
stage: test
extends: .basic_usage_example_base
rules:
- if: $CI_PIPELINE_SOURCE != "schedule"
# stage: publish -------------------------
pypi upload:
extends: .publish
stage: publish
dependencies:
- package
rules:
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/'
script:
- poetry publish --verbose --no-interaction