Add unit test coverage and CI coverage reporting (#158) #668
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: Python package | |
| permissions: | |
| contents: read | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| # Simplified to single Python version (per project requirements) | |
| # Can expand to matrix testing later: strategy.matrix.python-version: ["3.10", "3.11", "3.12", "3.13"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python 3.12 | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| python -m pip install flake8 black build diff-cover | |
| python -m pip install -e .[dev] | |
| - name: Check format with black | |
| run: | | |
| black src tests examples --check | |
| - name: Lint with flake8 | |
| run: | | |
| # stop the build if there are Python syntax errors or undefined names | |
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
| # exit-zero treats all errors as warnings, matching Agents-for-python approach | |
| flake8 . --count --exit-zero --show-source --statistics | |
| - name: Build package | |
| run: | | |
| python -m build | |
| - name: Install wheel | |
| run: | | |
| python -m pip install dist/*.whl | |
| - name: Test with pytest | |
| run: | | |
| PYTHONPATH=src pytest --junitxml=test-results.xml --cov --cov-report=xml | |
| - name: Diff coverage (90% for new changes) | |
| run: | | |
| git fetch origin ${{ github.base_ref }} | |
| diff-cover coverage.xml --compare-branch=origin/${{ github.base_ref }} --fail-under=90 | |
| - name: Upload test results | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-results | |
| path: test-results.xml | |
| - name: Upload coverage report | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-report | |
| path: coverage.xml |