name: Python CI on: push: branches: [ main, master, develop ] 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: 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: 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: Generate coverage badges run: | COMMIT_HASH=$(git rev-parse --short HEAD) echo "Generating badges for commit: ${COMMIT_HASH}" # Generate test coverage badge or error badge if [ "${{ steps.pytest.outcome }}" == "success" ] && [ -f coverage.json ]; then echo "Generating successful test coverage badge..." coverage-badge -o coverage-${COMMIT_HASH}.svg echo "Test coverage badge created: coverage-${COMMIT_HASH}.svg" else echo "Generating error badge for test coverage (pytest outcome: ${{ steps.pytest.outcome }})" curl -o coverage-${COMMIT_HASH}.svg "https://img.shields.io/badge/coverage-error-red.svg" echo "Error test coverage badge created: coverage-${COMMIT_HASH}.svg" fi # Generate docs coverage badge or error badge if [ "${{ steps.docs.outcome }}" == "success" ]; then echo "Generating successful docs coverage badge..." interrogate --generate-badge coverage-docs-${COMMIT_HASH}.svg pyWebLayout/ echo "Docs coverage badge created: coverage-docs-${COMMIT_HASH}.svg" else echo "Generating error badge for docs coverage (docs outcome: ${{ steps.docs.outcome }})" curl -o coverage-docs-${COMMIT_HASH}.svg "https://img.shields.io/badge/docs-error-red.svg" echo "Error docs coverage badge created: coverage-docs-${COMMIT_HASH}.svg" fi # List all SVG files created echo "SVG files in directory:" ls -la *.svg || echo "No SVG files found" echo "Current working directory:" pwd echo "All files in current directory:" ls -la - 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: Debug artifacts before upload run: | echo "Files matching coverage patterns:" ls -la coverage-*.svg || echo "No coverage-*.svg files found" ls -la coverage-docs-*.svg || echo "No coverage-docs-*.svg files found" ls -la coverage.json || echo "No coverage.json found" ls -la coverage-summary.txt || echo "No coverage-summary.txt found" ls -la htmlcov/ || echo "No htmlcov directory found" echo "All files in current directory:" ls -la - 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: Test package installation run: | # Test that the package can be imported python -c "import pyWebLayout; print('Package imported successfully')"