-
Notifications
You must be signed in to change notification settings - Fork 1
287 lines (233 loc) · 9.28 KB
/
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
275
276
277
278
279
280
281
282
283
284
285
286
287
name: CI
on:
push:
pull_request:
release:
types: [published]
schedule: # run every week to see if there are any upstream issues
- cron: '0 12 * * 6'
jobs:
style-python:
name: "💄 Style: python"
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # [email protected]
- name: Setup python
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # [email protected]
with:
python-version: "3.10"
- name: Install style check dependencies
run: |
pip install flake8==6.0.0
pip install pep8-naming==0.13.2
- name: Check style
run: |
flake8 .
style-js:
name: "💄 Style: js"
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # [email protected]
- name: Setup node
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # [email protected]
with:
node-version: "18"
- name: Install dependencies
run: cd inventree_bulk_plugin/frontend && npm ci
- name: Check style
run: cd inventree_bulk_plugin/frontend && npm run lint
tests-unit-python:
name: "🧪 Unit tests: python"
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }}
needs: style-python
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # [email protected]
- name: Setup python
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # [email protected]
with:
python-version: "3.10"
- name: Install pip dependencies
run: |
pip install pydantic==2.* Jinja2==3.* coverage==7.0.1
- name: Run tests
run: |
python -m coverage run -m unittest discover -s inventree_bulk_plugin.tests.unit
echo $GITHUB_WORKSPACE > coverage_info
- name: Upload coverage
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # [email protected]
with:
name: unit-coverage
path: |
.coverage
coverage_info
tests-integration-python:
name: "🧪 Integration tests: python (${{ matrix.inventree-tag }})"
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }}
needs: style-python
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
inventree-tag: [latest, stable]
container:
image: inventree/inventree:${{ matrix.inventree-tag }}
options: --user root
env:
INVENTREE_DB_ENGINE: postgresql
INVENTREE_DB_NAME: inventree
INVENTREE_DB_HOST: db
INVENTREE_DB_PORT: 5432
INVENTREE_DB_USER: inventree
INVENTREE_DB_PASSWORD: inventree
INVENTREE_PLUGINS_ENABLED: True
INVENTREE_PLUGIN_TESTING: True
INVENTREE_PLUGIN_TESTING_SETUP: True
services:
db:
image: postgres:13
ports:
- 5432:5432
env:
POSTGRES_USER: inventree
POSTGRES_PASSWORD: inventree
POSTGRES_DB: inventree
steps:
- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # [email protected]
- name: Setup inventree
run: |
cd /home/inventree
HOME=/root pip3 install --no-cache-dir --disable-pip-version-check -U -r requirements.txt
- name: Setup inventree-bulk-plugin
run: |
cd /home/inventree
HOME=/root pip3 install -e $GITHUB_WORKSPACE
# install additional dependencies required for testing
# and newer coverage version due to https://github.com/nedbat/coveragepy/issues/1150
HOME=/root pip3 install django-test-migrations==1.2.0 coverage==7.4.1 django_slowtests==1.1.1
# migrate db
HOME=/root invoke migrate
- name: Run tests
run: |
cd /home/inventree
HOME=/root coverage run --omit="InvenTree/**" InvenTree/manage.py test inventree_bulk_plugin.tests.integration
echo $GITHUB_WORKSPACE > coverage_info
- name: Upload coverage
if: ${{ matrix.inventree-tag == 'latest' }}
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # [email protected]
with:
name: integration-coverage
path: |
/home/inventree/.coverage
/home/inventree/coverage_info
report:
name: 📝 Report
needs: [tests-unit-python, tests-integration-python]
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }}
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # [email protected]
- name: Setup python
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # [email protected]
with:
python-version: "3.10"
- name: Install test dependencies
run: pip install coverage==7.0.1
- name: Download coverage
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # [email protected]
with:
path: coverage
- name: Prepare reports
run: |
echo "" >> .coveragerc
echo "[paths]" >> .coveragerc
echo "source =" >> .coveragerc
echo " ." >> .coveragerc
echo " $(cat coverage/unit-coverage/coverage_info)" >> .coveragerc
echo " $(cat coverage/integration-coverage/coverage_info)" >> .coveragerc
coverage combine coverage/integration-coverage/.coverage coverage/unit-coverage/.coverage
coverage json
coverage html
coverage_percentage=$(jq -r ".totals.percent_covered" coverage.json | xargs printf "%.*f\n" "1")
echo '## Coverage Report' > coverage.md
echo "![Code Coverage](https://img.shields.io/badge/Code%20Coverage-${coverage_percentage}%25-green?style=flat)" >> coverage.md
coverage report --format=markdown -m >> coverage.md
- name: Upload full-coverage
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # [email protected]
with:
name: coverage
path: |
.coverage
htmlcov
- name: Get PR number
uses: 8BitJonny/gh-get-current-pr@2215326c76d51bfa3f2af0a470f32677f6c0cae9 # [email protected]
id: pr
with:
sha: ${{ github.event.pull_request.head.sha }}
filterOutClosed: true
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@f6a2580ed520ae15da6076e7410b088d1c5dddd9 # [email protected]
if: success() && steps.pr.outputs.number
with:
number: ${{ steps.pr.outputs.number }}
path: coverage.md
- name: Write to Job Summary
run: cat coverage.md >> $GITHUB_STEP_SUMMARY
build-js:
name: "🏗️ Build: js"
needs: [style-js]
if: ${{ !(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # [email protected]
- name: Setup node
uses: actions/setup-node@e33196f7422957bea03ed53f6fbb155025ffc7b8 # [email protected]
with:
node-version: "18"
- name: Install dependencies
run: cd inventree_bulk_plugin/frontend && npm ci
- name: Build js
run: cd inventree_bulk_plugin/frontend && npm run build
- name: Upload frontend artifact
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # [email protected]
with:
name: frontend
path: inventree_bulk_plugin/static/inventree-bulk-plugin/dist
publish:
if: github.event_name == 'release' && github.event.action == 'published'
needs: [report, build-js]
name: 📦 Publish to PyPi
runs-on: ubuntu-latest
environment:
name: release
url: https://pypi.org/p/inventree-bulk-plugin
permissions:
id-token: write
steps:
- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # [email protected]
- name: Setup python
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # [email protected]
with:
python-version: "3.10"
- name: Install build dependencies
run: pip install --upgrade wheel setuptools twine build
- name: Download frontend artifact
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # [email protected]
with:
name: frontend
path: inventree_bulk_plugin/static/inventree-bulk-plugin/dist
- name: Build pip package
run: python3 -m build
- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@f8c70e705ffc13c3b4d1221169b84f12a75d6ca8 # [email protected]