Skip to content

Report unavailable job logs cleanly #27

Report unavailable job logs cleanly

Report unavailable job logs cleanly #27

name: Python Tests on PR
on:
pull_request:
branches:
- cwbi-dev
- cwbi-test
- cwbi-prod
paths:
- "cwms_batch_events/**"
- "tests/**"
- "requirements.txt"
- "requirements-dev.txt"
- "pytest.ini"
- ".github/workflows/cwbi-test-push-api.yml"
permissions:
contents: read
jobs:
python-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.13"
cache: "pip"
cache-dependency-path: |
requirements.txt
requirements-dev.txt
- name: Install dependencies
run: python -m pip install -r requirements-dev.txt
- name: Run pytest
run: pytest --cov-report=html --cov-report=json
- name: Upload coverage HTML report
if: always()
uses: actions/upload-artifact@v4
with:
name: python-htmlcov
path: htmlcov/
- name: Add coverage summary
if: always()
run: |
python - <<'PY'
import json
import os
from pathlib import Path
coverage_file = Path("coverage.json")
if not coverage_file.exists():
raise SystemExit("coverage.json was not generated")
data = json.loads(coverage_file.read_text())
total = data["totals"]["percent_covered_display"]
summary = Path(os.environ["GITHUB_STEP_SUMMARY"])
summary.write_text(
"## Python Coverage\n\n"
f"- Total coverage: `{total}%`\n"
"- HTML report: download the `python-htmlcov` artifact from this workflow run.\n",
encoding="utf-8",
)
PY