|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - master |
| 8 | + pull_request: ~ |
| 9 | + |
| 10 | +env: |
| 11 | + CACHE_VERSION: 3 |
| 12 | + DEFAULT_PYTHON: 3.8 |
| 13 | + PRE_COMMIT_CACHE: ~/.cache/pre-commit |
| 14 | + |
| 15 | +jobs: |
| 16 | + prepare-base: |
| 17 | + name: Prepare base dependencies |
| 18 | + runs-on: ubuntu-latest |
| 19 | + outputs: |
| 20 | + python-key: ${{ steps.generate-python-key.outputs.key }} |
| 21 | + pre-commit-key: ${{ steps.generate-pre-commit-key.outputs.key }} |
| 22 | + steps: |
| 23 | + - name: Check out code from GitHub |
| 24 | + |
| 25 | + with: |
| 26 | + fetch-depth: 0 |
| 27 | + - name: Set up Python ${{ env.DEFAULT_PYTHON }} |
| 28 | + id: python |
| 29 | + |
| 30 | + with: |
| 31 | + python-version: ${{ env.DEFAULT_PYTHON }} |
| 32 | + - name: Generate partial Python venv restore key |
| 33 | + id: generate-python-key |
| 34 | + run: >- |
| 35 | + echo "::set-output name=key::base-venv-${{ env.CACHE_VERSION }}-${{ |
| 36 | + hashFiles('setup.cfg', 'requirements_test.txt', 'requirements_test_min.txt') |
| 37 | + }}" |
| 38 | + - name: Restore Python virtual environment |
| 39 | + id: cache-venv |
| 40 | + |
| 41 | + with: |
| 42 | + path: venv |
| 43 | + key: >- |
| 44 | + ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ |
| 45 | + steps.generate-python-key.outputs.key }} |
| 46 | + restore-keys: | |
| 47 | + ${{ runner.os }}-${{ steps.python.outputs.python-version }}-base-venv-${{ env.CACHE_VERSION }}- |
| 48 | + - name: Create Python virtual environment |
| 49 | + if: steps.cache-venv.outputs.cache-hit != 'true' |
| 50 | + run: | |
| 51 | + python -m venv venv |
| 52 | + . venv/bin/activate |
| 53 | + python -m pip install -U pip setuptools wheel |
| 54 | + pip install -U -r requirements_test.txt |
| 55 | + - name: Generate pre-commit restore key |
| 56 | + id: generate-pre-commit-key |
| 57 | + run: >- |
| 58 | + echo "::set-output name=key::pre-commit-${{ env.CACHE_VERSION }}-${{ |
| 59 | + hashFiles('.pre-commit-config.yaml') }}" |
| 60 | + - name: Restore pre-commit environment |
| 61 | + id: cache-precommit |
| 62 | + |
| 63 | + with: |
| 64 | + path: ${{ env.PRE_COMMIT_CACHE }} |
| 65 | + key: >- |
| 66 | + ${{ runner.os }}-${{ steps.generate-pre-commit-key.outputs.key }} |
| 67 | + restore-keys: | |
| 68 | + ${{ runner.os }}-pre-commit-${{ env.CACHE_VERSION }}- |
| 69 | + - name: Install pre-commit dependencies |
| 70 | + if: steps.cache-precommit.outputs.cache-hit != 'true' |
| 71 | + run: | |
| 72 | + . venv/bin/activate |
| 73 | + pre-commit install --install-hooks |
| 74 | +
|
| 75 | + formatting: |
| 76 | + name: Run pre-commit checks |
| 77 | + runs-on: ubuntu-latest |
| 78 | + needs: prepare-base |
| 79 | + steps: |
| 80 | + - name: Check out code from GitHub |
| 81 | + |
| 82 | + - name: Set up Python ${{ env.DEFAULT_PYTHON }} |
| 83 | + id: python |
| 84 | + |
| 85 | + with: |
| 86 | + python-version: ${{ env.DEFAULT_PYTHON }} |
| 87 | + - name: Restore Python virtual environment |
| 88 | + id: cache-venv |
| 89 | + |
| 90 | + with: |
| 91 | + path: venv |
| 92 | + key: |
| 93 | + ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ |
| 94 | + needs.prepare-base.outputs.python-key }} |
| 95 | + - name: Fail job if Python cache restore failed |
| 96 | + if: steps.cache-venv.outputs.cache-hit != 'true' |
| 97 | + run: | |
| 98 | + echo "Failed to restore Python venv from cache" |
| 99 | + exit 1 |
| 100 | + - name: Restore pre-commit environment |
| 101 | + id: cache-precommit |
| 102 | + |
| 103 | + with: |
| 104 | + path: ${{ env.PRE_COMMIT_CACHE }} |
| 105 | + key: ${{ runner.os }}-${{ needs.prepare-base.outputs.pre-commit-key }} |
| 106 | + - name: Fail job if pre-commit cache restore failed |
| 107 | + if: steps.cache-precommit.outputs.cache-hit != 'true' |
| 108 | + run: | |
| 109 | + echo "Failed to restore pre-commit environment from cache" |
| 110 | + exit 1 |
| 111 | + - name: Run formatting check |
| 112 | + run: | |
| 113 | + . venv/bin/activate |
| 114 | + pip install -e . |
| 115 | + pre-commit run pylint --all-files |
| 116 | +
|
| 117 | + prepare-tests-linux: |
| 118 | + name: Prepare tests for Python ${{ matrix.python-version }} (Linux) |
| 119 | + runs-on: ubuntu-latest |
| 120 | + strategy: |
| 121 | + matrix: |
| 122 | + python-version: [3.6, 3.7, 3.8, 3.9, "3.10"] |
| 123 | + outputs: |
| 124 | + python-key: ${{ steps.generate-python-key.outputs.key }} |
| 125 | + steps: |
| 126 | + - name: Check out code from GitHub |
| 127 | + |
| 128 | + with: |
| 129 | + fetch-depth: 0 |
| 130 | + - name: Set up Python ${{ matrix.python-version }} |
| 131 | + id: python |
| 132 | + |
| 133 | + with: |
| 134 | + python-version: ${{ matrix.python-version }} |
| 135 | + - name: Generate partial Python venv restore key |
| 136 | + id: generate-python-key |
| 137 | + run: >- |
| 138 | + echo "::set-output name=key::venv-${{ env.CACHE_VERSION }}-${{ |
| 139 | + hashFiles('setup.cfg', 'requirements_test.txt', 'requirements_test_min.txt') |
| 140 | + }}" |
| 141 | + - name: Restore Python virtual environment |
| 142 | + id: cache-venv |
| 143 | + |
| 144 | + with: |
| 145 | + path: venv |
| 146 | + key: >- |
| 147 | + ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ |
| 148 | + steps.generate-python-key.outputs.key }} |
| 149 | + restore-keys: | |
| 150 | + ${{ runner.os }}-${{ steps.python.outputs.python-version }}-venv-${{ env.CACHE_VERSION }}- |
| 151 | + - name: Create Python virtual environment |
| 152 | + if: steps.cache-venv.outputs.cache-hit != 'true' |
| 153 | + run: | |
| 154 | + python -m venv venv |
| 155 | + . venv/bin/activate |
| 156 | + python -m pip install -U pip setuptools wheel |
| 157 | + pip install -U -r requirements_test.txt |
| 158 | +
|
| 159 | + pytest-linux: |
| 160 | + name: Run tests Python ${{ matrix.python-version }} (Linux) |
| 161 | + runs-on: ubuntu-latest |
| 162 | + needs: prepare-tests-linux |
| 163 | + strategy: |
| 164 | + fail-fast: false |
| 165 | + matrix: |
| 166 | + python-version: [3.6, 3.7, 3.8, 3.9, "3.10"] |
| 167 | + steps: |
| 168 | + - name: Check out code from GitHub |
| 169 | + |
| 170 | + - name: Set up Python ${{ matrix.python-version }} |
| 171 | + id: python |
| 172 | + |
| 173 | + with: |
| 174 | + python-version: ${{ matrix.python-version }} |
| 175 | + - name: Restore Python virtual environment |
| 176 | + id: cache-venv |
| 177 | + |
| 178 | + with: |
| 179 | + path: venv |
| 180 | + key: |
| 181 | + ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ |
| 182 | + needs.prepare-tests-linux.outputs.python-key }} |
| 183 | + - name: Fail job if Python cache restore failed |
| 184 | + if: steps.cache-venv.outputs.cache-hit != 'true' |
| 185 | + run: | |
| 186 | + echo "Failed to restore Python venv from cache" |
| 187 | + exit 1 |
| 188 | + - name: Run pytest |
| 189 | + run: | |
| 190 | + . venv/bin/activate |
| 191 | + pytest --cov --cov-report= tests/ |
| 192 | + - name: Upload coverage artifact |
| 193 | + |
| 194 | + with: |
| 195 | + name: coverage-${{ matrix.python-version }} |
| 196 | + path: .coverage |
| 197 | + |
| 198 | + coverage: |
| 199 | + name: Process test coverage |
| 200 | + runs-on: ubuntu-latest |
| 201 | + needs: ["prepare-tests-linux", "pytest-linux"] |
| 202 | + strategy: |
| 203 | + matrix: |
| 204 | + python-version: [3.8] |
| 205 | + env: |
| 206 | + COVERAGERC_FILE: .coveragerc |
| 207 | + steps: |
| 208 | + - name: Check out code from GitHub |
| 209 | + |
| 210 | + - name: Set up Python ${{ matrix.python-version }} |
| 211 | + id: python |
| 212 | + |
| 213 | + with: |
| 214 | + python-version: ${{ matrix.python-version }} |
| 215 | + - name: Restore Python virtual environment |
| 216 | + id: cache-venv |
| 217 | + |
| 218 | + with: |
| 219 | + path: venv |
| 220 | + key: |
| 221 | + ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ |
| 222 | + needs.prepare-tests-linux.outputs.python-key }} |
| 223 | + - name: Fail job if Python cache restore failed |
| 224 | + if: steps.cache-venv.outputs.cache-hit != 'true' |
| 225 | + run: | |
| 226 | + echo "Failed to restore Python venv from cache" |
| 227 | + exit 1 |
| 228 | + - name: Download all coverage artifacts |
| 229 | + |
| 230 | + - name: Combine coverage results |
| 231 | + run: | |
| 232 | + . venv/bin/activate |
| 233 | + coverage combine coverage*/.coverage |
| 234 | + coverage report --rcfile=${{ env.COVERAGERC_FILE }} |
| 235 | + - name: Upload coverage to Coveralls |
| 236 | + env: |
| 237 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 238 | + run: | |
| 239 | + . venv/bin/activate |
| 240 | + coveralls --rcfile=${{ env.COVERAGERC_FILE }} --service=github |
| 241 | +
|
| 242 | + prepare-tests-windows: |
| 243 | + name: Prepare tests for Python ${{ matrix.python-version }} (Windows) |
| 244 | + runs-on: windows-latest |
| 245 | + strategy: |
| 246 | + matrix: |
| 247 | + python-version: [3.6, 3.7, 3.8, 3.9, "3.10"] |
| 248 | + outputs: |
| 249 | + python-key: ${{ steps.generate-python-key.outputs.key }} |
| 250 | + steps: |
| 251 | + - name: Check out code from GitHub |
| 252 | + |
| 253 | + with: |
| 254 | + fetch-depth: 0 |
| 255 | + - name: Set up Python ${{ matrix.python-version }} |
| 256 | + id: python |
| 257 | + |
| 258 | + with: |
| 259 | + python-version: ${{ matrix.python-version }} |
| 260 | + - name: Generate partial Python venv restore key |
| 261 | + id: generate-python-key |
| 262 | + run: >- |
| 263 | + echo "::set-output name=key::venv-${{ env.CACHE_VERSION }}-${{ |
| 264 | + hashFiles('setup.cfg', 'requirements_test_min.txt') |
| 265 | + }}" |
| 266 | + - name: Restore Python virtual environment |
| 267 | + id: cache-venv |
| 268 | + |
| 269 | + with: |
| 270 | + path: venv |
| 271 | + key: >- |
| 272 | + ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ |
| 273 | + steps.generate-python-key.outputs.key }} |
| 274 | + restore-keys: | |
| 275 | + ${{ runner.os }}-${{ steps.python.outputs.python-version }}-venv-${{ env.CACHE_VERSION }}- |
| 276 | + - name: Create Python virtual environment |
| 277 | + if: steps.cache-venv.outputs.cache-hit != 'true' |
| 278 | + run: | |
| 279 | + python -m venv venv |
| 280 | + . venv\\Scripts\\activate |
| 281 | + python -m pip install -U pip setuptools wheel |
| 282 | + pip install -U -r requirements_test_min.txt |
| 283 | +
|
| 284 | + pytest-windows: |
| 285 | + name: Run tests Python ${{ matrix.python-version }} (Windows) |
| 286 | + runs-on: windows-latest |
| 287 | + needs: prepare-tests-windows |
| 288 | + strategy: |
| 289 | + fail-fast: false |
| 290 | + matrix: |
| 291 | + python-version: [3.6, 3.7, 3.8, 3.9, "3.10"] |
| 292 | + steps: |
| 293 | + - name: Set temp directory |
| 294 | + run: echo "TEMP=$env:USERPROFILE\AppData\Local\Temp" >> $env:GITHUB_ENV |
| 295 | + # Workaround to set correct temp directory on Windows |
| 296 | + # https://github.com/actions/virtual-environments/issues/712 |
| 297 | + - name: Check out code from GitHub |
| 298 | + |
| 299 | + - name: Set up Python ${{ matrix.python-version }} |
| 300 | + id: python |
| 301 | + |
| 302 | + with: |
| 303 | + python-version: ${{ matrix.python-version }} |
| 304 | + - name: Restore Python virtual environment |
| 305 | + id: cache-venv |
| 306 | + |
| 307 | + with: |
| 308 | + path: venv |
| 309 | + key: |
| 310 | + ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ |
| 311 | + needs.prepare-tests-windows.outputs.python-key }} |
| 312 | + - name: Fail job if Python cache restore failed |
| 313 | + if: steps.cache-venv.outputs.cache-hit != 'true' |
| 314 | + run: | |
| 315 | + echo "Failed to restore Python venv from cache" |
| 316 | + exit 1 |
| 317 | + - name: Run pytest |
| 318 | + run: | |
| 319 | + . venv\\Scripts\\activate |
| 320 | + pytest tests/ |
| 321 | +
|
| 322 | + prepare-tests-pypy: |
| 323 | + name: Prepare tests for Python ${{ matrix.python-version }} |
| 324 | + runs-on: ubuntu-latest |
| 325 | + strategy: |
| 326 | + matrix: |
| 327 | + python-version: ["pypy3"] |
| 328 | + outputs: |
| 329 | + python-key: ${{ steps.generate-python-key.outputs.key }} |
| 330 | + steps: |
| 331 | + - name: Check out code from GitHub |
| 332 | + |
| 333 | + with: |
| 334 | + fetch-depth: 0 |
| 335 | + - name: Set up Python ${{ matrix.python-version }} |
| 336 | + id: python |
| 337 | + |
| 338 | + with: |
| 339 | + python-version: ${{ matrix.python-version }} |
| 340 | + - name: Generate partial Python venv restore key |
| 341 | + id: generate-python-key |
| 342 | + run: >- |
| 343 | + echo "::set-output name=key::venv-${{ env.CACHE_VERSION }}-${{ |
| 344 | + hashFiles('setup.cfg', 'requirements_test_min.txt') |
| 345 | + }}" |
| 346 | + - name: Restore Python virtual environment |
| 347 | + id: cache-venv |
| 348 | + |
| 349 | + with: |
| 350 | + path: venv |
| 351 | + key: >- |
| 352 | + ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ |
| 353 | + steps.generate-python-key.outputs.key }} |
| 354 | + restore-keys: | |
| 355 | + ${{ runner.os }}-${{ steps.python.outputs.python-version }}-venv-${{ env.CACHE_VERSION }}- |
| 356 | + - name: Create Python virtual environment |
| 357 | + if: steps.cache-venv.outputs.cache-hit != 'true' |
| 358 | + run: | |
| 359 | + python -m venv venv |
| 360 | + . venv/bin/activate |
| 361 | + python -m pip install -U pip setuptools wheel |
| 362 | + pip install -U -r requirements_test_min.txt |
| 363 | +
|
| 364 | + pytest-pypy: |
| 365 | + name: Run tests Python ${{ matrix.python-version }} |
| 366 | + runs-on: ubuntu-latest |
| 367 | + needs: prepare-tests-pypy |
| 368 | + strategy: |
| 369 | + fail-fast: false |
| 370 | + matrix: |
| 371 | + python-version: ["pypy3"] |
| 372 | + steps: |
| 373 | + - name: Check out code from GitHub |
| 374 | + |
| 375 | + - name: Set up Python ${{ matrix.python-version }} |
| 376 | + id: python |
| 377 | + |
| 378 | + with: |
| 379 | + python-version: ${{ matrix.python-version }} |
| 380 | + - name: Restore Python virtual environment |
| 381 | + id: cache-venv |
| 382 | + |
| 383 | + with: |
| 384 | + path: venv |
| 385 | + key: |
| 386 | + ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ |
| 387 | + needs.prepare-tests-pypy.outputs.python-key }} |
| 388 | + - name: Fail job if Python cache restore failed |
| 389 | + if: steps.cache-venv.outputs.cache-hit != 'true' |
| 390 | + run: | |
| 391 | + echo "Failed to restore Python venv from cache" |
| 392 | + exit 1 |
| 393 | + - name: Run pytest |
| 394 | + run: | |
| 395 | + . venv/bin/activate |
| 396 | + pytest tests/ |
0 commit comments