|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +jobs: |
| 18 | + lint: |
| 19 | + name: Lint (ruff + pre-commit) |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + - uses: actions/setup-python@v5 |
| 24 | + with: |
| 25 | + python-version: "3.12" |
| 26 | + cache: "pip" |
| 27 | + - name: Install dev tooling |
| 28 | + run: | |
| 29 | + python -m pip install --upgrade pip |
| 30 | + pip install -e ".[dev]" |
| 31 | + - name: Ruff lint |
| 32 | + run: ruff check . |
| 33 | + - name: Ruff format check |
| 34 | + run: ruff format --check . |
| 35 | + - name: Pre-commit hooks |
| 36 | + run: pre-commit run --all-files --show-diff-on-failure |
| 37 | + |
| 38 | + test: |
| 39 | + name: Tests (py${{ matrix.python }} on ${{ matrix.os }}) |
| 40 | + runs-on: ${{ matrix.os }} |
| 41 | + needs: lint |
| 42 | + strategy: |
| 43 | + fail-fast: false |
| 44 | + matrix: |
| 45 | + os: [ubuntu-latest, macos-latest, windows-latest] |
| 46 | + python: ["3.11", "3.12", "3.13"] |
| 47 | + steps: |
| 48 | + - uses: actions/checkout@v4 |
| 49 | + - uses: actions/setup-python@v5 |
| 50 | + with: |
| 51 | + python-version: ${{ matrix.python }} |
| 52 | + cache: "pip" |
| 53 | + - name: Install package |
| 54 | + run: | |
| 55 | + python -m pip install --upgrade pip |
| 56 | + pip install -e ".[dev]" |
| 57 | + - name: Run pytest with coverage |
| 58 | + run: pytest --cov=src --cov-report=xml --cov-report=term -q |
| 59 | + - name: Upload coverage to Codecov |
| 60 | + if: matrix.os == 'ubuntu-latest' && matrix.python == '3.12' |
| 61 | + uses: codecov/codecov-action@v4 |
| 62 | + with: |
| 63 | + files: coverage.xml |
| 64 | + fail_ci_if_error: false |
| 65 | + env: |
| 66 | + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
| 67 | + |
| 68 | + benchmarks: |
| 69 | + name: Analytical benchmarks |
| 70 | + runs-on: ubuntu-latest |
| 71 | + needs: lint |
| 72 | + steps: |
| 73 | + - uses: actions/checkout@v4 |
| 74 | + - uses: actions/setup-python@v5 |
| 75 | + with: |
| 76 | + python-version: "3.12" |
| 77 | + cache: "pip" |
| 78 | + - name: Install package |
| 79 | + run: | |
| 80 | + python -m pip install --upgrade pip |
| 81 | + pip install -e ".[dev]" |
| 82 | + - name: Run benchmarks |
| 83 | + run: python validation/benchmarks.py |
| 84 | + |
| 85 | + pipeline-smoke: |
| 86 | + name: Full pipeline smoke test |
| 87 | + runs-on: ubuntu-latest |
| 88 | + needs: [test, benchmarks] |
| 89 | + steps: |
| 90 | + - uses: actions/checkout@v4 |
| 91 | + - uses: actions/setup-python@v5 |
| 92 | + with: |
| 93 | + python-version: "3.12" |
| 94 | + cache: "pip" |
| 95 | + - name: Install package |
| 96 | + run: | |
| 97 | + python -m pip install --upgrade pip |
| 98 | + pip install -e ".[dev]" |
| 99 | + - name: Run pipeline (run_all.py) |
| 100 | + run: python run_all.py |
| 101 | + - name: Verify assets generated |
| 102 | + run: | |
| 103 | + test -f assets/figures/panel_ab_fields.png |
| 104 | + test -f assets/figures/panel_c_mc_distribution.png |
| 105 | + test -f assets/figures/panel_d_sensitivity.png |
| 106 | + test -f assets/figures/panel_e_surrogate.png |
| 107 | + test -f assets/figures/panel_f_iso_risk.png |
| 108 | + test -f assets/figures/panel_g_fad.png |
| 109 | + test -f assets/figures/panel_h_inverse.png |
| 110 | + test -f assets/animations/cui_moisture_front.gif |
| 111 | + test -f assets/audit_chain.json |
| 112 | + - name: Verify audit chain integrity |
| 113 | + run: | |
| 114 | + python -c " |
| 115 | + import json |
| 116 | + with open('assets/audit_chain.json') as f: |
| 117 | + entries = json.load(f) |
| 118 | + assert len(entries) >= 2, f'Expected >=2 entries, got {len(entries)}' |
| 119 | + assert entries[0]['prev_hash'] == '0' * 64 |
| 120 | + assert all(e['entry_hash'] for e in entries) |
| 121 | + print(f'Audit chain OK: {len(entries)} entries') |
| 122 | + " |
| 123 | + - name: Upload pipeline artifacts |
| 124 | + uses: actions/upload-artifact@v4 |
| 125 | + with: |
| 126 | + name: pipeline-outputs-${{ github.sha }} |
| 127 | + path: | |
| 128 | + assets/figures/*.png |
| 129 | + assets/animations/*.gif |
| 130 | + assets/audit_chain.json |
| 131 | + retention-days: 30 |
| 132 | + |
| 133 | + security: |
| 134 | + name: Security scan (pip-audit) |
| 135 | + runs-on: ubuntu-latest |
| 136 | + needs: lint |
| 137 | + steps: |
| 138 | + - uses: actions/checkout@v4 |
| 139 | + - uses: actions/setup-python@v5 |
| 140 | + with: |
| 141 | + python-version: "3.12" |
| 142 | + cache: "pip" |
| 143 | + - name: Install package + pip-audit |
| 144 | + run: | |
| 145 | + python -m pip install --upgrade pip |
| 146 | + pip install -e . |
| 147 | + pip install pip-audit |
| 148 | + - name: Audit dependencies |
| 149 | + run: pip-audit --strict |
| 150 | + continue-on-error: true |
| 151 | + |
| 152 | + ci-pass: |
| 153 | + name: All checks passed |
| 154 | + runs-on: ubuntu-latest |
| 155 | + needs: [lint, test, benchmarks, pipeline-smoke, security] |
| 156 | + steps: |
| 157 | + - run: echo "All CI jobs succeeded." |
0 commit comments