-
Notifications
You must be signed in to change notification settings - Fork 0
203 lines (174 loc) · 6.02 KB
/
tests.yml
File metadata and controls
203 lines (174 loc) · 6.02 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
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
name: "Tests"
on:
workflow_call:
jobs:
unit:
name: "Unit | Py${{ matrix.python-version }} on ${{ matrix.os }}"
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-22.04
python-version: '3.7'
- os: ubuntu-22.04
python-version: '3.8'
- os: ubuntu-22.04
python-version: '3.9'
- os: ubuntu-22.04
python-version: '3.10'
- os: ubuntu-22.04
python-version: '3.11'
- os: ubuntu-22.04
python-version: '3.12'
- os: ubuntu-22.04
python-version: '3.13'
- os: ubuntu-22.04
python-version: '3.14'
- os: macos-latest
python-version: '3.13'
- os: windows-latest
python-version: '3.13'
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
cache-dependency-path: |
pyproject.toml
uv.lock
- name: "Install unit test dependencies"
run: python -m pip install --upgrade pip pytest pytest-cov httpx requests pyyaml
- name: "Run unit tests with coverage"
env:
COVERAGE_FILE: coverage-unit.dat
run: >
pytest -q tests/unit
--cov=src/mellophone
--cov-report=
- name: "Upload unit coverage data"
if: matrix.os == 'ubuntu-22.04' && matrix.python-version == '3.13'
uses: actions/upload-artifact@v4
with:
name: coverage-unit-data
path: coverage-unit.dat
integration:
name: "Integration | Py3.13 on ubuntu-22.04"
runs-on: ubuntu-22.04
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version: '3.13'
cache: pip
cache-dependency-path: |
pyproject.toml
uv.lock
- name: "Install integration test dependencies"
run: python -m pip install --upgrade pip pytest pytest-cov httpx requests pyyaml
- name: "Cache Docker images"
id: docker-cache
uses: actions/cache@v4
with:
path: /tmp/docker-image-cache
key: docker-images-${{ runner.os }}-${{ hashFiles('docker-compose.yml') }}
- name: "Load cached Docker images"
if: steps.docker-cache.outputs.cache-hit == 'true'
shell: bash
run: |
[ -f /tmp/docker-image-cache/mellophone.tar ] && docker load -i /tmp/docker-image-cache/mellophone.tar || true
[ -f /tmp/docker-image-cache/postgres.tar ] && docker load -i /tmp/docker-image-cache/postgres.tar || true
- name: "Pull Docker images"
if: steps.docker-cache.outputs.cache-hit != 'true'
shell: bash
run: |
docker pull curs/mellophone2:1.6.1
docker pull postgres:16.3-alpine
- name: "Save Docker images to cache"
if: steps.docker-cache.outputs.cache-hit != 'true'
shell: bash
run: |
mkdir -p /tmp/docker-image-cache
docker save curs/mellophone2:1.6.1 -o /tmp/docker-image-cache/mellophone.tar
docker save postgres:16.3-alpine -o /tmp/docker-image-cache/postgres.tar
- name: "Start DB and Mellophone"
run: docker compose up -d db mellophone
- name: "Wait for Mellophone"
shell: bash
run: |
for i in {1..20}; do
if curl -fsS "http://localhost:8082/mellophone/authentication.gif?sesid=ci-smoke" >/dev/null; then
echo "Mellophone is reachable"
exit 0
fi
sleep 2
done
docker compose logs
exit 1
- name: "Run integration tests with coverage"
env:
COVERAGE_FILE: coverage-integration.dat
run: >
pytest -q tests/integration
--cov=src/mellophone
--cov-report=
- name: "Upload integration coverage data"
uses: actions/upload-artifact@v4
with:
name: coverage-integration-data
path: coverage-integration.dat
- name: "Stop services"
if: always()
run: docker compose down -v
coverage-report:
name: "Coverage Report"
needs: [unit, integration]
runs-on: ubuntu-22.04
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: "Set up Python"
uses: actions/setup-python@v5
with:
python-version: '3.13'
- name: "Download unit coverage data"
uses: actions/download-artifact@v4
with:
name: coverage-unit-data
path: coverage_data/unit
- name: "Download integration coverage data"
uses: actions/download-artifact@v4
with:
name: coverage-integration-data
path: coverage_data/integration
- name: "Install coverage tools"
run: python -m pip install --upgrade pip coverage
- name: "Combine and build coverage reports"
run: |
python -m coverage combine coverage_data/unit/coverage-unit.dat coverage_data/integration/coverage-integration.dat
python -m coverage report -m
python -m coverage xml -o coverage.xml
python -m coverage json -o coverage.json
- name: "Add coverage to job summary"
uses: actions/github-script@v7
with:
script: |
const fs = require("fs");
const report = JSON.parse(fs.readFileSync("coverage.json", "utf8"));
const total = report.totals.percent_covered_display;
core.summary
.addHeading("Coverage (unit + integration)", 2)
.addRaw(`- Total: ${total}%`)
.write();
- name: "Upload coverage artifacts"
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: |
coverage.xml
coverage.json