-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
218 lines (201 loc) · 5.8 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
###############################################################################
# GitLab CI YAML Documentation: https://docs.gitlab.com/ee/ci/yaml/
#
# Using badge colors from https://shields.io
# - Green: #44cc11
# - Yellow: #dfb317
# - Red: #e05d44
###############################################################################
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
POETRY_VERSION: "1.5.1"
POETRY_HOME: "$CI_PROJECT_DIR/.poetry"
POETRY_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pypoetry"
default:
tags:
- gitlab-org-docker
image: python:3.7
interruptible: true
cache:
key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
paths:
- ${POETRY_HOME}/
- .cache/
before_script:
# Install Poetry
- /usr/local/bin/python -c "import urllib.request; urllib.request.urlretrieve('https://install.python-poetry.org', 'install-poetry.py')"
- /usr/local/bin/python ./install-poetry.py --version ${POETRY_VERSION}
- export PATH="${POETRY_HOME}/bin:${PATH}"
- which poetry
- |
if poetry --version ; then
echo "Install seems okay";
else
/usr/local/bin/python ./install-poetry.py --uninstall;
/usr/local/bin/python ./install-poetry.py --version ${POETRY_VERSION};
poetry --version;
fi
# Install Poetry plugins
- poetry self add "poetry-dynamic-versioning[plugin]==1.1.0"
stages:
- lint
- build
- test
- deploy
###############################################################################
# STYLE & LINT
###############################################################################
pylint:
stage: lint
needs: []
dependencies: []
script:
# Setup dev env
- poetry install -v --sync --only main,ci,dev,test
- source $(poetry env info --path)/bin/activate
- pip install 'pylint-gitlab>=1.1.0'
- anybadge -l pylint -v 'fail' -c '#e05d44' -o -f badge.svg
- python_files=$(git ls-files '*.py' | tr '\n' ' ')
# Gitlab CodeQuality report
- pylint --rcfile=.pylintrc --exit-zero --output-format=pylint_gitlab.GitlabCodeClimateReporter ${python_files} > codeclimate.json
# Text file output
- pylint --rcfile=.pylintrc ${python_files} | tee ./pylint_out.txt || pylint-exit $?
- PYLINT_SCORE=$(cat ./pylint_out.txt | grep -oP 'Your code has been rated at \K(\d+\.*\d+)')
- anybadge -v $PYLINT_SCORE -o -f badge.svg pylint
- echo "pylint_rating $PYLINT_SCORE" > metrics.txt
artifacts:
when: always
paths:
- badge.svg
- pylint_out.txt
- codeclimate.json
- metrics.txt
reports:
metrics: metrics.txt
codequality: codeclimate.json
format_black:
stage: lint
needs: []
dependencies: []
script:
- poetry install -v --sync --only ci,dev
- source $(poetry env info --path)/bin/activate
- anybadge -l format -v 'fail' -c '#e05d44' -o -f badge.svg
- black --check ./
- anybadge -l format -v ' ok ' -c '#44cc11' -o -f badge.svg
allow_failure: true
artifacts:
when: always
paths:
- badge.svg
###############################################################################
# BUILD
###############################################################################
build:
stage: build
needs: []
dependencies: []
script:
- poetry install -vv --sync --only main
- poetry env info
- poetry build
artifacts:
paths:
- dist/*
###############################################################################
# TEST
###############################################################################
pytest:
stage: test
image: $IMAGE
needs: []
dependencies: []
script:
- poetry env info
#- poetry install -v --only ci,multienv
#- poetry run tox -e ${TOXENV} | tee pytest_session.out
- pip install tox
- tox -e ${TOXENV} | tee pytest_session.out
- coverage=$(grep -oP 'TOTAL.*\s+\K(\d+\.\d+)%' ./pytest_session.out)
- echo "coverage{env=\"${TOXENV}\"} ${coverage}" > metrics.txt
artifacts:
when: always
paths:
- .tox/**/*.log
- ./.coverage.*
- ./pytest_out*
- coverage.xml
- metrics.txt
reports:
metrics: metrics.txt
junit: ./*.xml.junit
parallel:
matrix:
- IMAGE: python:3.7
TOXENV: py37
- IMAGE: python:3.8
TOXENV: py38
- IMAGE: python:3.9
TOXENV: py39
- IMAGE: python:3.10
TOXENV: py310
- IMAGE: python:3.11
TOXENV: py311
- IMAGE: python:3.12
TOXENV: py312
coverage:
stage: test
needs:
- job: pytest
artifacts: true
script:
- poetry install -v --sync --only ci,multienv
- poetry run tox -e report
coverage: /(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/
artifacts:
paths:
- coverage.xml
- htmlcov/
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
# gitlab_artifact_report:
# stage: test
# needs:
# - job: build
# artifacts: true
# before_script:
# - python3 -m pip install --user virtualenv
# - python3 -m virtualenv venv/
# - source venv/bin/activate
# - pip install ./dist/cppcheck_*.zip
# script:
# - cppcheck-codequality -i ./tests/cppcheck_simple.xml -o codequality.json
# artifacts:
# when: always
# paths:
# - codequality.json
# #reports:
# # codequality: codequality.json
###############################################################################
# DEPLOY
###############################################################################
pypi_publish:
stage: deploy
rules:
- if: $CI_COMMIT_TAG
needs:
- job: pylint
artifacts: false
- job: build
artifacts: false
- job: pytest
artifacts: false
script:
- poetry install -v --sync
- poetry build
- poetry publish -u __token__ -p "${PYPI_API_TOKEN}"
artifacts:
paths:
- dist/*