|
| 1 | +Continuous Integration and Deployment |
| 2 | +===================================== |
| 3 | + |
| 4 | +This document describes the continuous integration (CI) and continuous deployment (CD) setup for torchquad, which ensures code quality, testing, and automated releases. |
| 5 | + |
| 6 | +Overview |
| 7 | +-------- |
| 8 | + |
| 9 | +Torchquad uses GitHub Actions for CI/CD with the following key objectives: |
| 10 | + |
| 11 | +* **Automated Testing**: Run comprehensive test suites on every code change |
| 12 | +* **Code Quality**: Enforce consistent formatting and linting standards |
| 13 | +* **Multi-Backend Support**: Test across PyTorch, JAX, TensorFlow, and NumPy |
| 14 | +* **Automated Deployment**: Streamlined releases to PyPI and Test PyPI |
| 15 | +* **Documentation**: Automated paper builds for JOSS submissions |
| 16 | + |
| 17 | +GitHub Actions Workflows |
| 18 | +------------------------- |
| 19 | + |
| 20 | +The CI/CD pipeline consists of five main workflows: |
| 21 | + |
| 22 | +1. **Test Suite** (``run_tests.yml``) |
| 23 | + |
| 24 | + **Triggers**: Push to main/develop branches, pull requests, manual dispatch |
| 25 | + |
| 26 | + This is the core testing workflow that runs on every code change: |
| 27 | + |
| 28 | + * **Linting Stage**: Uses flake8 to check code quality and style |
| 29 | + * **Testing Stage**: |
| 30 | + - Sets up Python 3.9 environment |
| 31 | + - Installs all backend dependencies via micromamba |
| 32 | + - Runs full pytest suite with coverage reporting |
| 33 | + - Posts coverage reports as PR comments |
| 34 | + |
| 35 | + **Key Features**: |
| 36 | + |
| 37 | + * Multi-backend testing (all numerical backends) |
| 38 | + * Coverage tracking with pytest-cov |
| 39 | + * JUnit XML output for CI integration |
| 40 | + * Automated PR comments with test results |
| 41 | + |
| 42 | +2. **Code Formatting** (``autoblack.yml``) |
| 43 | + |
| 44 | + **Triggers**: Pull requests only |
| 45 | + |
| 46 | + Ensures consistent code formatting across the project: |
| 47 | + |
| 48 | + * Uses Black formatter with 100-character line length |
| 49 | + * Python 3.11 environment |
| 50 | + * Checks formatting without modifying files |
| 51 | + * Fails if reformatting is needed |
| 52 | + |
| 53 | +3. **PyPI Deployment** (``deploy_to_pypi.yml``) |
| 54 | + |
| 55 | + **Triggers**: Manual workflow dispatch only |
| 56 | + |
| 57 | + Production deployment to PyPI: |
| 58 | + |
| 59 | + * Python 3.10 environment |
| 60 | + * Builds source distribution and wheel packages |
| 61 | + * Uploads to PyPI using stored authentication token |
| 62 | + * Manual trigger ensures controlled releases |
| 63 | + |
| 64 | +4. **Test PyPI Deployment** (``deploy_to_test_pypi.yml``) |
| 65 | + |
| 66 | + **Triggers**: Manual workflow dispatch, GitHub releases |
| 67 | + |
| 68 | + Test deployment for validation: |
| 69 | + |
| 70 | + * Same process as PyPI deployment |
| 71 | + * Targets Test PyPI for safe testing |
| 72 | + * Used to validate packages before production release |
| 73 | + |
| 74 | +5. **Documentation** (``draft-pdf.yml``) |
| 75 | + |
| 76 | + **Triggers**: Changes to paper directory |
| 77 | + |
| 78 | + Builds academic paper PDF: |
| 79 | + |
| 80 | + * Uses OpenJournals GitHub Action |
| 81 | + * Compiles Markdown to PDF for JOSS submissions |
| 82 | + * Stores generated PDF as workflow artifact |
| 83 | + |
| 84 | +Environment Setup |
| 85 | +----------------- |
| 86 | + |
| 87 | +The CI system uses conda/micromamba for dependency management: |
| 88 | + |
| 89 | +.. code-block:: yaml |
| 90 | +
|
| 91 | + # From run_tests.yml |
| 92 | + - name: provision-with-micromamba |
| 93 | + uses: mamba-org/setup-micromamba@v1 |
| 94 | + with: |
| 95 | + environment-file: environment_all_backends.yml |
| 96 | + environment-name: torchquad |
| 97 | + cache-downloads: true |
| 98 | +
|
| 99 | +Environment Files |
| 100 | +~~~~~~~~~~~~~~~~~ |
| 101 | + |
| 102 | +* ``environment.yml`` - Basic PyTorch setup for development |
| 103 | +* ``environment_all_backends.yml`` - Complete backend support for CI |
| 104 | +* ``rtd_environment.yml`` - ReadTheDocs documentation builds |
| 105 | + |
| 106 | +Test Execution |
| 107 | +-------------- |
| 108 | + |
| 109 | +The test suite runs with comprehensive coverage: |
| 110 | + |
| 111 | +.. code-block:: bash |
| 112 | +
|
| 113 | + cd tests/ |
| 114 | + pytest -ra --error-for-skips \\ |
| 115 | + --junitxml=pytest.xml \\ |
| 116 | + --cov-report=term-missing:skip-covered \\ |
| 117 | + --cov=../torchquad . | tee pytest-coverage.txt |
| 118 | +
|
| 119 | +**Test Parameters**: |
| 120 | + |
| 121 | +* ``-ra`` - Show summary for all test outcomes |
| 122 | +* ``--error-for-skips`` - Treat skipped tests as errors (fail CI) |
| 123 | +* ``--junitxml`` - Generate XML report for CI integration |
| 124 | +* ``--cov`` - Generate coverage report for the torchquad package |
| 125 | + |
| 126 | +Code Quality Standards |
| 127 | +---------------------- |
| 128 | + |
| 129 | +Linting with Flake8 |
| 130 | +~~~~~~~~~~~~~~~~~~~ |
| 131 | + |
| 132 | +Two-stage linting process: |
| 133 | + |
| 134 | +1. **Critical Errors**: Check for syntax errors and undefined names |
| 135 | + |
| 136 | + .. code-block:: bash |
| 137 | + |
| 138 | + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics |
| 139 | +
|
| 140 | +2. **Full Analysis**: Complete code quality check using project ``.flake8`` configuration |
| 141 | + |
| 142 | + .. code-block:: bash |
| 143 | + |
| 144 | + flake8 . --count --show-source --statistics |
| 145 | +
|
| 146 | +Formatting with Black |
| 147 | +~~~~~~~~~~~~~~~~~~~~~ |
| 148 | + |
| 149 | +Consistent code style enforcement: |
| 150 | + |
| 151 | +.. code-block:: bash |
| 152 | +
|
| 153 | + black --check --line-length 100 . |
| 154 | +
|
| 155 | +**Configuration**: |
| 156 | + |
| 157 | +* Line length: 100 characters |
| 158 | +* Target: Python 3.11+ |
| 159 | +* Complies with project style guide |
| 160 | + |
| 161 | +Coverage Reporting |
| 162 | +------------------ |
| 163 | + |
| 164 | +The CI system provides detailed coverage analysis: |
| 165 | + |
| 166 | +* **PR Comments**: Automated coverage reports on pull requests |
| 167 | +* **Trend Tracking**: Coverage change detection |
| 168 | +* **Missing Lines**: Identification of untested code |
| 169 | +* **Badge Integration**: Coverage badges for README |
| 170 | + |
| 171 | +**Coverage Requirements**: |
| 172 | + |
| 173 | +* New features must include comprehensive tests |
| 174 | +* Significant coverage decreases block PR merges |
| 175 | +* Target: >90% coverage for new code |
| 176 | + |
| 177 | +Local Development |
| 178 | +----------------- |
| 179 | + |
| 180 | +Before pushing changes, run these checks locally: |
| 181 | + |
| 182 | +.. code-block:: bash |
| 183 | +
|
| 184 | + # Format code |
| 185 | + black . --line-length 100 |
| 186 | + |
| 187 | + # Check linting |
| 188 | + flake8 . --count --show-source --statistics |
| 189 | + |
| 190 | + # Run tests |
| 191 | + cd tests/ |
| 192 | + pytest |
| 193 | + |
| 194 | + # Run with coverage |
| 195 | + pytest --cov=../torchquad |
| 196 | +
|
| 197 | +Environment Setup |
| 198 | +~~~~~~~~~~~~~~~~~ |
| 199 | + |
| 200 | +For local development: |
| 201 | + |
| 202 | +.. code-block:: bash |
| 203 | +
|
| 204 | + # Create environment |
| 205 | + conda env create -f environment_all_backends.yml |
| 206 | + conda activate torchquad |
| 207 | + |
| 208 | + # Install in development mode |
| 209 | + pip install -e . |
| 210 | +
|
| 211 | +Backend Testing |
| 212 | +--------------- |
| 213 | + |
| 214 | +Multi-Backend Strategy |
| 215 | +~~~~~~~~~~~~~~~~~~~~~~ |
| 216 | + |
| 217 | +Tests run across all supported numerical backends: |
| 218 | + |
| 219 | +* **NumPy**: Reference implementation and baseline testing |
| 220 | +* **PyTorch**: GPU acceleration and automatic differentiation |
| 221 | +* **JAX**: JIT compilation and XLA optimization |
| 222 | +* **TensorFlow**: Graph execution and TPU support |
| 223 | + |
| 224 | +**Backend-Specific Considerations**: |
| 225 | + |
| 226 | +* Some tests are backend-specific and use appropriate skip decorators |
| 227 | +* GPU tests run automatically when CUDA is available |
| 228 | +* Complex number support varies by backend |
| 229 | +* Performance characteristics differ between backends |
| 230 | + |
| 231 | +Release Process |
| 232 | +--------------- |
| 233 | + |
| 234 | +PyPI Deployment |
| 235 | +~~~~~~~~~~~~~~~ |
| 236 | + |
| 237 | +Production releases follow this process: |
| 238 | + |
| 239 | +1. **Code Review**: All changes go through PR review |
| 240 | +2. **Testing**: Full test suite must pass |
| 241 | +3. **Version Update**: Update version in ``pyproject.toml`` |
| 242 | +4. **Test Deployment**: Deploy to Test PyPI first |
| 243 | +5. **Validation**: Test installation from Test PyPI |
| 244 | +6. **Production**: Manual trigger of PyPI deployment workflow |
| 245 | + |
| 246 | +**Required Secrets**: |
| 247 | + |
| 248 | +* ``PYPI_TOKEN`` - PyPI API token for package uploads |
| 249 | +* ``TEST_PYPI_TOKEN`` - Test PyPI API token |
| 250 | + |
| 251 | +Security Considerations |
| 252 | +----------------------- |
| 253 | + |
| 254 | +* **Token Management**: API tokens stored as GitHub secrets |
| 255 | +* **Manual Triggers**: Production deployments require manual approval |
| 256 | +* **Branch Protection**: Main branch protected with required status checks |
| 257 | +* **Dependency Scanning**: Automated security updates via Dependabot |
| 258 | + |
| 259 | +Troubleshooting |
| 260 | +--------------- |
| 261 | + |
| 262 | +Common CI Failures |
| 263 | +~~~~~~~~~~~~~~~~~~ |
| 264 | + |
| 265 | +1. **Formatting Issues**: |
| 266 | + |
| 267 | + .. code-block:: bash |
| 268 | + |
| 269 | + # Fix locally |
| 270 | + black . --line-length 100 |
| 271 | + git add . && git commit -m "Fix formatting" |
| 272 | +
|
| 273 | +2. **Import Errors**: |
| 274 | + |
| 275 | + * Check dependency versions in environment files |
| 276 | + * Verify relative imports after package structure changes |
| 277 | + * Ensure test files are properly isolated |
| 278 | + |
| 279 | +3. **Backend-Specific Failures**: |
| 280 | + |
| 281 | + * Check if backend is properly installed in CI environment |
| 282 | + * Verify skip decorators for unavailable backends |
| 283 | + * Review backend-specific test logic |
| 284 | + |
| 285 | +4. **Coverage Decreases**: |
| 286 | + |
| 287 | + * Add tests for new functionality |
| 288 | + * Check test discovery (files must match ``*_test.py`` or ``test_*.py``) |
| 289 | + * Verify coverage configuration in ``pyproject.toml`` |
| 290 | + |
| 291 | +5. **Environment Issues**: |
| 292 | + |
| 293 | + * Update ``environment_all_backends.yml`` for new dependencies |
| 294 | + * Check for version conflicts between backends |
| 295 | + * Verify micromamba cache invalidation |
| 296 | + |
| 297 | +Getting Help |
| 298 | +------------ |
| 299 | + |
| 300 | +For CI/CD issues: |
| 301 | + |
| 302 | +1. Check the `GitHub Actions <https://github.com/esa/torchquad/actions>`_ page for detailed logs |
| 303 | +2. Review similar successful runs for comparison |
| 304 | +3. Check environment file consistency |
| 305 | +4. Verify all required secrets are configured |
| 306 | +5. Open an issue with CI logs if problems persist |
| 307 | + |
| 308 | +The CI/CD system is designed to catch issues early and ensure high code quality. |
| 309 | +When in doubt, run the same commands locally that CI runs to debug issues quickly. |
0 commit comments