From d911f00c937c96dd240dcb6d9dd377d075ab6b0c Mon Sep 17 00:00:00 2001 From: Duncan Tourolle Date: Thu, 27 Nov 2025 22:07:58 +0100 Subject: [PATCH] added badges to main repo --- .gitea/workflows/tests.yml | 108 ++++++++++++++++++++++++++++++++++--- BADGES.md | 70 ------------------------ README.md | 8 +++ 3 files changed, 108 insertions(+), 78 deletions(-) delete mode 100644 BADGES.md diff --git a/.gitea/workflows/tests.yml b/.gitea/workflows/tests.yml index 87036ba..81f1350 100644 --- a/.gitea/workflows/tests.yml +++ b/.gitea/workflows/tests.yml @@ -1,6 +1,13 @@ name: Tests -on: [push, pull_request] +on: + push: + branches: [main, master, develop] + paths-ignore: + - 'coverage*.svg' + - 'README.md' + pull_request: + branches: [main, master, develop] jobs: test: @@ -8,29 +15,114 @@ jobs: strategy: matrix: python-version: ['3.11', '3.12', '3.13', '3.14'] - + steps: - name: Checkout code uses: actions/checkout@v3 - + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + + - name: Install system dependencies + run: | + sudo apt-get update + sudo apt-get install -y xvfb libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xfixes0 libegl1 libgl1-mesa-glx + - name: Install Python dependencies run: | python -m pip install --upgrade pip pip install -e ".[dev]" - - - name: Run tests with coverage + pip install coverage-badge interrogate + + - name: Download initial failed badges run: | - xvfb-run -a pytest --cov=pyPhotoAlbum --cov-report=xml --cov-report=term-missing + mkdir -p cov_info + 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: Run tests with coverage + id: pytest + continue-on-error: true + run: | + xvfb-run -a pytest --cov=pyPhotoAlbum --cov-report=xml --cov-report=json --cov-report=html --cov-report=term-missing env: QT_QPA_PLATFORM: offscreen - - - name: Upload coverage reports + + - name: Check documentation coverage + id: docs + continue-on-error: true + run: | + interrogate -v --ignore-init-method --ignore-init-module --ignore-magic --ignore-private --ignore-property-decorators --ignore-semiprivate --fail-under=80 pyPhotoAlbum/ + + - name: Update test coverage badge on success + if: steps.pytest.outcome == 'success' && always() + run: | + if [ -f coverage.json ]; then + coverage-badge -o cov_info/coverage.svg -f + echo "✅ Test coverage badge updated" + fi + + - name: Update docs coverage badge on success + if: steps.docs.outcome == 'success' && always() + run: | + rm -f cov_info/coverage-docs.svg + interrogate --generate-badge cov_info/coverage-docs.svg pyPhotoAlbum/ + echo "✅ Docs coverage badge updated" + + - name: Generate coverage reports + if: steps.pytest.outcome == 'success' + run: | + python -c " + import json + import os + if os.path.exists('coverage.json'): + with open('coverage.json', 'r') as f: + coverage_data = json.load(f) + total_coverage = round(coverage_data['totals']['percent_covered'], 1) + with open('cov_info/coverage-summary.txt', 'w') as f: + f.write(f'{total_coverage}%') + print(f'Test Coverage: {total_coverage}%') + " + 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() + 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 + uses: actions/upload-artifact@v3 + with: + name: coverage-reports + path: cov_info/ + + - name: Upload coverage reports to Codecov if: matrix.python-version == '3.11' uses: codecov/codecov-action@v3 with: file: ./coverage.xml fail_ci_if_error: false + + - name: Commit badges to badges branch + if: github.ref == 'refs/heads/master' && matrix.python-version == '3.11' + 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/pyPhotoAlbum.git + + 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 diff --git a/BADGES.md b/BADGES.md deleted file mode 100644 index ec8fc77..0000000 --- a/BADGES.md +++ /dev/null @@ -1,70 +0,0 @@ -# Coverage Badges Integration - -This document explains how to integrate the coverage badges generated by the CI workflow into your README. - -## How It Works - -The Python CI workflow automatically: -1. Runs tests with coverage reporting -2. Checks documentation coverage with interrogate -3. Generates coverage badges -4. Commits badges to a separate `badges` branch - -## Using the Badges in README - -Once the workflow has run successfully on the `master` branch, you can add the following badges to your README.md: - -### Test Coverage Badge - -```markdown -![Coverage Badge](https://gitea.tourolle.paris/dtourolle/pyPhotoAlbum/raw/branch/badges/cov_info/coverage.svg) -``` - -### Documentation Coverage Badge - -```markdown -![Docs Badge](https://gitea.tourolle.paris/dtourolle/pyPhotoAlbum/raw/branch/badges/cov_info/coverage-docs.svg) -``` - -## Example README Section - -```markdown -# pyPhotoAlbum - -![Coverage Badge](https://gitea.tourolle.paris/dtourolle/pyPhotoAlbum/raw/branch/badges/cov_info/coverage.svg) -![Docs Badge](https://gitea.tourolle.paris/dtourolle/pyPhotoAlbum/raw/branch/badges/cov_info/coverage-docs.svg) - -A Python application for designing photo albums and exporting them to PDF. -``` - -## Workflow Details - -- **Workflow File**: `.gitea/workflows/ci.yml` -- **Trigger**: Pushes to `main`, `master`, or `develop` branches -- **Runner**: Self-hosted -- **Badge Branch**: `badges` (automatically created/updated) -- **Badge Location**: `cov_info/` directory in badges branch - -## Requirements - -The workflow requires a `PUSH_TOKEN` secret to be configured in your Gitea repository settings. This token allows the workflow to push to the badges branch. - -### Setting Up the PUSH_TOKEN - -1. Go to your Gitea profile settings -2. Navigate to Applications → Generate New Token -3. Give it a descriptive name (e.g., "CI Badges Token") -4. Select the `repository` scope -5. Generate the token -6. Go to your repository → Settings → Secrets -7. Add a new secret named `PUSH_TOKEN` with the token value - -## Coverage Reports - -In addition to badges, the workflow also generates: -- `coverage.json` - Machine-readable coverage data -- `coverage.xml` - XML format coverage report -- `htmlcov/` - HTML coverage report -- `coverage-summary.txt` - Simple text summary of coverage percentage - -All these files are available as artifacts after each workflow run and are stored in the `badges` branch under `cov_info/`. diff --git a/README.md b/README.md index 03e6f30..8a841cf 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,13 @@ # pyPhotoAlbum +| Badge | Description | +|-------|-------------| +| ![Test Coverage](https://gitea.tourolle.paris/dtourolle/pyPhotoAlbum/raw/branch/badges/cov_info/coverage.svg) | **Test Coverage** - Percentage of code covered by unit tests | +| ![Documentation Coverage](https://gitea.tourolle.paris/dtourolle/pyPhotoAlbum/raw/branch/badges/cov_info/coverage-docs.svg) | **Documentation Coverage** - Percentage of code with docstrings | +| ![License](https://img.shields.io/badge/license-MIT-blue.svg) | **License** - Project licensing information | + +> 📋 **Note**: Badges show results from the commit referenced in the URLs. Red "error" badges indicate build failures for that specific step. + A Python-based desktop application for designing photo albums with an intuitive interface and professional PDF export capabilities. ## Overview