Debian Codegraph @

.gitlab-ci.yml

raw symbols SCIP
1 # This file is a template, and might need editing before it works on your project.
2 # To contribute improvements to CI/CD templates, please follow the Development guide at:
3 # https://docs.gitlab.com/ee/development/cicd/templates.html
4 # This specific template is located at:
5 # https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Python.gitlab-ci.yml
6
7 # Official language image. Look for the different tagged releases at:
8 # https://hub.docker.com/r/library/python/tags/
9 image: python:latest
10
11 variables:
12 # Change pip's cache directory to be inside the project directory since we can
13 # only cache local items.
14 PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
15
16 # Pip's cache doesn't store the python packages
17 # https://pip.pypa.io/en/stable/reference/pip_install/#caching
18 #
19 # If you want to also cache the installed packages, you have to install
20 # them in a virtualenv and cache it as well.
21 cache:
22 paths:
23 - .cache/pip
24
25 stages:
26 - build
27 - test
28 - deploy
29
30 build-package:
31 stage: build
32 script:
33 - 'export PATH="$PATH:/root/.local/bin"'
34 - python --version # For debugging
35 # install from the zip file to see if files were forgotten
36 - python setup.py sdist --dist-dir=dist --formats=zip
37 - pip install --user --upgrade pip
38 # download packages once and cache them for the others
39 - pip install --user -r test-requirements.txt -r requirements.txt virtualenv wheel
40 artifacts:
41 paths:
42 - sdist
43 untracked: true
44
45 # --------------------------- tests
46
47 .run-tests:
48 needs:
49 - build-package
50 stage: test
51 before_script:
52 - 'export PATH="$PATH:/root/.local/bin"'
53 - pip install --user --upgrade pip
54 # install the package in a virtual env
55 - pip install --user virtualenv
56 - virtualenv ENV
57 - source ENV/bin/activate
58 # install package from build step
59 - pip install dist/*.zip
60 # test that the example works without the test dependencies
61 - python example.py
62 # install test requirements
63 - pip install -r test-requirements.txt
64 # Debug and check the default time zone
65 - python3 -c 'import time; time.tzset(); print(time.strftime("%X %x %Z"))'
66 script:
67 - test/test_code_quality.sh
68 # using coverage see
69 # - https://docs.gitlab.com/ee/user/project/merge_requests/test_coverage_visualization.html#python-example
70 # - https://gitlab.com/gitlab-org/gitlab/-/issues/285086
71 - coverage run -m pytest
72 - coverage report
73 - coverage xml
74 artifacts:
75 expire_in: 2 days
76 reports:
77 coverage_report:
78 # format thanks to
79 # https://stackoverflow.com/a/72138320
80 coverage_format: cobertura
81 path: coverage.xml
82
83 .env1:
84 variables:
85 TZ: Europe/Berlin
86
87 .env2:
88 variables:
89 TZ: Australia/Sydney
90
91 # ----- tests
92
93 test-python-2.7-env1:
94 image: python:2.7
95 extends:
96 - .run-tests
97 - .env1
98
99 test-python-2.7-env2:
100 image: python:2.7
101 extends:
102 - .run-tests
103 - .env2
104
105 test-python-3.7-env1:
106 image: python:3.7
107 extends:
108 - .run-tests
109 - .env1
110
111 test-python-3.7-env2:
112 image: python:3.7
113 extends:
114 - .run-tests
115 - .env2
116
117 test-python-3.8-env1:
118 image: python:3.8
119 extends:
120 - .run-tests
121 - .env1
122
123 test-python-3.8-env2:
124 image: python:3.8
125 extends:
126 - .run-tests
127 - .env2
128
129 test-python-3.9-env1:
130 image: python:3.9
131 extends:
132 - .run-tests
133 - .env1
134
135 test-python-3.9-env2:
136 image: python:3.9
137 extends:
138 - .run-tests
139 - .env2
140
141 test-python-3.10-env1:
142 image: python:3.10
143 extends:
144 - .run-tests
145 - .env1
146
147 test-python-3.10-env2:
148 image: python:3.10
149 extends:
150 - .run-tests
151 - .env2
152
153 # --------------------------- deploy
154
155 deploy-package:
156 # use python3.9 because piwheels.org build for this version
157 image: python:3.9
158 stage: deploy
159 needs:
160 - test-python-2.7-env1
161 - test-python-2.7-env2
162 - test-python-3.7-env1
163 - test-python-3.7-env2
164 - test-python-3.8-env1
165 - test-python-3.8-env2
166 - test-python-3.9-env1
167 - test-python-3.9-env2
168 - test-python-3.10-env1
169 - test-python-3.10-env2
170 before_script:
171 - 'export PATH="$PATH:/root/.local/bin"'
172 - pip install --user --upgrade pip
173 # add piwheels so we can build on raspberry pi
174 - pip config set global.extra-index-url 'https://www.piwheels.org/simple'
175 - pip config list
176 - pip install --user wheel twine
177 script:
178 - PACKAGE_VERSION=`python setup.py --version`
179 - TAG_NAME=v$PACKAGE_VERSION
180 - echo "Package version $PACKAGE_VERSION with possible tag name $TAG_NAME on $CI_COMMIT_TAG"
181 # test that the tag represents the version
182 # see https://docs.gitlab.com/ee/ci/variables/predefined_variables.html
183 - '( if [ -n "$CI_COMMIT_TAG" ]; then if [ $TAG_NAME != $CI_COMMIT_TAG ]; then echo "This tag is for the wrong version. Got \"$CI_COMMIT_TAG\" expected \"$TAG_NAME\"."; exit 1; fi; fi; )'
184 # remove old files
185 - rm -rf dist/*
186 # build new files
187 - python setup.py bdist_wheel sdist
188 # You will have to set the variables TWINE_USERNAME and TWINE_PASSWORD
189 # You can use a token specific to your project by setting the user name to
190 # __token__ and the password to the token given to you by the PyPI project.
191 # sources:
192 # - https://shambu2k.hashnode.dev/gitlab-to-pypi
193 # - http://blog.octomy.org/2020/11/deploying-python-pacakges-to-pypi-using.html?m=1
194 # Also, set the tags as protected to allow the secrets to be used.
195 # see https://docs.gitlab.com/ee/user/project/protected_tags.html
196 - twine check dist/*
197 - twine upload dist/*
198 artifacts:
199 paths:
200 - dist/*
201 only:
202 # run only on tags with a certain name
203 # see http://stackoverflow.com/questions/52830653/ddg#52859379
204 - /^v[0-9]+\.[0-9]+\.[0-9a-z]+/
205