-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
274 lines (256 loc) · 7.9 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
stages:
- test
- build
- verify build
- release
- publish
.test_template:
stage: test
image: python:3-slim
before_script:
- apt-get update && apt-get install --no-install-recommends --assume-yes git
- pip install hatch
tags:
- kubernetes
.twine_template:
stage: publish
image: python:3-slim
tags:
- kubernetes
before_script:
- pip install build twine
- python -m build
.publish_to_git_template:
stage: publish
needs:
- job: twine check
- job: pytest
tags:
- kubernetes
allow_failure: true
rules:
- if: $CI_COMMIT_BRANCH == "main"
variables:
TARGET: HEAD:main
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/
variables:
TARGET: refs/tags/$CI_COMMIT_TAG
before_script:
- apt-get update -y && apt-get install openssh-client git curl -y
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY_GIT" | tr -d '\r' | ssh-add - > /dev/null
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan $GIT_HOST >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
- git config --global user.email "hello@askanna.io"
- git config --global user.name "AskAnna Robot"
script:
- git remote add public $GIT_REPO
- git push public $TARGET
lint:
extends: .test_template
script:
- hatch run +py=3 test:lint
pre-commit:
extends: .test_template
before_script:
- apt-get update && apt-get install --no-install-recommends --assume-yes git
- pip install pre-commit
script:
- pre-commit run --all-files
coverage:
extends: .test_template
script:
- hatch run +py=3 test:cov
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
artifacts:
expire_in: 2 weeks
name: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
paths:
- htmlcov/
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
junit: junit.xml
pytest:
extends: .test_template
parallel:
matrix:
- PY_VERSION: ["3", "3.8", "3.9", "3.10", "3.11", "3.12"]
image: python:$PY_VERSION-slim
script:
- hatch run +py=$PY_VERSION test:pytest
twine check:
extends: .twine_template
stage: test
script:
- twine check dist/*
build image:
stage: build
needs:
- job: pytest
tags:
- kubernetes
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [""]
parallel:
matrix:
- PY_VERSION: ["3", "3.8", "3.9", "3.10", "3.11", "3.12"]
rules:
- if: $CI_COMMIT_BRANCH == "main"
variables:
DESTINATION: $CI_REGISTRY_IMAGE:python-$PY_VERSION
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/
variables:
DESTINATION: $CI_REGISTRY_IMAGE/tag:$CI_COMMIT_TAG-python-$PY_VERSION
- if: $CI_COMMIT_BRANCH
variables:
DESTINATION: $CI_REGISTRY_IMAGE/review:$CI_COMMIT_REF_SLUG-python-$PY_VERSION
script:
- echo "Building image to " $DESTINATION
- echo "{\"auths\":{\"$CI_REGISTRY\":{\"username\":\"$CI_REGISTRY_USER\",\"password\":\"$CI_REGISTRY_PASSWORD\"}}}" > /kaniko/.docker/config.json
- /kaniko/executor --context $CI_PROJECT_DIR --dockerfile $CI_PROJECT_DIR/Dockerfile --destination $DESTINATION --build-arg PY_VERSION=$PY_VERSION-slim
verify image:
stage: verify build
needs:
- job: build image
parallel:
matrix:
- PY_VERSION: ["3", "3.8", "3.9", "3.10", "3.11", "3.12"]
rules:
- if: $CI_COMMIT_BRANCH == "main"
variables:
DOCKER_IMAGE: $CI_REGISTRY_IMAGE:python-$PY_VERSION
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/
variables:
DOCKER_IMAGE: $CI_REGISTRY_IMAGE/tag:$CI_COMMIT_TAG-python-$PY_VERSION
- if: $CI_COMMIT_BRANCH
variables:
DOCKER_IMAGE: $CI_REGISTRY_IMAGE/review:$CI_COMMIT_REF_SLUG-python-$PY_VERSION
image: $DOCKER_IMAGE
tags:
- kubernetes
script:
- echo "Using Docker image " $DOCKER_IMAGE
- python -V
- askanna --version
- askanna
- askanna-run-utils --version
- askanna-run-utils
release:
stage: release
image: registry.gitlab.com/gitlab-org/release-cli:latest
rules:
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/
script:
- echo "Creating a new release..."
release:
tag_name: $CI_COMMIT_TAG
description: $CI_COMMIT_TAG_MESSAGE
publish to pypi:
extends: .twine_template
needs:
- job: twine check
- job: pytest
rules:
- if: $CI_COMMIT_BRANCH == "main"
script:
- echo $PYPIRC | base64 -d > ~/.pypirc
- python -m twine upload --verbose --non-interactive --config-file ~/.pypirc -r pypi dist/*
publish to testpypi:
extends: .twine_template
needs:
- job: twine check
rules:
- if: $CI_COMMIT_BRANCH == "main"
when: never
- if: $CI_COMMIT_BRANCH
when: manual
allow_failure: true
script:
- echo $PYPITESTRC | base64 -d > ~/.pypirc
- python -m twine upload --verbose --non-interactive --config-file ~/.pypirc -r testpypi dist/*
publish to docker:
stage: publish
needs:
- job: verify image
image: docker:latest
services:
- docker:dind
tags:
- docker
rules:
- if: $CI_COMMIT_BRANCH == "main"
allow_failure: true
before_script:
- echo "$DOCKER_TOKEN" | docker login --username $DOCKER_USER --password-stdin
- echo "$CI_REGISTRY_PASSWORD" | docker login $CI_REGISTRY --username $CI_REGISTRY_USER --password-stdin
script:
- docker pull $CI_REGISTRY_IMAGE --all-tags
- docker tag $CI_REGISTRY_IMAGE:python-3 askanna/python:3
- docker tag $CI_REGISTRY_IMAGE:python-3 askanna/python:latest
- docker tag $CI_REGISTRY_IMAGE:python-3.8 askanna/python:3.8
- docker tag $CI_REGISTRY_IMAGE:python-3.9 askanna/python:3.9
- docker tag $CI_REGISTRY_IMAGE:python-3.10 askanna/python:3.10
- docker tag $CI_REGISTRY_IMAGE:python-3.11 askanna/python:3.11
- docker tag $CI_REGISTRY_IMAGE:python-3.12 askanna/python:3.12
- docker push askanna/python:latest
- docker push askanna/python:3
- docker push askanna/python:3.8
- docker push askanna/python:3.9
- docker push askanna/python:3.10
- docker push askanna/python:3.11
- docker push askanna/python:3.12
after_script:
- docker logout
publish to gitlab:
extends: .publish_to_git_template
variables:
SSH_PRIVATE_KEY_GIT: $SSH_PRIVATE_KEY_GITLAB_COM
GIT_HOST: gitlab.com
GIT_REPO: git@gitlab.com:askanna/askanna-python.git
publish to github:
extends: .publish_to_git_template
variables:
SSH_PRIVATE_KEY_GIT: $SSH_PRIVATE_KEY_GITHUB_COM
GIT_HOST: github.com
GIT_REPO: git@github.com:askanna-io/askanna-python.git
publish release to gitlab:
stage: publish
image: registry.gitlab.com/gitlab-org/release-cli:latest
needs:
- job: release
- job: publish to gitlab
tags:
- kubernetes
allow_failure: true
rules:
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/
variables:
GITLAB_PRIVATE_TOKEN: $GITLAB_COM_API_TOKEN
script:
- release-cli --server-url https://gitlab.com --project-id 33066876 create --tag-name $CI_COMMIT_TAG --description "$CI_COMMIT_TAG_MESSAGE"
publish release to github:
stage: publish
image: ubuntu:22.04
needs:
- job: release
- job: publish to github
tags:
- kubernetes
allow_failure: true
rules:
- if: $CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+$/
variables:
GH_TOKEN: $GITHUB_COM_API_TOKEN
before_script:
- apt-get update -y && apt-get install curl -y
- curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
- chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
- echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null
- apt-get update -y && apt-get install gh -y
script:
- gh release create $CI_COMMIT_TAG --verify-tag --title $CI_COMMIT_TAG --notes "$CI_COMMIT_TAG_MESSAGE" --repo askanna-io/askanna-python