name: Test Suite & Coverage on: push: branches: [ main, dev ] pull_request: branches: [ main, dev ] jobs: test: runs-on: ubuntu-latest strategy: matrix: python-version: ['3.10', '3.11', '3.12'] steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} cache: 'pip' - name: Install dependencies run: | python -m pip install --upgrade pip pip install -r requirements-dev.txt pip install pytest pytest-cov pytest-asyncio pytest-benchmark - name: Run tests run: | python -m pytest tests/ -v --tb=short --cov=hearthnet --cov-report=xml --cov-report=html - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 with: file: ./coverage.xml flags: unittests name: codecov-umbrella - name: Generate coverage badge run: | python -c " import xml.etree.ElementTree as ET tree = ET.parse('coverage.xml') root = tree.getroot() coverage = float(root.attrib.get('line-rate', 0)) * 100 print(f'Coverage: {coverage:.1f}%') " - name: Comment PR with test results if: github.event_name == 'pull_request' uses: actions/github-script@v7 with: script: | const fs = require('fs'); const coverage = fs.readFileSync('./coverage.xml', 'utf8'); github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: 'āœ… All tests passed!\n\nšŸ“Š [View Coverage Report](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})' });