97 lines
3.0 KiB
YAML
97 lines
3.0 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
|
|
|
|
- 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
|
|
run: |
|
|
# Run tests with coverage
|
|
python -m pytest tests/ -v --cov=pyWebLayout --cov-report=term-missing --cov-report=json --cov-report=html
|
|
|
|
- name: Generate test coverage badge
|
|
run: |
|
|
# Install coverage-badge for generating badges
|
|
pip install coverage-badge
|
|
# Generate coverage badge from coverage data
|
|
coverage-badge -o coverage.svg
|
|
|
|
- name: Check documentation coverage
|
|
run: |
|
|
# Install interrogate for documentation coverage
|
|
pip install interrogate
|
|
# Generate documentation coverage report and badge
|
|
interrogate -v --ignore-init-method --ignore-init-module --ignore-magic --ignore-private --ignore-property-decorators --ignore-semiprivate --fail-under=80 --generate-badge coverage-docs.svg pyWebLayout/
|
|
|
|
- name: Generate coverage reports
|
|
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')"
|