|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + pull_request: |
| 7 | + branches: [ main ] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +env: |
| 11 | + FORCE_COLOR: 1 |
| 12 | + |
| 13 | +jobs: |
| 14 | + test: |
| 15 | + name: Test Python ${{ matrix.python-version }} on ${{ matrix.os }} |
| 16 | + runs-on: ${{ matrix.os }} |
| 17 | + strategy: |
| 18 | + fail-fast: false |
| 19 | + matrix: |
| 20 | + os: [ubuntu-latest, macos-latest] |
| 21 | + python-version: ['3.9', '3.10', '3.11', '3.12', '3.13', '3.14'] |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Checkout code |
| 25 | + uses: actions/checkout@v4 |
| 26 | + |
| 27 | + - name: Set up Python ${{ matrix.python-version }} |
| 28 | + uses: actions/setup-python@v5 |
| 29 | + with: |
| 30 | + python-version: ${{ matrix.python-version }} |
| 31 | + |
| 32 | + - name: Get pip cache dir |
| 33 | + id: pip-cache |
| 34 | + run: | |
| 35 | + echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT |
| 36 | +
|
| 37 | + - name: Cache pip dependencies |
| 38 | + uses: actions/cache@v4 |
| 39 | + with: |
| 40 | + path: ${{ steps.pip-cache.outputs.dir }} |
| 41 | + key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/pyproject.toml', '**/tests/requirements.txt') }} |
| 42 | + restore-keys: | |
| 43 | + ${{ runner.os }}-pip-${{ matrix.python-version }}- |
| 44 | + ${{ runner.os }}-pip- |
| 45 | +
|
| 46 | + - name: Install dependencies |
| 47 | + run: | |
| 48 | + python -m pip install --upgrade pip setuptools wheel |
| 49 | + pip install -e .[dev] |
| 50 | +
|
| 51 | + - name: Lint with flake8 |
| 52 | + run: | |
| 53 | + # Stop the build if there are Python syntax errors or undefined names |
| 54 | + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics |
| 55 | + # Exit-zero treats all errors as warnings |
| 56 | + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics |
| 57 | +
|
| 58 | + - name: Type check with mypy |
| 59 | + run: | |
| 60 | + mypy himl/ --ignore-missing-imports |
| 61 | +
|
| 62 | + - name: Run tests with pytest |
| 63 | + run: | |
| 64 | + python -m pytest tests/ -v --tb=short --cov=himl --cov-report=xml --cov-report=term-missing --cov-fail-under=80 |
| 65 | +
|
| 66 | + - name: Upload coverage to Codecov |
| 67 | + if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.14' |
| 68 | + uses: codecov/codecov-action@v4 |
| 69 | + with: |
| 70 | + file: ./coverage.xml |
| 71 | + flags: unittests |
| 72 | + name: codecov-umbrella |
| 73 | + fail_ci_if_error: false |
| 74 | + |
| 75 | + security: |
| 76 | + name: Security checks |
| 77 | + runs-on: ubuntu-latest |
| 78 | + # Note: Using Python 3.13 for security checks until bandit supports Python 3.14 |
| 79 | + # See: https://github.com/PyCQA/bandit/issues with ast.Num deprecation |
| 80 | + steps: |
| 81 | + - name: Checkout code |
| 82 | + uses: actions/checkout@v4 |
| 83 | + |
| 84 | + - name: Set up Python |
| 85 | + uses: actions/setup-python@v5 |
| 86 | + with: |
| 87 | + python-version: '3.13' # Use 3.13 until bandit supports 3.14 |
| 88 | + |
| 89 | + - name: Install security tools |
| 90 | + run: | |
| 91 | + python -m pip install --upgrade pip |
| 92 | + pip install bandit[toml] safety |
| 93 | +
|
| 94 | + - name: Run security checks with bandit |
| 95 | + run: | |
| 96 | + # Generate JSON report (allow failures for reporting) |
| 97 | + bandit -r himl/ -f json -o bandit-report.json || echo "Bandit JSON report generation completed with issues" |
| 98 | + # Run bandit with medium severity (fail on medium+ issues) |
| 99 | + bandit -r himl/ --severity-level medium |
| 100 | +
|
| 101 | +
|
| 102 | + - name: Upload security reports |
| 103 | + if: always() |
| 104 | + uses: actions/upload-artifact@v4 |
| 105 | + with: |
| 106 | + name: security-reports |
| 107 | + path: | |
| 108 | + bandit-report.json |
| 109 | +
|
| 110 | + build: |
| 111 | + name: Build package |
| 112 | + runs-on: ubuntu-latest |
| 113 | + steps: |
| 114 | + - name: Checkout code |
| 115 | + uses: actions/checkout@v4 |
| 116 | + with: |
| 117 | + fetch-depth: 0 # Needed for setuptools_scm |
| 118 | + |
| 119 | + - name: Set up Python |
| 120 | + uses: actions/setup-python@v5 |
| 121 | + with: |
| 122 | + python-version: '3.14' |
| 123 | + |
| 124 | + - name: Install build dependencies |
| 125 | + run: | |
| 126 | + python -m pip install --upgrade pip |
| 127 | + pip install build twine |
| 128 | +
|
| 129 | + - name: Build package |
| 130 | + run: | |
| 131 | + python -m build |
| 132 | +
|
| 133 | + - name: Check package |
| 134 | + run: | |
| 135 | + twine check dist/* |
| 136 | +
|
| 137 | + - name: Test package installation |
| 138 | + run: | |
| 139 | + pip install dist/*.whl |
| 140 | + himl --help |
| 141 | + himl-config-merger --help |
| 142 | +
|
| 143 | + - name: Upload build artifacts |
| 144 | + uses: actions/upload-artifact@v4 |
| 145 | + with: |
| 146 | + name: dist-${{ github.sha }} |
| 147 | + path: dist/ |
| 148 | + retention-days: 30 |
| 149 | + |
| 150 | + integration: |
| 151 | + name: Integration tests |
| 152 | + runs-on: ubuntu-latest |
| 153 | + needs: [test, build] |
| 154 | + if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main' |
| 155 | + steps: |
| 156 | + - name: Checkout code |
| 157 | + uses: actions/checkout@v4 |
| 158 | + |
| 159 | + - name: Set up Python |
| 160 | + uses: actions/setup-python@v5 |
| 161 | + with: |
| 162 | + python-version: '3.14' |
| 163 | + |
| 164 | + - name: Download build artifacts |
| 165 | + uses: actions/download-artifact@v4 |
| 166 | + with: |
| 167 | + name: dist-${{ github.sha }} |
| 168 | + path: dist/ |
| 169 | + |
| 170 | + - name: Install package from wheel |
| 171 | + run: | |
| 172 | + python -m pip install --upgrade pip |
| 173 | + pip install dist/*.whl |
| 174 | +
|
| 175 | + - name: Run integration tests |
| 176 | + run: | |
| 177 | + # Test CLI tools work |
| 178 | + himl --help |
| 179 | + himl-config-merger --help |
| 180 | +
|
| 181 | + # Test basic functionality with examples |
| 182 | + if [ -d "examples" ]; then |
| 183 | + cd examples |
| 184 | + if [ -d "simple" ]; then |
| 185 | + himl simple/production --format yaml |
| 186 | + fi |
| 187 | + fi |
| 188 | +
|
| 189 | + docker: |
| 190 | + name: Docker build test |
| 191 | + runs-on: ubuntu-latest |
| 192 | + needs: [test, build] |
| 193 | + if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main' |
| 194 | + steps: |
| 195 | + - name: Checkout code |
| 196 | + uses: actions/checkout@v4 |
| 197 | + with: |
| 198 | + fetch-depth: 0 # Needed for setuptools_scm |
| 199 | + |
| 200 | + - name: Set up Docker Buildx |
| 201 | + uses: docker/setup-buildx-action@v3 |
| 202 | + |
| 203 | + - name: Build Docker image |
| 204 | + uses: docker/build-push-action@v6 |
| 205 | + with: |
| 206 | + context: . |
| 207 | + push: false |
| 208 | + tags: himl:test |
| 209 | + cache-from: type=gha |
| 210 | + cache-to: type=gha,mode=max |
| 211 | + |
| 212 | + - name: Test Docker image |
| 213 | + run: | |
| 214 | + # Test that both CLI commands work |
| 215 | + docker run --rm himl:test himl --help |
| 216 | + docker run --rm himl:test himl-config-merger --help |
| 217 | +
|
| 218 | + # Test basic functionality |
| 219 | + docker run --rm himl:test python -c "import himl; print('himl import successful')" |
0 commit comments