forked from yeswehack/ywh2bugtracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
200 lines (181 loc) · 4.72 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
image: python:3.9
variables:
PIP_CACHE_DIR: "${CI_PROJECT_DIR}/.cache/pip"
POETRY_CACHE_DIR: "${CI_PROJECT_DIR}/.cache/poetry"
PYENV_ROOT: "${CI_PROJECT_DIR}/.cache/pyenv"
TOX_WORK_DIR: "${CI_PROJECT_DIR}/.cache/tox"
DOCKER_VERSION: "20"
CI_REGISTRY: registry.clacos.ninja
CONTAINER_BASE: "${CI_REGISTRY}/${CI_PROJECT_PATH}"
DOCKER_HUB_BASE_TAG: "yeswehack/ywh2bugtracker"
cache:
key: global
paths:
- .cache/pip
- .cache/poetry
stages:
- verify
- version
- build
- publish
.base_poetry:
tags:
- docker20
before_script:
- pip install poetry
- poetry install --no-root
.base_docker:
tags:
- docker20
image: "docker:${DOCKER_VERSION}"
services:
- name: "docker:${DOCKER_VERSION}-dind"
alias: docker
Poetry check:
stage: verify
extends: .base_poetry
script:
- poetry check
Flake8 code style check:
stage: verify
extends: .base_poetry
script:
- make flake8
artifacts:
when: always
paths:
- build/flake8
expire_in: 1 day
Static type check:
stage: verify
extends: .base_poetry
script:
- make mypy
artifacts:
when: always
paths:
- build/mypy
expire_in: 1 day
Unit tests:
stage: verify
extends: .base_poetry
script:
- if [ ! -d "${PYENV_ROOT}" ]; then curl https://pyenv.run | sh; fi
- export PATH="${PYENV_ROOT}/bin:$PATH"
- eval "$(pyenv init -)"
- pyenv update
- cat .python-version | xargs -n1 pyenv install -s
- make tox
User Guide Check:
stage: verify
extends: .base_docker
script:
- apk add make
- md5_md=$(make user-guide-md5sum-markdown)
- md5_pdf=$(make user-guide-md5sum-pdf)
- if [ "${md5_md}" != "${md5_pdf}" ]; then echo 'PDF version of User Guide is outdated, regenerate it via `make user-guide-pdf`'; exit 1; fi
- md5_html=$(make user-guide-md5sum-html)
- if [ "${md5_md}" != "${md5_html}" ]; then echo 'HTML version of User Guide is outdated, regenerate it via `make user-guide-html`'; exit 1; fi
Bump dev version:
stage: version
except:
- tags
extends: .base_poetry
script:
- export YWH2BT_VERSION="$(poetry version -s)-beta-$(date +%s)"
- poetry version "${YWH2BT_VERSION}"
- echo "${YWH2BT_VERSION}" > .ywh2bt-version
artifacts:
paths:
- pyproject.toml
- .ywh2bt-version
Save tag version:
stage: version
only:
- tags
extends: .base_poetry
script:
- poetry version -s > .ywh2bt-version
artifacts:
paths:
- .ywh2bt-version
Build:
stage: build
extends: .base_poetry
script:
- make build
artifacts:
paths:
- dist
Build Docker:
stage: build
tags:
- docker20
image:
name: gcr.io/kaniko-project/executor:debug
entrypoint: [ "" ]
script:
- mkdir -p /kaniko/.docker
- echo "{\"auths\":{\"registry.clacos.ninja\":{\"auth\":\"$DOCKER_AUTH\"}}}" > /kaniko/.docker/config.json
- cat /kaniko/.docker/config.json
- >-
/kaniko/executor --cache=true --context .
--dockerfile Dockerfile
--destination "${CONTAINER_BASE}:${CI_COMMIT_REF_SLUG}-$(cat .ywh2bt-version)"
pages:
stage: publish
only:
- tags
script:
- mkdir .public
- cp docs/user-guide/* .public
- cp docs/img/badge-user-guide-*.svg .public
- mv .public public
artifacts:
paths:
- public
Publish Test PyPi:
stage: publish
extends: .base_poetry
when: manual
except:
- tags
script:
- poetry publish --repository testpypi
Publish PyPi:
stage: publish
extends: .base_poetry
when: manual
only:
- tags
script:
- poetry publish
Publish Docker Hub Test:
stage: publish
extends: .base_docker
when: manual
except:
- tags
script:
- export DOCKER_LOCAL_TAG="${CONTAINER_BASE}:${CI_COMMIT_REF_SLUG}-$(cat .ywh2bt-version)"
- export DOCKER_HUB_TAG="${DOCKER_HUB_BASE_TAG}:${CI_COMMIT_REF_SLUG}-$(cat .ywh2bt-version)"
- docker pull "${DOCKER_LOCAL_TAG}"
- echo "${DOCKER_HUB_PASSWORD}" | docker login -u "${DOCKER_HUB_LOGIN}" --password-stdin
- docker tag "${DOCKER_LOCAL_TAG}" "${DOCKER_HUB_TAG}"
- docker push "${DOCKER_HUB_TAG}"
Publish Docker Hub:
stage: publish
extends: .base_docker
when: manual
only:
- tags
script:
- export DOCKER_LOCAL_TAG="${CONTAINER_BASE}:${CI_COMMIT_REF_SLUG}-$(cat .ywh2bt-version)"
- export DOCKER_HUB_TAG="${DOCKER_HUB_BASE_TAG}:$(cat .ywh2bt-version)"
- export DOCKER_HUB_TAG_LATEST="${DOCKER_HUB_BASE_TAG}:latest"
- docker pull "${DOCKER_LOCAL_TAG}"
- echo "${DOCKER_HUB_PASSWORD}" | docker login -u "${DOCKER_HUB_LOGIN}" --password-stdin
- docker tag "${DOCKER_LOCAL_TAG}" "${DOCKER_HUB_TAG}"
- docker push "${DOCKER_HUB_TAG}"
- docker tag "${DOCKER_LOCAL_TAG}" "${DOCKER_HUB_TAG_LATEST}"
- docker push "${DOCKER_HUB_TAG_LATEST}"