Duncan Tourolle f7c2933e54
All checks were successful
Python CI / test (push) Successful in 38s
yet another attempt
2025-06-07 16:59:42 +02:00

178 lines
6.6 KiB
YAML

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
pip install -e .
# Install test dependencies if they exist
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
if [ -f requirements/test.txt ]; then pip install -r requirements/test.txt; fi
# Install common test packages
pip install pytest pytest-cov flake8 coverage-badge interrogate
- name: Download initial failed badges
run: |
echo "Downloading initial failed badges..."
# Download failed badges as defaults
curl -o coverage.svg "https://img.shields.io/badge/coverage-failed-red.svg"
curl -o coverage-docs.svg "https://img.shields.io/badge/docs-failed-red.svg"
echo "Initial failed badges created:"
ls -la coverage*.svg
- name: Run tests with pytest
id: pytest
continue-on-error: true
run: |
# Run tests with coverage
python -m pytest tests/ -v --cov=pyWebLayout --cov-report=term-missing --cov-report=json --cov-report=html
- 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 pyWebLayout/
- name: Lint with flake8
run: |
# Stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# Exit-zero treats all errors as warnings
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- 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 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 coverage-docs.svg
interrogate --generate-badge coverage-docs.svg pyWebLayout/
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
with open('coverage-summary.txt', 'w') as f:
f.write(f'{total_coverage}%')
print(f'Test Coverage: {total_coverage}%')
else:
print('No coverage data found')
"
- 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 coverage.svg ]; then
echo "✅ Test coverage badge: $(ls -lh coverage.svg)"
else
echo "❌ Test coverage badge: MISSING"
fi
if [ -f coverage-docs.svg ]; then
echo "✅ Docs coverage badge: $(ls -lh coverage-docs.svg)"
else
echo "❌ Docs coverage badge: MISSING"
fi
echo "All SVG files:"
ls -la *.svg 2>/dev/null || echo "No SVG files found"
- name: Upload coverage artifacts
uses: actions/upload-artifact@v3
with:
name: coverage-reports
path: |
coverage.svg
coverage-docs.svg
htmlcov/
coverage.json
coverage-summary.txt
- name: Safety check - prevent infinite loops
if: github.ref == 'refs/heads/master'
run: |
# Check if this is a CI-generated commit
LAST_COMMIT_MSG=$(git log -1 --pretty=%B)
if [[ "$LAST_COMMIT_MSG" == *"[skip ci]"* ]] || [[ "$LAST_COMMIT_MSG" == *"Update coverage badges"* ]]; then
echo "Last commit was CI-generated, skipping badge update to prevent loops"
echo "SKIP_BADGE_COMMIT=true" >> $GITHUB_ENV
else
echo "Safe to update badges"
echo "SKIP_BADGE_COMMIT=false" >> $GITHUB_ENV
fi
- name: Commit badges to repository
if: github.ref == 'refs/heads/master' && env.SKIP_BADGE_COMMIT != 'true'
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/pyWebLayout.git
# Force add the SVG files (ignore .gitignore)
git add -f coverage.svg coverage-docs.svg
if git diff --staged --quiet; then
echo "No badge changes to commit"
else
echo "Committing updated badges..."
git commit -m "Update coverage badges [skip ci]"
git push origin HEAD:master
fi
- name: Test package installation
run: |
# Test that the package can be imported
python -c "import pyWebLayout; print('Package imported successfully')"