107 lines
3.9 KiB
YAML
107 lines
3.9 KiB
YAML
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)
|
|
|
|
# Generate test coverage badge or error badge
|
|
if [ "${{ steps.pytest.outcome }}" == "success" ] && [ -f coverage.json ]; then
|
|
coverage-badge -o coverage-${COMMIT_HASH}.svg
|
|
else
|
|
# Create error badge for test coverage
|
|
curl -o coverage-${COMMIT_HASH}.svg "https://img.shields.io/badge/coverage-error-red.svg"
|
|
fi
|
|
|
|
# Generate docs coverage badge or error badge
|
|
if [ "${{ steps.docs.outcome }}" == "success" ]; then
|
|
interrogate --generate-badge coverage-docs-${COMMIT_HASH}.svg pyWebLayout/
|
|
else
|
|
# Create error badge for docs coverage
|
|
curl -o coverage-docs-${COMMIT_HASH}.svg "https://img.shields.io/badge/docs-error-red.svg"
|
|
fi
|
|
|
|
- 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: 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')" |