Skip to content

Commit 7d007a5

Browse files
committed
Setup action for code coverage
1 parent b7e6b09 commit 7d007a5

4 files changed

Lines changed: 2636 additions & 249 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Code Coverage
2+
3+
on:
4+
push:
5+
branches: [ '*' ] # Run on all branches
6+
pull_request:
7+
branches: [ '*' ] # Run on PRs to any branch
8+
9+
jobs:
10+
coverage:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Install Rust
17+
uses: actions-rs/toolchain@v1
18+
with:
19+
toolchain: stable
20+
components: rustfmt, clippy
21+
override: true
22+
23+
- name: Cache cargo registry
24+
uses: actions/cache@v3
25+
with:
26+
path: ~/.cargo/registry
27+
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
28+
29+
- name: Cache cargo index
30+
uses: actions/cache@v3
31+
with:
32+
path: ~/.cargo/git
33+
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
34+
35+
- name: Cache cargo build
36+
uses: actions/cache@v3
37+
with:
38+
path: target
39+
key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
40+
41+
# Install cargo-tarpaulin for coverage
42+
- name: Install cargo-tarpaulin
43+
run: cargo install cargo-tarpaulin
44+
45+
# Run coverage for main rats crate
46+
- name: Run coverage for rats
47+
run: |
48+
cd rats
49+
cargo tarpaulin --out Xml --output-dir ../coverage --exclude-files "*/tests/*" "*/examples/*"
50+
# Rename to avoid conflicts
51+
mv ../coverage/cobertura.xml ../coverage/rats-coverage.xml
52+
53+
# Run coverage for ratspy crate
54+
- name: Run coverage for ratspy
55+
run: |
56+
cd ratspy
57+
cargo tarpaulin --out Xml --output-dir ../coverage --exclude-files "*/tests/*" "*/examples/*"
58+
# Rename to avoid conflicts
59+
mv ../coverage/cobertura.xml ../coverage/ratspy-coverage.xml
60+
61+
# Install Python dependencies
62+
- name: Set up Python
63+
uses: actions/setup-python@v4
64+
with:
65+
python-version: '3.9'
66+
67+
- name: Install Python dependencies
68+
run: |
69+
cd ratspy
70+
pip install -r requirements.txt
71+
pip install coverage pytest-cov
72+
73+
# Build ratspy for Python coverage
74+
- name: Build ratspy
75+
run: |
76+
cd ratspy
77+
pip install maturin
78+
maturin develop --release
79+
80+
# Run Python coverage
81+
- name: Run Python coverage
82+
run: |
83+
cd ratspy
84+
coverage run --source=ratspy -m pytest tests/
85+
coverage xml -o ../coverage/python-coverage.xml
86+
coverage report
87+
88+
# Upload coverage to Codecov
89+
- name: Upload coverage to Codecov
90+
uses: codecov/codecov-action@v3
91+
with:
92+
file: ./coverage/rats-coverage.xml,./coverage/ratspy-coverage.xml,./coverage/python-coverage.xml
93+
flags: unittests
94+
name: codecov-umbrella
95+
fail_ci_if_error: false
96+
verbose: true

.gitignore

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,23 @@ data/
44
*.png
55
.idea
66
**/*.csv
7-
.DS_Store
7+
.DS_Store
8+
9+
# Coverage files
10+
coverage/
11+
.coverage
12+
.coverage.*
13+
htmlcov/
14+
*.coverage
15+
coverage.xml
16+
*.lcov
17+
18+
# Python cache
19+
__pycache__/
20+
*.py[cod]
21+
*$py.class
22+
*.so
23+
24+
# Rust build artifacts
25+
target/
26+
Cargo.lock

0 commit comments

Comments
 (0)