-
Notifications
You must be signed in to change notification settings - Fork 2
90 lines (79 loc) · 3.05 KB
/
run_unit_tests.yaml
File metadata and controls
90 lines (79 loc) · 3.05 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
name: Unit Testing Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
# REQUIRED so the coverage job can push to coverage-badge branch
permissions:
contents: write
jobs:
test:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Setup python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install pyhctsa dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools
pip install -r requirements.txt
pip install -e .[test]
pip install pytest-cov
# Run normal tests everywhere EXCEPT the single coverage runner
- name: Run pyhctsa unit tests
if: ${{ !(matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10') }}
run: |
pytest -v ./tests/
# Coverage run on ONE job only (ubuntu + py3.10)
- name: Run unit tests with coverage
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10' }}
run: |
mkdir -p coverage
pytest -v ./tests/ \
--cov=pyhctsa \
--cov-report=term-missing \
--cov-report=xml:coverage.xml \
--cov-report=html
- name: Prepare coverage folder
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10' && github.event_name == 'push' }}
run: |
mkdir -p coverage
cp -r htmlcov coverage/html
# Generate the badge WITHOUT tj-actions (it currently breaks due to pkg_resources/setuptools changes)
- name: Generate coverage badge (SVG)
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10' }}
run: |
# coverage-badge currently expects pkg_resources, which is absent in newer setuptools
python -m pip install "setuptools<81" coverage-badge
coverage-badge -o coverage/coverage.svg
- name: Add simple index page (optional)
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10' }}
run: |
cat > coverage/index.html <<'EOF'
<!doctype html>
<html>
<head><meta charset="utf-8"><title>Coverage</title></head>
<body>
<p><img src="coverage.svg" alt="coverage badge"></p>
<p><a href="html/index.html">Open HTML coverage report</a></p>
</body>
</html>
EOF
- name: Publish coverage badge + report to coverage-badge branch
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == '3.10' && github.event_name == 'push' }}
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: coverage-badge
folder: coverage
clean: true
single-commit: true