A6 Submission #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Tests and Coverage | |
| on: | |
| push: | |
| branches: | |
| - a6 | |
| - hybrid-pipeline | |
| - main | |
| pull_request: | |
| branches: | |
| - a6 | |
| - hybrid-pipeline | |
| - main | |
| jobs: | |
| tests: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.10" | |
| - name: Install test dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install -r requirements-ci.txt | |
| pip install torch==2.3.1 --index-url https://download.pytorch.org/whl/cpu | |
| - name: Run tests with coverage | |
| run: | | |
| export PYTHONPATH=$PYTHONPATH:${{ github.workspace }}/src | |
| pytest --maxfail=1 --cov=src --cov-report=xml | |
| - name: Generate coverage badge | |
| run: coverage-badge -o coverage.svg -f | |
| - name: Add coverage summary to PR | |
| run: | | |
| python - << 'EOF' | |
| import os | |
| import xml.etree.ElementTree as ET | |
| xml_path = "coverage.xml" | |
| if not os.path.exists(xml_path): | |
| raise SystemExit(f"{xml_path} not found; ensure pytest-cov generated the XML report.") | |
| tree = ET.parse(xml_path) | |
| root = tree.getroot() | |
| line_rate = float(root.get("line-rate", 0.0)) * 100.0 | |
| summary_file = os.environ.get("GITHUB_STEP_SUMMARY") | |
| if summary_file: | |
| with open(summary_file, "a", encoding="utf-8") as f: | |
| f.write("## Test Coverage\\n\\n") | |
| f.write(f"Line coverage: {line_rate:.1f}%\\n") | |
| EOF | |
| - name: Upload coverage artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-artifacts | |
| path: | | |
| coverage.xml | |
| coverage.svg | |
| - name: Commit updated coverage badge | |
| if: github.ref == 'refs/heads/a6' | |
| uses: stefanzweifel/git-auto-commit-action@v5 | |
| with: | |
| commit_message: "chore: update coverage badge" | |
| file_pattern: coverage.svg |