-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
200 lines (184 loc) · 4.16 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
---
stages:
- test
- tagging
- deploy
default:
image: python:3.11
artifacts:
expire_in: 1 week
# Change pip's cache directory to be inside the project directory since we can
# only cache local items.
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
# Pip's cache doesn't store the python packages
# https://pip.pypa.io/en/stable/topics/caching/
#
# If you want to also cache the installed packages, you have to install
# them in a virtualenv and cache it as well.
cache:
paths:
- .cache/pip
- venv/
- .tox/
.create_venv: &create_venv
- python --version
- pip install virtualenv
- virtualenv venv
- source venv/bin/activate
.setup_dev_env: &setup_dev_env
- pip install .[dev]
- pip install .[test]
.extract_changelog_tag: &extract_changelog_tag
- pip install 'changelog2version>=0.5.0,<1'
- export CHANGELOG_TAG=$(changelog2version
--changelog_file changelog.md
--print |
python -c "import sys, json; print(json.load(sys.stdin)['info']['version'])")
- echo "Extracted tag from changelog ${CHANGELOG_TAG}"
test:
stage: test
image: $IMAGE
before_script:
- *create_venv
- *setup_dev_env
script:
- tox -e test
- coverage report -m
parallel:
matrix:
- IMAGE: [
'python:3.7',
'python:3.8',
'python:3.9',
'python:3.10',
'python:3.11'
]
coverage: '/TOTAL.*\s+(\d+%)$/'
artifacts:
reports:
coverage_report:
coverage_format: cobertura
path: reports/coverage/coverage.xml
junit: reports/test_results/nose2-junit.xml
paths:
- reports/coverage/coverage.xml
- reports/test_results/nose2-junit.xml
except:
- tags
codecov:
stage: test
image: alpine:3
needs: ["test"]
before_script:
- apk --no-cache add curl git
script:
- curl -Os https://uploader.codecov.io/latest/alpine/codecov
- chmod +x codecov
- ./codecov -t ${CODECOV_TOKEN} -f reports/coverage/coverage.xml -R ./ -v
except:
- tags
build:
stage: test
before_script:
- *create_venv
- *setup_dev_env
script:
- tox -e build
- pip install dist/*.whl
artifacts:
paths:
- dist/*
except:
- tags
lint:
stage: test
before_script:
- *create_venv
- *setup_dev_env
- pip install 'yamllint>=1.29,<2'
script:
- tox -e lint
- yamllint .
artifacts:
paths:
- reports/sca/flake8.out
except:
- tags
docs:
stage: test
before_script:
- *create_venv
- *setup_dev_env
script:
- tox -e docs
artifacts:
paths:
- docs/build/html
except:
- tags
tag-version:
stage: tagging
before_script:
- *create_venv
- *extract_changelog_tag
- git config user.email [email protected]
- git config user.name TagBot
script:
- PROJECT_URL=$(echo $CI_PROJECT_URL | sed 's/https:\/\///')
- export CHANGELOG_TAG_FULL=${CHANGELOG_TAG}-rc+build.${CI_PIPELINE_IID}
- git tag ${CHANGELOG_TAG_FULL} -m "$(git show | head -n 3)"
- git tag --list -n1 --sort=-creatordate | head -n 3
# never use an access token if it is not protected + masked
# ensure the the branch/tag it is running on is also protected
- git push
https://gitlab-ci-token:${GITLAB_ACCESS_TOKEN}@${PROJECT_URL}
${CHANGELOG_TAG_FULL}
only:
- main
except:
- tags
generate-docs:
stage: tagging
before_script:
- *create_venv
- *setup_dev_env
script:
- tox -e docs
- mv docs/build/html/ public/
artifacts:
expire_in: never
paths:
- public
only:
- tags
deploy:
stage: deploy
before_script:
- *create_venv
- *setup_dev_env
- pip install 'twine>=4.0.1,<5'
script:
- tox -e build
# never use an access token if it is not protected + masked
# ensure the the branch/tag it is running on is also protected
- TWINE_PASSWORD=${TWINE_PASSWORD}
TWINE_USERNAME=__token__
twine upload dist/*
only:
- tags
pages:
stage: deploy
before_script:
- *create_venv
- pip install .
script:
- generate-versioned-pages
--project-id ${CI_PROJECT_ID}
--job-name generate-docs
artifacts:
expire_in: never
paths:
- public
only:
- tags