Repository navigation
163 lines (152 loc) · 5.49 KB
/
Copy pathpython-modules.yml
File metadata and controls
163 lines (152 loc) · 5.49 KB
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
name: Python Modules
on:
push:
branches: [dev]
paths:
- 'modules/**/*.py'
- 'modules/common/biometrics/*.json'
- 'modules/piezo-processor/fixtures/*.json'
- 'modules/**/pyproject.toml'
- 'modules/**/uv.lock'
- 'modules/.coveragerc'
- 'scripts/**/*.py'
- '.github/workflows/python-modules.yml'
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'modules/**/*.py'
- 'modules/common/biometrics/*.json'
- 'modules/piezo-processor/fixtures/*.json'
- 'modules/**/pyproject.toml'
- 'modules/**/uv.lock'
- 'modules/.coveragerc'
- 'scripts/**/*.py'
- '.github/workflows/python-modules.yml'
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
id-token: write
jobs:
pytest:
name: pytest (${{ matrix.module.name }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
module:
# `common` has no pyproject.toml; tests live under modules/common/
# and import `from common.X`, so they must run with cwd=modules/.
#
# We don't `pip install -e .` per module: each module is a flat
# layout with `main.py` + `test_main.py` at the top, which trips
# setuptools auto-discovery ("Multiple top-level modules"). Tests
# don't need the module installed anyway — they `from main import`
# via cwd. We just install the runtime deps main.py loads at
# import time (the rest are stubbed in sys.modules by the tests).
- name: common
workdir: modules
target: common
cov_source: common
# Build-identity tests inspect installed NumPy/SciPy metadata;
# use the piezo module's locked environment, including cbor2.
deps: ""
- name: cover-buttons
workdir: modules/cover-buttons
target: .
cov_source: .
deps: ""
- name: environment-monitor
workdir: modules/environment-monitor
target: .
cov_source: .
deps: ""
- name: calibrator
workdir: modules/calibrator
target: .
cov_source: .
deps: ""
- name: piezo-processor
workdir: modules/piezo-processor
target: .
cov_source: .
cov_extra: "--cov=../common/biometrics"
deps: "numpy scipy"
- name: sleep-detector
workdir: modules/sleep-detector
target: .
cov_source: .
deps: ""
# Stdlib-only repo scripts; tests load them by path from
# scripts/tests/.
- name: scripts
workdir: scripts
target: tests
cov_source: .
deps: ""
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
# Pod runtime is pinned to 3.10 by every module's pyproject
# (`requires-python = ">=3.9,<3.11"`). Match it in CI.
python-version: '3.10'
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
- name: Install test deps
working-directory: ${{ matrix.module.workdir }}
run: |
if [ "${{ matrix.module.name }}" = "common" ]; then
# Keep common's cwd/import layout while using the numerical lock.
UV_PROJECT_ENVIRONMENT="$PWD/.venv" uv sync --project piezo-processor --locked --no-install-project
elif [ -f uv.lock ]; then
uv sync --locked --no-install-project
else
uv venv .venv
if [ -n "${{ matrix.module.deps }}" ]; then
uv pip install --python .venv/bin/python ${{ matrix.module.deps }}
fi
fi
# shellcheck source=/dev/null
. .venv/bin/activate
uv pip install pytest pytest-cov
- name: Run pytest with coverage
working-directory: ${{ matrix.module.workdir }}
run: |
# shellcheck source=/dev/null
. .venv/bin/activate
pytest ${{ matrix.module.target }} \
--cov-config=${{ github.workspace }}/modules/.coveragerc \
--cov=${{ matrix.module.cov_source }} \
${{ matrix.module.cov_extra }} \
--cov-report=xml:coverage.xml \
--junit-xml=junit.xml \
-o junit_family=legacy
- name: Upload coverage to Codecov
if: ${{ github.repository == 'sleepypod/core' && !cancelled() }}
uses: codecov/codecov-action@v5
with:
use_oidc: true
fail_ci_if_error: false
slug: sleepypod/core
flags: python,${{ matrix.module.name }}
files: ${{ matrix.module.workdir }}/coverage.xml
# Coverage XML uses paths relative to the pytest run dir; tell
# Codecov where that was so report paths resolve to repo paths.
working-directory: ${{ matrix.module.workdir }}
- name: Upload test results to Codecov
if: ${{ github.repository == 'sleepypod/core' && !cancelled() }}
uses: codecov/codecov-action@v5
with:
report_type: test_results
use_oidc: true
fail_ci_if_error: false
slug: sleepypod/core
flags: python,${{ matrix.module.name }}
files: ${{ matrix.module.workdir }}/junit.xml