Update coverage badges [skip ci]
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
name: Python CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main, master, develop ]
|
||||
paths-ignore:
|
||||
- 'coverage*.svg'
|
||||
- 'README.md'
|
||||
pull_request:
|
||||
branches: [ main, master, develop ]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: linux/amd64
|
||||
container:
|
||||
# Built from Dockerfile.ci at the repo root. Carries Python 3.10-3.13,
|
||||
# each in its own venv at /opt/py<version> with every dependency
|
||||
# pre-installed, so a run downloads nothing.
|
||||
image: gitea.tourolle.paris/dtourolle/pyweblayout-ci:latest
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: ['3.10', '3.11', '3.12', '3.13']
|
||||
fail-fast: false
|
||||
|
||||
env:
|
||||
# pyWebLayout is a library: it is tested on every interpreter
|
||||
# pyproject.toml's requires-python claims to support.
|
||||
PYBIN: /opt/py${{ matrix.python-version }}/bin
|
||||
# Badges and artifacts are published once, not once per matrix leg -
|
||||
# four jobs racing to force-push the same branch is not a publish
|
||||
# strategy. This leg is the one that publishes.
|
||||
PUBLISH: ${{ matrix.python-version == '3.13' }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install project
|
||||
run: |
|
||||
# --no-deps: dependencies are baked into the image. If a new one is
|
||||
# added to pyproject.toml, add it to Dockerfile.ci and rebuild;
|
||||
# the check below is what catches forgetting to.
|
||||
$PYBIN/pip install -e . --no-deps
|
||||
$PYBIN/python -c "import pyWebLayout; print('pyWebLayout', pyWebLayout.__file__)"
|
||||
|
||||
- name: Verify declared dependencies are sufficient
|
||||
if: env.PUBLISH == 'true'
|
||||
run: |
|
||||
# A clean venv with ONLY the declared runtime deps, installed from
|
||||
# the index rather than from the image. If an import here fails,
|
||||
# pyproject.toml is incomplete and a real `pip install pyWebLayout`
|
||||
# fails the same way for a user. This is the one step that is
|
||||
# allowed to reach the network.
|
||||
$PYBIN/python -m venv /tmp/clean-install
|
||||
/tmp/clean-install/bin/pip install --upgrade pip
|
||||
/tmp/clean-install/bin/pip install .
|
||||
/tmp/clean-install/bin/python -c "
|
||||
import pyWebLayout.concrete, pyWebLayout.abstract
|
||||
import pyWebLayout.io.readers.epub_reader
|
||||
import pyWebLayout.io.readers.html_extraction
|
||||
import pyWebLayout.layout.ereader_manager
|
||||
print('clean install imports OK')
|
||||
"
|
||||
|
||||
- name: Run tests with pytest
|
||||
id: pytest
|
||||
continue-on-error: true
|
||||
run: |
|
||||
$PYBIN/python -m pytest tests/ -v \
|
||||
--cov=pyWebLayout \
|
||||
--cov-report=term-missing \
|
||||
--cov-report=json \
|
||||
--cov-report=html \
|
||||
--cov-report=xml
|
||||
|
||||
- name: Check documentation coverage
|
||||
id: docs
|
||||
continue-on-error: true
|
||||
run: |
|
||||
$PYBIN/interrogate -v \
|
||||
--ignore-init-method --ignore-init-module --ignore-magic \
|
||||
--ignore-private --ignore-property-decorators --ignore-semiprivate \
|
||||
--fail-under=80 pyWebLayout/
|
||||
|
||||
- name: Lint with flake8
|
||||
run: |
|
||||
# Stop the build if there are Python syntax errors or undefined names
|
||||
$PYBIN/flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
|
||||
# Exit-zero treats all errors as warnings
|
||||
$PYBIN/flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
|
||||
|
||||
- name: Fail the job if tests failed
|
||||
if: steps.pytest.outcome != 'success'
|
||||
run: |
|
||||
# pytest runs with continue-on-error so the badge steps below still
|
||||
# execute; without this the job would report green on a red suite.
|
||||
echo "::error::pytest failed on Python ${{ matrix.python-version }}"
|
||||
exit 1
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
# Badges and artifacts - publishing leg only
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
- name: Prepare badge directory
|
||||
if: always() && env.PUBLISH == 'true'
|
||||
run: |
|
||||
mkdir -p cov_info
|
||||
# Default to failed badges; the steps below overwrite them on success
|
||||
curl -o cov_info/coverage.svg "https://img.shields.io/badge/coverage-failed-red.svg"
|
||||
curl -o cov_info/coverage-docs.svg "https://img.shields.io/badge/docs-failed-red.svg"
|
||||
|
||||
- name: Update test coverage badge on success
|
||||
if: always() && env.PUBLISH == 'true' && steps.pytest.outcome == 'success'
|
||||
run: |
|
||||
if [ -f coverage.json ]; then
|
||||
$PYBIN/coverage-badge -o cov_info/coverage.svg -f
|
||||
echo "✅ Test coverage badge updated"
|
||||
else
|
||||
echo "⚠️ No coverage.json found, keeping failed badge"
|
||||
fi
|
||||
|
||||
- name: Update docs coverage badge on success
|
||||
if: always() && env.PUBLISH == 'true' && steps.docs.outcome == 'success'
|
||||
run: |
|
||||
rm -f cov_info/coverage-docs.svg
|
||||
$PYBIN/interrogate --generate-badge cov_info/coverage-docs.svg pyWebLayout/
|
||||
echo "✅ Docs coverage badge updated"
|
||||
|
||||
- name: Generate coverage reports
|
||||
if: env.PUBLISH == 'true' && steps.pytest.outcome == 'success'
|
||||
run: |
|
||||
$PYBIN/python -c "
|
||||
import json, os
|
||||
if os.path.exists('coverage.json'):
|
||||
with open('coverage.json') as f:
|
||||
data = json.load(f)
|
||||
total = round(data['totals']['percent_covered'], 1)
|
||||
with open('cov_info/coverage-summary.txt', 'w') as f:
|
||||
f.write(f'{total}%')
|
||||
print(f\"Test Coverage: {total}%\")
|
||||
print(f\"Lines Covered: {data['totals']['covered_lines']}/{data['totals']['num_statements']}\")
|
||||
else:
|
||||
print('No coverage data found')
|
||||
"
|
||||
if [ -f coverage.json ]; then cp coverage.json cov_info/; fi
|
||||
if [ -f coverage.xml ]; then cp coverage.xml cov_info/; fi
|
||||
if [ -d htmlcov ]; then cp -r htmlcov cov_info/; fi
|
||||
|
||||
- name: Final badge status
|
||||
if: always() && env.PUBLISH == 'true'
|
||||
run: |
|
||||
echo "=== FINAL BADGE STATUS ==="
|
||||
echo "Test outcome: ${{ steps.pytest.outcome }}"
|
||||
echo "Docs outcome: ${{ steps.docs.outcome }}"
|
||||
ls -la cov_info/ 2>/dev/null || echo "No cov_info directory"
|
||||
|
||||
- name: Upload coverage artifacts
|
||||
if: always() && env.PUBLISH == 'true'
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: coverage-reports
|
||||
path: cov_info/
|
||||
|
||||
- name: Commit badges to badges branch
|
||||
if: env.PUBLISH == 'true' && github.ref == 'refs/heads/master'
|
||||
run: |
|
||||
git config --local user.email "action@gitea.local"
|
||||
git config --local user.name "Gitea Action"
|
||||
|
||||
git remote set-url origin https://${{ secrets.PUSH_TOKEN }}@gitea.tourolle.paris/dtourolle/pyWebLayout.git
|
||||
|
||||
# Orphan branch holding only the badges, force-pushed each time
|
||||
git checkout --orphan badges
|
||||
find . -maxdepth 1 -not -name '.git' -not -name 'cov_info' -exec rm -rf {} + 2>/dev/null || true
|
||||
git add -f cov_info/
|
||||
git commit -m "Update coverage badges [skip ci]"
|
||||
git push -f origin badges
|
||||
Reference in New Issue
Block a user