Skip to content

Commit 4291267

Browse files
authored
Use shared CI (#220)
* Use shared CI * Add a `requirements_test.txt` file * Bump minimum required zigpy version for 3.12 changes
1 parent e2fa419 commit 4291267

File tree

3 files changed

+14
-310
lines changed

3 files changed

+14
-310
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 309 deletions
Original file line numberDiff line numberDiff line change
@@ -1,316 +1,15 @@
11
name: CI
22

3-
# yamllint disable-line rule:truthy
43
on:
54
push:
65
pull_request: ~
76

8-
env:
9-
CACHE_VERSION: 1
10-
DEFAULT_PYTHON: 3.8
11-
PRE_COMMIT_HOME: ~/.cache/pre-commit
12-
137
jobs:
14-
# Separate job to pre-populate the base dependency cache
15-
# This prevent upcoming jobs to do the same individually
16-
prepare-base:
17-
name: Prepare base dependencies
18-
runs-on: ubuntu-latest
19-
strategy:
20-
matrix:
21-
python-version: [3.8, 3.9, "3.10", "3.11"]
22-
steps:
23-
- name: Check out code from GitHub
24-
uses: actions/checkout@v2
25-
- name: Set up Python ${{ matrix.python-version }}
26-
id: python
27-
uses: actions/setup-python@v2
28-
with:
29-
python-version: ${{ matrix.python-version }}
30-
- name: Restore base Python virtual environment
31-
id: cache-venv
32-
uses: actions/cache@v2
33-
with:
34-
path: venv
35-
key: >-
36-
${{ env.CACHE_VERSION}}-${{ runner.os }}-base-venv-${{
37-
steps.python.outputs.python-version }}-${{
38-
hashFiles('pyproject.toml') }}
39-
restore-keys: |
40-
${{ env.CACHE_VERSION}}-${{ runner.os }}-base-venv-${{ steps.python.outputs.python-version }}-
41-
- name: Create Python virtual environment
42-
if: steps.cache-venv.outputs.cache-hit != 'true'
43-
run: |
44-
python -m venv venv
45-
. venv/bin/activate
46-
pip install -U pip setuptools pre-commit
47-
pip install -e '.[testing]'
48-
49-
pre-commit:
50-
name: Prepare pre-commit environment
51-
runs-on: ubuntu-latest
52-
needs: prepare-base
53-
steps:
54-
- name: Check out code from GitHub
55-
uses: actions/checkout@v2
56-
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
57-
uses: actions/setup-python@v2
58-
id: python
59-
with:
60-
python-version: ${{ env.DEFAULT_PYTHON }}
61-
- name: Restore base Python virtual environment
62-
id: cache-venv
63-
uses: actions/cache@v2
64-
with:
65-
path: venv
66-
key: >-
67-
${{ env.CACHE_VERSION}}-${{ runner.os }}-base-venv-${{
68-
steps.python.outputs.python-version }}-${{
69-
hashFiles('pyproject.toml') }}
70-
- name: Fail job if Python cache restore failed
71-
if: steps.cache-venv.outputs.cache-hit != 'true'
72-
run: |
73-
echo "Failed to restore Python virtual environment from cache"
74-
exit 1
75-
- name: Restore pre-commit environment from cache
76-
id: cache-precommit
77-
uses: actions/cache@v2
78-
with:
79-
path: ${{ env.PRE_COMMIT_HOME }}
80-
key: |
81-
${{ env.CACHE_VERSION}}-${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
82-
restore-keys: |
83-
${{ env.CACHE_VERSION}}-${{ runner.os }}-pre-commit-
84-
- name: Install pre-commit dependencies
85-
if: steps.cache-precommit.outputs.cache-hit != 'true'
86-
run: |
87-
. venv/bin/activate
88-
pre-commit install-hooks
89-
90-
lint-black:
91-
name: Check black
92-
runs-on: ubuntu-latest
93-
needs: pre-commit
94-
steps:
95-
- name: Check out code from GitHub
96-
uses: actions/checkout@v2
97-
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
98-
uses: actions/setup-python@v2
99-
id: python
100-
with:
101-
python-version: ${{ env.DEFAULT_PYTHON }}
102-
- name: Restore base Python virtual environment
103-
id: cache-venv
104-
uses: actions/cache@v2
105-
with:
106-
path: venv
107-
key: >-
108-
${{ env.CACHE_VERSION}}-${{ runner.os }}-base-venv-${{
109-
steps.python.outputs.python-version }}-${{
110-
hashFiles('pyproject.toml') }}
111-
- name: Fail job if Python cache restore failed
112-
if: steps.cache-venv.outputs.cache-hit != 'true'
113-
run: |
114-
echo "Failed to restore Python virtual environment from cache"
115-
exit 1
116-
- name: Restore pre-commit environment from cache
117-
id: cache-precommit
118-
uses: actions/cache@v2
119-
with:
120-
path: ${{ env.PRE_COMMIT_HOME }}
121-
key: |
122-
${{ env.CACHE_VERSION}}-${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
123-
- name: Fail job if cache restore failed
124-
if: steps.cache-venv.outputs.cache-hit != 'true'
125-
run: |
126-
echo "Failed to restore Python virtual environment from cache"
127-
exit 1
128-
- name: Run black
129-
run: |
130-
. venv/bin/activate
131-
pre-commit run --hook-stage manual black --all-files --show-diff-on-failure
132-
133-
lint-flake8:
134-
name: Check flake8
135-
runs-on: ubuntu-latest
136-
needs: pre-commit
137-
steps:
138-
- name: Check out code from GitHub
139-
uses: actions/checkout@v2
140-
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
141-
uses: actions/setup-python@v2
142-
id: python
143-
with:
144-
python-version: ${{ env.DEFAULT_PYTHON }}
145-
- name: Restore base Python virtual environment
146-
id: cache-venv
147-
uses: actions/cache@v2
148-
with:
149-
path: venv
150-
key: >-
151-
${{ env.CACHE_VERSION}}-${{ runner.os }}-base-venv-${{
152-
steps.python.outputs.python-version }}-${{
153-
hashFiles('pyproject.toml') }}
154-
- name: Fail job if Python cache restore failed
155-
if: steps.cache-venv.outputs.cache-hit != 'true'
156-
run: |
157-
echo "Failed to restore Python virtual environment from cache"
158-
exit 1
159-
- name: Restore pre-commit environment from cache
160-
id: cache-precommit
161-
uses: actions/cache@v2
162-
with:
163-
path: ${{ env.PRE_COMMIT_HOME }}
164-
key: |
165-
${{ env.CACHE_VERSION}}-${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
166-
- name: Fail job if cache restore failed
167-
if: steps.cache-venv.outputs.cache-hit != 'true'
168-
run: |
169-
echo "Failed to restore Python virtual environment from cache"
170-
exit 1
171-
- name: Register flake8 problem matcher
172-
run: |
173-
echo "::add-matcher::.github/workflows/matchers/flake8.json"
174-
- name: Run flake8
175-
run: |
176-
. venv/bin/activate
177-
pre-commit run --hook-stage manual flake8 --all-files
178-
179-
lint-isort:
180-
name: Check isort
181-
runs-on: ubuntu-latest
182-
needs: pre-commit
183-
steps:
184-
- name: Check out code from GitHub
185-
uses: actions/checkout@v2
186-
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
187-
uses: actions/setup-python@v2
188-
id: python
189-
with:
190-
python-version: ${{ env.DEFAULT_PYTHON }}
191-
- name: Restore base Python virtual environment
192-
id: cache-venv
193-
uses: actions/cache@v2
194-
with:
195-
path: venv
196-
key: >-
197-
${{ env.CACHE_VERSION}}-${{ runner.os }}-base-venv-${{
198-
steps.python.outputs.python-version }}-${{
199-
hashFiles('pyproject.toml') }}
200-
- name: Fail job if Python cache restore failed
201-
if: steps.cache-venv.outputs.cache-hit != 'true'
202-
run: |
203-
echo "Failed to restore Python virtual environment from cache"
204-
exit 1
205-
- name: Restore pre-commit environment from cache
206-
id: cache-precommit
207-
uses: actions/cache@v2
208-
with:
209-
path: ${{ env.PRE_COMMIT_HOME }}
210-
key: |
211-
${{ env.CACHE_VERSION}}-${{ runner.os }}-pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
212-
- name: Fail job if cache restore failed
213-
if: steps.cache-venv.outputs.cache-hit != 'true'
214-
run: |
215-
echo "Failed to restore Python virtual environment from cache"
216-
exit 1
217-
- name: Run isort
218-
run: |
219-
. venv/bin/activate
220-
pre-commit run --hook-stage manual isort --all-files --show-diff-on-failure
221-
222-
pytest:
223-
runs-on: ubuntu-latest
224-
needs: prepare-base
225-
strategy:
226-
matrix:
227-
python-version: [3.8, 3.9, "3.10", "3.11"]
228-
name: >-
229-
Run tests Python ${{ matrix.python-version }}
230-
steps:
231-
- name: Check out code from GitHub
232-
uses: actions/checkout@v2
233-
- name: Set up Python ${{ matrix.python-version }}
234-
uses: actions/setup-python@v2
235-
id: python
236-
with:
237-
python-version: ${{ matrix.python-version }}
238-
- name: Restore base Python virtual environment
239-
id: cache-venv
240-
uses: actions/cache@v2
241-
with:
242-
path: venv
243-
key: >-
244-
${{ env.CACHE_VERSION}}-${{ runner.os }}-base-venv-${{
245-
steps.python.outputs.python-version }}-${{
246-
hashFiles('pyproject.toml') }}
247-
- name: Fail job if Python cache restore failed
248-
if: steps.cache-venv.outputs.cache-hit != 'true'
249-
run: |
250-
echo "Failed to restore Python virtual environment from cache"
251-
exit 1
252-
- name: Register Python problem matcher
253-
run: |
254-
echo "::add-matcher::.github/workflows/matchers/python.json"
255-
- name: Install Pytest Annotation plugin
256-
run: |
257-
. venv/bin/activate
258-
# Ideally this should be part of our dependencies
259-
# However this plugin is fairly new and doesn't run correctly
260-
# on a non-GitHub environment.
261-
pip install pytest-github-actions-annotate-failures
262-
- name: Run pytest
263-
run: |
264-
. venv/bin/activate
265-
pytest \
266-
-qq \
267-
--timeout=30 \
268-
--durations=10 \
269-
--cov zigpy_znp \
270-
--cov-config pyproject.toml \
271-
-o console_output_style=count \
272-
-p no:sugar \
273-
tests
274-
- name: Upload coverage artifact
275-
uses: actions/upload-artifact@v2
276-
with:
277-
name: coverage-${{ matrix.python-version }}
278-
path: .coverage
279-
280-
281-
coverage:
282-
name: Process test coverage
283-
runs-on: ubuntu-latest
284-
needs: pytest
285-
steps:
286-
- name: Check out code from GitHub
287-
uses: actions/checkout@v2
288-
- name: Set up Python ${{ matrix.python-version }}
289-
uses: actions/setup-python@v2
290-
id: python
291-
with:
292-
python-version: ${{ env.DEFAULT_PYTHON }}
293-
- name: Restore base Python virtual environment
294-
id: cache-venv
295-
uses: actions/cache@v2
296-
with:
297-
path: venv
298-
key: >-
299-
${{ env.CACHE_VERSION}}-${{ runner.os }}-base-venv-${{
300-
steps.python.outputs.python-version }}-${{
301-
hashFiles('pyproject.toml') }}
302-
- name: Fail job if Python cache restore failed
303-
if: steps.cache-venv.outputs.cache-hit != 'true'
304-
run: |
305-
echo "Failed to restore Python virtual environment from cache"
306-
exit 1
307-
- name: Download all coverage artifacts
308-
uses: actions/download-artifact@v2
309-
- name: Combine coverage results
310-
run: |
311-
. venv/bin/activate
312-
coverage combine coverage*/.coverage*
313-
coverage report --fail-under=98
314-
coverage xml
315-
- name: Upload coverage to Codecov
316-
uses: codecov/codecov-action@v2
8+
shared-ci:
9+
uses: zigpy/workflows/.github/workflows/ci.yml@main
10+
with:
11+
CODE_FOLDER: zigpy_znp
12+
CACHE_VERSION: 2
13+
PRE_COMMIT_CACHE_PATH: ~/.cache/pre-commit
14+
PYTHON_VERSION_DEFAULT: 3.9.15
15+
MINIMUM_COVERAGE_PERCENTAGE: 95

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ readme = "README.md"
1414
license = {text = "GPL-3.0"}
1515
requires-python = ">=3.8"
1616
dependencies = [
17-
"zigpy>=0.55.0",
17+
"zigpy>=0.56.3",
1818
"async_timeout",
1919
"voluptuous",
2020
"coloredlogs",

requirements_test.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pytest>=7.3.1
2+
pytest-asyncio>=0.21.0
3+
pytest-timeout>=2.1.0
4+
pytest-mock>=3.10.0
5+
pytest-cov>=4.1.0

0 commit comments

Comments
 (0)