-
Notifications
You must be signed in to change notification settings - Fork 5
/
.gitlab-ci.yml
170 lines (155 loc) · 3.85 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
stages:
- build
- verify
- test:unit
- test:integration
- deploy:build
- deploy:check
- deploy:upload
- deploy:doc
- doc
variables:
DOCKER_DRIVER: overlay2
CONTAINER_TEST_IMAGE: $CI_REGISTRY_IMAGE:$CI_BUILD_REF_SLUG
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
CACHE_IMAGE: $CI_REGISTRY_IMAGE:cache
MYSQL_DATABASE: cim
MYSQL_ALLOW_EMPTY_PASSWORD: "1"
PYPI_ENDPOINT: $PYPI_ENDPOINT
PYPI_USER: $PYPI_USER
PYPI_PASSWORD: $PYPI_PASSWORD
build:
# Build an image with all requirements installed to use in later stages
tags:
- linux
stage: build
script:
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
- docker build --cache-from $CACHE_IMAGE -t $CONTAINER_TEST_IMAGE -t $CACHE_IMAGE .
- docker push $CONTAINER_TEST_IMAGE
- docker push $CACHE_IMAGE
.test:
tags:
- docker
image: $CONTAINER_TEST_IMAGE
except:
- Releases
pylint:
# Run a static code style checker (pylint)
extends: .test
stage: verify
script:
- ./pylint.sh
bandit:
# Run a static vulnerability checker (Bandit)
extends: .test
stage: verify
allow_failure: true
script:
- pip install bandit
- bandit -r cimpyorm -f html -o report.html
artifacts:
when: always
expose_as: "Bandit"
paths: [report.html]
pytest:
# Run unit tests, skipping some more special test cases (Integration, Deployment)
extends: .test
image: python:${PY_VERSION}
stage: test:unit
script:
- pip install -r requirements.txt
- pip install -r dev-requirements.txt
- pytest --ignore=cimpyorm/Test/Integration --ignore=cimpyorm/Test/Deployment --junitxml=pytest.xml --cov
coverage: '/TOTAL.+ ([0-9]{1,3}%)/'
needs: ["build"]
artifacts:
when: always
reports:
junit: pytest.xml
parallel:
matrix:
- PY_VERSION: ["3.9", "3.10", "3.11"]
DUMMY: "0"
.integration:
# Anchor for integration tests - retried once (sometimes services don't startup properly) and
# only run on Dev branch
tags:
- docker
image: $CONTAINER_TEST_IMAGE
stage: test:integration
needs: ["build"]
retry: 1
only:
- Dev
integration:SQLite:
# Test with SQLite Backend
extends: .integration
script:
- pytest --maxfail=1 cimpyorm/Test/Integration/SQLite
.deploy:
only:
- Releases
tags:
- docker
image: python
build_dist:
extends: .deploy
stage: deploy:build
script:
- pip install --upgrade setuptools wheel
- python setup.py sdist bdist_wheel
artifacts:
paths:
- dist/
check:
# Show contents of build archive (for manual inspection)
only:
- Releases
tags:
- linux
stage: deploy:check
script:
- mkdir contents
- tar -xf dist/*.tar.gz --directory contents
- ls -R contents
dependencies:
- build_dist
release:pypi:
# Release on pypi using twine and the variable-defined credentials
extends: .deploy
stage: deploy:upload
needs: ["build_dist"]
when: manual
allow_failure: true
script:
- pip install -q twine toml requests pytest pandas
- twine upload --repository-url $PYPI_ENDPOINT --u $PYPI_USER --p $PYPI_PASSWORD dist/*
- sleep 20
- pytest cimpyorm/Test/Deployment
dependencies:
- build_dist
release:gitlab:
extends: .deploy
stage: deploy:upload
needs: ["build_dist"]
when: manual
script:
- pip install -q twine
- TWINE_PASSWORD=${GITLAB_PACKAGE_KEY} TWINE_USERNAME=package-token python -m twine upload --verbose --repository-url ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/pypi dist/*
doc:
# Create PDF documentation
tags:
- docker
image: $CI_REGISTRY/iaew/docker/python-texlive:3.7
stage: deploy:doc
script:
- pip install sphinx sphinx-autodoc-typehints sphinx_rtd_theme
- sphinx-build -b latex docs/ Documentation
- cd Documentation && make
artifacts:
when: on_success
expire_in: 1 week
paths:
- Documentation/cimpyorm.pdf
needs: []