-
Notifications
You must be signed in to change notification settings - Fork 5
233 lines (198 loc) · 6.18 KB
/
github-actions.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
name: pipeline
on:
push:
pull_request:
env:
PYTHON_IMAGE: 3.9
DOCKER_IMAGE: docker:20.10.23
PYTHON_PACKAGE_NAME: deker
DOCKER_REG_IMAGE: ${{ secrets.CI_REGISTRY_IMAGE }}
jobs:
setup:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ env.PYTHON_IMAGE }}
- name: Install dependencies
run: |
pip install --upgrade pip
pip install virtualenv
virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
pip install -r requirements_dev.txt
pip list
- name: Cache virtual environment
uses: actions/cache@v2
with:
path: venv
key: ${{ runner.os }}-venv-${{ env.PYTHON_IMAGE }}-${{ hashFiles('requirements.txt', 'requirements_dev.txt') }}
linters:
needs: setup
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ env.PYTHON_IMAGE }}
- name: Load virtual environment
uses: actions/cache@v2
with:
path: venv
key: ${{ runner.os }}-venv-${{ env.PYTHON_IMAGE }}-${{ hashFiles('requirements.txt', 'requirements_dev.txt') }}
- name: Run linters and checks
run: |
source venv/bin/activate
isort ./${{ env.PYTHON_PACKAGE_NAME }}
black ./${{ env.PYTHON_PACKAGE_NAME }}
flake8 ./${{ env.PYTHON_PACKAGE_NAME }}
mypy ./${{ env.PYTHON_PACKAGE_NAME }} --install-types --non-interactive --config-file pyproject.toml
env:
PIP_DISABLE_PIP_VERSION_CHECK: 1
- name: Save linter reports
if: always()
uses: actions/upload-artifact@v2
with:
name: linter-reports
path: report.xml
tests:
needs: setup
runs-on: ubuntu-latest
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_IMAGE }}
- name: Load virtual environment
uses: actions/cache@v2
with:
path: venv
key: ${{ runner.os }}-venv-${{ env.PYTHON_IMAGE }}-${{ hashFiles('requirements.txt', 'requirements_dev.txt') }}
- name: Run shuffled tests
run: |
source venv/bin/activate
pytest --random-order --junitxml=tests.xml
env:
PIP_DISABLE_PIP_VERSION_CHECK: 1
- name: Save test reports
if: always()
uses: actions/upload-artifact@v2
with:
name: test-reports
path: tests.xml
coverage:
needs: setup
runs-on: ubuntu-latest
if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_IMAGE }}
- name: Load virtual environment
uses: actions/cache@v2
with:
path: venv
key: ${{ runner.os }}-venv-${{ env.PYTHON_IMAGE }}-${{ hashFiles('requirements.txt', 'requirements_dev.txt') }}
- name: Run coverage
run: |
source venv/bin/activate
coverage run -m pytest --junitxml=report.xml
coverage report
coverage xml
env:
PIP_DISABLE_PIP_VERSION_CHECK: 1
- name: Save coverage reports
if: always()
uses: actions/upload-artifact@v2
with:
name: coverage-reports
path: coverage.xml
tox_tests:
needs: setup
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
container:
image: ghcr.io/openweathermap/deker/deker-embedded/tox:latest
env:
PACKAGE_VERSION: ${{ github.REF_NAME }}
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Set python versions
run: pyenv global 3.9 3.10 3.11
- name: Checkout code
uses: actions/checkout@v2
- name: Install tox
run: |
pip install tox
env:
PIP_DISABLE_PIP_VERSION_CHECK: 1
- name: Run tox tests
run: tox
env:
PIP_DISABLE_PIP_VERSION_CHECK: 1
PACKAGE_VERSION: ${{ github.REF_NAME }}
build_wheels:
name: Build wheels on ${{ matrix.os }}
needs: tox_tests
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04]
steps:
- uses: actions/checkout@v3
- name: Build wheels
run: |
pip wheel -w ./wheelhouse .
build_sdist:
needs: tox_tests
name: Build source distribution
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build sdist
run: pipx run build --sdist
- uses: actions/upload-artifact@v3
with:
path: dist/*.tar.gz
upload_pypi:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
permissions:
id-token: write
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
environment:
# TODO: next is for prod pypi; comment for tests
name: pypi
url: https://pypi.org/p/deker
# TODO: next is for test pypi; comment for prod
# name: testpypi
# url: https://test.pypi.org/p/deker
steps:
- uses: actions/download-artifact@v3
with:
# unpacks default artifact into dist/
# if `name: artifact` is omitted, the action will create extra parent dir
name: artifact
path: dist
- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# TODO: next is for test pypi; comment for prod
# with:
# repository-url: https://test.pypi.org/legacy/