name: Unit Tests
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch: # Allow manual trigger
jobs:
test-python-community:
name: Test Python (Community)
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.11", "3.12", "3.13"]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[test]
- name: Run tests with coverage
run: pytest
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-xml-community-${{ matrix.python-version }}
path: coverage.xml
- name: Fail if any file has <90% coverage (except _version.py)
run: |
coverage report -m | tee coverage.txt
awk '
NR > 2 && $1 !~ /_version\.py/ && $1 ~ /\.py/ {
cov = $4
gsub("%","",cov)
if (cov+0 < 90) {
print $1 " has coverage " cov "% which is below the required 90%."
fail=1
}
}
END { exit fail }
' coverage.txt
test-python-enterprise:
name: Test Python (Enterprise)
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.11", "3.12", "3.13"]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies with enterprise support
run: |
python -m pip install --upgrade pip
pip install ".[test,enterprise]"
- name: Run tests with coverage
run: pytest
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-xml-enterprise-${{ matrix.python-version }}
path: coverage.xml
- name: Fail if any file has <90% coverage (except _version.py)
run: |
coverage report -m | tee coverage.txt
awk '
NR > 2 && $1 !~ /_version\.py/ && $1 ~ /\.py/ {
cov = $4
gsub("%","",cov)
if (cov+0 < 90) {
print $1 " has coverage " cov "% which is below the required 90%."
fail=1
}
}
END { exit fail }
' coverage.txt