|
| 1 | +# GitHub Actions CI/CD Setup |
| 2 | + |
| 3 | +This directory contains the complete CI/CD setup for the python-simple-ioc project. |
| 4 | + |
| 5 | +## Workflows Overview |
| 6 | + |
| 7 | +### 🚀 Main CI Workflow (`ci.yml`) |
| 8 | +- **Purpose**: Primary continuous integration for every push and PR |
| 9 | +- **Features**: |
| 10 | + - Tests against Python 3.9, 3.10, 3.11, 3.12, and 3.13 |
| 11 | + - Runs flake8 linting (required to pass) |
| 12 | + - Executes core tests using smart dependency detection |
| 13 | + - Optional mypy type checking (non-blocking) |
| 14 | + |
| 15 | +### 🧪 Comprehensive Testing (`tests.yml`) |
| 16 | +- **Purpose**: Detailed testing with multiple configurations and optional dependencies |
| 17 | +- **Jobs**: |
| 18 | + - **Lint**: Flake8 and optional mypy across all Python versions |
| 19 | + - **Core Tests**: Tests without optional dependencies |
| 20 | + - **Specific Extras**: Tests individual optional dependencies (flask, jinja2, redis) |
| 21 | + - **All Extras**: Tests with all optional dependencies installed |
| 22 | + - **Documentation**: Builds Sphinx docs and uploads artifacts |
| 23 | + - **Package**: Validates package building |
| 24 | + |
| 25 | +### 🌍 Cross-Platform Testing (`test-matrix.yml`) |
| 26 | +- **Purpose**: Ensure compatibility across operating systems |
| 27 | +- **Coverage**: Linux, macOS, and Windows |
| 28 | +- **Focus**: Core functionality verification |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +### 🏷️ Release Automation (`release.yml`) |
| 33 | +- **Purpose**: Automated package building and PyPI publishing |
| 34 | +- **Triggers**: Git tags (version tags) |
| 35 | +- **Features**: |
| 36 | + - Runs full test suite before releasing |
| 37 | + - Builds and validates package |
| 38 | + - Publishes to Test PyPI first (if token available) |
| 39 | + - Publishes to PyPI for tagged releases |
| 40 | + |
| 41 | +## Smart Dependency Handling |
| 42 | + |
| 43 | +### Problem Solved |
| 44 | +The project has optional dependencies (flask, jinja2, redis) that may not be installed in all environments. Traditional test runs would fail with import errors. |
| 45 | + |
| 46 | +### Solution |
| 47 | +- **Workflow-Level Detection**: CI jobs check for dependency availability before running tests |
| 48 | +- **Graceful Degradation**: Tests skip gracefully when dependencies are missing |
| 49 | +- **Clear Reporting**: Distinguish between real failures and expected missing dependencies |
| 50 | +- **Smart Test Scripts**: Embedded test runners in workflows that detect available dependencies |
| 51 | + |
| 52 | +### Usage Examples |
| 53 | + |
| 54 | +```bash |
| 55 | +# Run core tests only (no optional dependencies) |
| 56 | +python -m unittest discover -s tests -p "test_*.py" | grep -v "extra\." |
| 57 | + |
| 58 | +# Run all tests with make targets |
| 59 | +make test |
| 60 | + |
| 61 | +# Run linting only |
| 62 | +make lint |
| 63 | +``` |
| 64 | + |
| 65 | +## Repository Setup Requirements |
| 66 | + |
| 67 | +### Required Secrets (for release automation) |
| 68 | +Add these to your GitHub repository settings: |
| 69 | +- `PYPI_API_TOKEN`: Your PyPI API token for publishing releases |
| 70 | +- `TEST_PYPI_API_TOKEN`: Your Test PyPI API token for testing |
| 71 | + |
| 72 | + |
| 73 | +### Branch Protection |
| 74 | +Consider setting up branch protection rules for `main`/`master`: |
| 75 | +- Require status checks: CI workflow must pass |
| 76 | +- Require up-to-date branches before merging |
| 77 | +- Include administrators in restrictions |
| 78 | + |
| 79 | +## Status Badges |
| 80 | + |
| 81 | +Add these to your README.md: |
| 82 | + |
| 83 | +```markdown |
| 84 | +[](https://github.com/rande/python-simple-ioc/actions/workflows/ci.yml) |
| 85 | +[](https://github.com/rande/python-simple-ioc/actions/workflows/tests.yml) |
| 86 | +[](https://github.com/rande/python-simple-ioc/actions/workflows/docs.yml) |
| 87 | +[](https://github.com/rande/python-simple-ioc/actions/workflows/test-matrix.yml) |
| 88 | +``` |
| 89 | + |
| 90 | +## Maintenance |
| 91 | + |
| 92 | +### Dependabot |
| 93 | +Automated dependency updates are configured in `dependabot.yml`: |
| 94 | +- Weekly Python package updates |
| 95 | +- Weekly GitHub Actions updates |
| 96 | +- Automatic PR creation with proper labels |
| 97 | + |
| 98 | +### Local Development |
| 99 | +For local development and testing: |
| 100 | +```bash |
| 101 | +# Install with dev dependencies |
| 102 | +pip install -e ".[dev]" |
| 103 | + |
| 104 | +# Run linting |
| 105 | +make lint |
| 106 | + |
| 107 | +# Run tests (basic) |
| 108 | +make test |
| 109 | + |
| 110 | +# Run tests with type checking |
| 111 | +make test-strict |
| 112 | + |
| 113 | +# Run core tests only |
| 114 | +python -m unittest discover -s tests -p "test_*.py" | grep -v "extra\." |
| 115 | +``` |
0 commit comments