|
| 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 |
0 commit comments