|
15 | 15 | # Policy/fixture changes that affect tests |
16 | 16 | - "fixtures/**" |
17 | 17 | - "**.rego" |
| 18 | + # Python binding changes |
| 19 | + - "cupcake-py/**" |
18 | 20 | workflow_dispatch: |
19 | 21 |
|
20 | 22 | env: |
@@ -162,6 +164,95 @@ jobs: |
162 | 164 | - uses: eqtylab-actions/install-nix-action@v31 |
163 | 165 | - run: nix build .#cupcake-cli -L |
164 | 166 |
|
| 167 | + test-python: |
| 168 | + name: Python Bindings (${{ matrix.os }}) |
| 169 | + runs-on: ${{ matrix.os }} |
| 170 | + strategy: |
| 171 | + fail-fast: false |
| 172 | + matrix: |
| 173 | + os: [cupcake-ubuntu-latest, macos-latest, windows-latest] |
| 174 | + steps: |
| 175 | + - name: Checkout code |
| 176 | + uses: actions/checkout@v4 |
| 177 | + |
| 178 | + - name: Setup Rust |
| 179 | + uses: dtolnay/rust-toolchain@stable |
| 180 | + |
| 181 | + - name: Setup Rust cache |
| 182 | + uses: Swatinem/rust-cache@v2 |
| 183 | + |
| 184 | + - name: Setup Python |
| 185 | + uses: actions/setup-python@v5 |
| 186 | + with: |
| 187 | + python-version: "3.12" |
| 188 | + |
| 189 | + - name: Install OPA (Unix) |
| 190 | + if: runner.os != 'Windows' |
| 191 | + run: | |
| 192 | + if [[ "$RUNNER_OS" == "Linux" ]]; then |
| 193 | + curl -L -o opa https://github.com/open-policy-agent/opa/releases/download/v1.7.1/opa_linux_amd64_static |
| 194 | + elif [[ "$RUNNER_OS" == "macOS" ]]; then |
| 195 | + curl -L -o opa https://github.com/open-policy-agent/opa/releases/download/v1.7.1/opa_darwin_amd64 |
| 196 | + fi |
| 197 | + chmod +x opa |
| 198 | + sudo mv opa /usr/local/bin/ |
| 199 | + opa version |
| 200 | +
|
| 201 | + - name: Install OPA (Windows) |
| 202 | + if: runner.os == 'Windows' |
| 203 | + shell: pwsh |
| 204 | + run: | |
| 205 | + Invoke-WebRequest -Uri "https://github.com/open-policy-agent/opa/releases/download/v1.7.1/opa_windows_amd64.exe" -OutFile "opa.exe" |
| 206 | + Move-Item opa.exe "C:\Windows\System32\opa.exe" -Force |
| 207 | + & opa version |
| 208 | +
|
| 209 | + - name: Create virtualenv and install dependencies (Unix) |
| 210 | + if: runner.os != 'Windows' |
| 211 | + run: | |
| 212 | + python -m venv .venv |
| 213 | + source .venv/bin/activate |
| 214 | + pip install maturin pytest pytest-asyncio |
| 215 | +
|
| 216 | + - name: Create virtualenv and install dependencies (Windows) |
| 217 | + if: runner.os == 'Windows' |
| 218 | + shell: pwsh |
| 219 | + run: | |
| 220 | + python -m venv .venv |
| 221 | + .venv\Scripts\Activate.ps1 |
| 222 | + pip install maturin pytest pytest-asyncio |
| 223 | +
|
| 224 | + - name: Build Python bindings (Unix) |
| 225 | + if: runner.os != 'Windows' |
| 226 | + run: | |
| 227 | + source .venv/bin/activate |
| 228 | + cd cupcake-py |
| 229 | + maturin develop --release |
| 230 | +
|
| 231 | + - name: Build Python bindings (Windows) |
| 232 | + if: runner.os == 'Windows' |
| 233 | + shell: pwsh |
| 234 | + run: | |
| 235 | + .venv\Scripts\Activate.ps1 |
| 236 | + cd cupcake-py |
| 237 | + maturin develop --release |
| 238 | +
|
| 239 | + - name: Run Python tests (Unix) |
| 240 | + if: runner.os != 'Windows' |
| 241 | + run: | |
| 242 | + source .venv/bin/activate |
| 243 | + cd cupcake-py |
| 244 | + pytest tests/ -v |
| 245 | +
|
| 246 | + - name: Run Python tests (Windows) |
| 247 | + if: runner.os == 'Windows' |
| 248 | + shell: pwsh |
| 249 | + run: | |
| 250 | + .venv\Scripts\Activate.ps1 |
| 251 | + cd cupcake-py |
| 252 | + pytest tests/ -v |
| 253 | + env: |
| 254 | + CI: true |
| 255 | + |
165 | 256 | fmt: |
166 | 257 | name: Format |
167 | 258 | runs-on: ubuntu-latest |
|
0 commit comments