From 15d8ca8c05c7b8cda1656e10062ec4e429cdc235 Mon Sep 17 00:00:00 2001 From: Duncan Tourolle Date: Sat, 20 Jun 2026 14:54:22 +0200 Subject: [PATCH] Fix ci more --- .gitea/workflows/ci.yml | 182 -------------------------------------- .gitea/workflows/lint.yml | 22 ++--- Dockerfile.ci | 2 + Dockerfile.debian-test | 63 +++++++++++++ 4 files changed, 72 insertions(+), 197 deletions(-) delete mode 100644 .gitea/workflows/ci.yml create mode 100644 Dockerfile.debian-test diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml deleted file mode 100644 index 5ae85f2..0000000 --- a/.gitea/workflows/ci.yml +++ /dev/null @@ -1,182 +0,0 @@ -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: self-hosted - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.x' - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - # Install package in development mode with dev dependencies - pip install -e ".[dev]" - # Install additional test packages - pip install coverage-badge interrogate - - - name: Download initial failed badges - run: | - echo "Downloading initial failed badges..." - - # Create cov_info directory first - mkdir -p cov_info - - # Download failed badges as defaults - 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" - - echo "Initial failed badges created:" - ls -la cov_info/coverage*.svg - - - name: Run tests with pytest - id: pytest - continue-on-error: true - run: | - # Run tests with coverage - # Check if xvfb-run is available, use it if present - if command -v xvfb-run &> /dev/null; then - echo "Using xvfb-run for headless Qt testing" - xvfb-run -a python -m pytest tests/ -v --cov=pyPhotoAlbum --cov-report=term-missing --cov-report=json --cov-report=html --cov-report=xml - else - echo "xvfb-run not found, running with QT_QPA_PLATFORM=offscreen only" - python -m pytest tests/ -v --cov=pyPhotoAlbum --cov-report=term-missing --cov-report=json --cov-report=html --cov-report=xml - fi - env: - QT_QPA_PLATFORM: offscreen - - - name: Check documentation coverage - id: docs - continue-on-error: true - run: | - # Generate documentation coverage report - interrogate -v --ignore-init-method --ignore-init-module --ignore-magic --ignore-private --ignore-property-decorators --ignore-semiprivate --fail-under=80 pyPhotoAlbum/ - - - name: Lint with flake8 - run: | - # Stop the build if there are Python syntax errors or undefined names - flake8 pyPhotoAlbum --count --select=E9,F63,F7,F82 --show-source --statistics - # Exit-zero treats all errors as warnings - flake8 pyPhotoAlbum --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - - name: Create coverage info directory - if: always() - run: | - mkdir -p cov_info - echo "Created cov_info directory for coverage data" - - - name: Update test coverage badge on success - if: steps.pytest.outcome == 'success' && always() - run: | - echo "Tests passed! Generating successful coverage badge..." - - if [ -f coverage.json ]; then - coverage-badge -o cov_info/coverage.svg -f - echo "✅ Test coverage badge updated with actual results" - else - echo "⚠️ No coverage.json found, keeping failed badge" - fi - - - name: Update docs coverage badge on success - if: steps.docs.outcome == 'success' && always() - run: | - echo "Docs check passed! Generating successful docs badge..." - - # Remove existing badge first to avoid overwrite error - rm -f cov_info/coverage-docs.svg - interrogate --generate-badge cov_info/coverage-docs.svg pyPhotoAlbum/ - echo "✅ Docs coverage badge updated with actual results" - - - name: Generate coverage reports - if: steps.pytest.outcome == 'success' - run: | - # Generate coverage summary for README - python -c " - import json - import os - # Read coverage data - 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) - # Create coverage summary file in cov_info directory - with open('cov_info/coverage-summary.txt', 'w') as f: - f.write(f'{total_coverage}%') - print(f'Test Coverage: {total_coverage}%') - covered_lines = coverage_data['totals']['covered_lines'] - total_lines = coverage_data['totals']['num_statements'] - print(f'Lines Covered: {covered_lines}/{total_lines}') - else: - print('No coverage data found') - " - - # Copy other coverage files to cov_info - 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 }}" - - if [ -f cov_info/coverage.svg ]; then - echo "✅ Test coverage badge: $(ls -lh cov_info/coverage.svg)" - else - echo "❌ Test coverage badge: MISSING" - fi - - if [ -f cov_info/coverage-docs.svg ]; then - echo "✅ Docs coverage badge: $(ls -lh cov_info/coverage-docs.svg)" - else - echo "❌ Docs coverage badge: MISSING" - fi - - echo "Coverage info directory contents:" - ls -la cov_info/ 2>/dev/null || echo "No cov_info directory found" - - - name: Upload coverage artifacts - uses: actions/upload-artifact@v3 - with: - name: coverage-reports - path: | - cov_info/ - - - name: Commit badges to badges branch - if: github.ref == 'refs/heads/master' - run: | - git config --local user.email "action@gitea.local" - git config --local user.name "Gitea Action" - - # Set the remote URL to use the token - git remote set-url origin https://${{ secrets.PUSH_TOKEN }}@gitea.tourolle.paris/dtourolle/pyPhotoAlbum.git - - # Create a new orphan branch for badges (this discards any existing badges branch) - git checkout --orphan badges - - # Remove all files except cov_info - find . -maxdepth 1 -not -name '.git' -not -name 'cov_info' -exec rm -rf {} + 2>/dev/null || true - - # Add only the coverage info directory - git add -f cov_info/ - - # Always commit (force overwrite) - echo "Force updating badges branch with new coverage data..." - git commit -m "Update coverage badges [skip ci]" - git push -f origin badges diff --git a/.gitea/workflows/lint.yml b/.gitea/workflows/lint.yml index 15a3535..8a0c808 100644 --- a/.gitea/workflows/lint.yml +++ b/.gitea/workflows/lint.yml @@ -4,34 +4,26 @@ on: [push, pull_request] jobs: lint: - runs-on: ubuntu-latest - + runs-on: linux/amd64 + container: + image: gitea.tourolle.paris/dtourolle/pyphotoalbum-ci:latest + steps: - name: Checkout code uses: actions/checkout@v3 - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.11' - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 black mypy - + - name: Run flake8 run: | # Stop the build if there are Python syntax errors or undefined names flake8 pyPhotoAlbum --count --select=E9,F63,F7,F82 --show-source --statistics # Exit-zero treats all errors as warnings flake8 pyPhotoAlbum --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - + - name: Check formatting with black run: | black --check pyPhotoAlbum continue-on-error: true - + - name: Type check with mypy run: | mypy pyPhotoAlbum --ignore-missing-imports diff --git a/Dockerfile.ci b/Dockerfile.ci index 0d756a1..e04657b 100644 --- a/Dockerfile.ci +++ b/Dockerfile.ci @@ -60,6 +60,8 @@ RUN pip3 install --break-system-packages --no-cache-dir \ pytest-mock \ pdfplumber \ flake8 \ + black \ + mypy \ coverage-badge \ interrogate \ setuptools diff --git a/Dockerfile.debian-test b/Dockerfile.debian-test new file mode 100644 index 0000000..5aade44 --- /dev/null +++ b/Dockerfile.debian-test @@ -0,0 +1,63 @@ +# Dockerfile for testing pyPhotoAlbum installation on Debian +FROM debian:bookworm + +# Avoid interactive prompts +ENV DEBIAN_FRONTEND=noninteractive + +# Install system dependencies (same as install-debian.sh) +RUN apt-get update && apt-get install -y \ + sudo \ + curl \ + python3 \ + python3-venv \ + python3-pip \ + libgl1-mesa-dev \ + libglu1-mesa-dev \ + libxcb-xinerama0 \ + libxcb-cursor0 \ + libxkbcommon0 \ + libdbus-1-3 \ + libegl1 \ + libfontconfig1 \ + libfreetype6 \ + libx11-6 \ + libx11-xcb1 \ + libxcb1 \ + libxcb-glx0 \ + libxcb-icccm4 \ + libxcb-image0 \ + libxcb-keysyms1 \ + libxcb-randr0 \ + libxcb-render0 \ + libxcb-render-util0 \ + libxcb-shape0 \ + libxcb-shm0 \ + libxcb-sync1 \ + libxcb-xfixes0 \ + libxcb-xkb1 \ + libxkbcommon-x11-0 \ + libglib2.0-0 \ + libgtk-3-0 \ + && rm -rf /var/lib/apt/lists/* + +# Create a non-root user for testing +RUN useradd -m -s /bin/bash testuser && \ + echo "testuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers + +# Copy project files +WORKDIR /home/testuser/pyPhotoAlbum +COPY . . + +# Fix ownership +RUN chown -R testuser:testuser /home/testuser/pyPhotoAlbum + +# Switch to test user +USER testuser + +# Create venv and install +RUN python3 -m venv venv && \ + ./venv/bin/pip install --upgrade pip && \ + ./venv/bin/pip install -e . + +# Default command - run the app +CMD ["./launch-pyphotoalbum.sh"]