|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - dev |
| 8 | + pull_request: ~ |
| 9 | + |
| 10 | +env: |
| 11 | + CACHE_VERSION: 0 |
| 12 | + DEFAULT_PYTHON: 3.8 |
| 13 | + LIB_FOLDER: python_typing_update |
| 14 | + PRE_COMMIT_CACHE: ~/.cache/pre-commit |
| 15 | + |
| 16 | + |
| 17 | +jobs: |
| 18 | + prepare-base: |
| 19 | + name: Prepare base dependencies |
| 20 | + runs-on: ubuntu-latest |
| 21 | + outputs: |
| 22 | + python-key: ${{ steps.generate-python-key.outputs.key }} |
| 23 | + pre-commit-key: ${{ steps.generate-pre-commit-key.outputs.key }} |
| 24 | + steps: |
| 25 | + - name: Check out code from GitHub |
| 26 | + |
| 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('requirements.txt', 'requirements_test.txt', |
| 37 | + 'requirements_test_pre_commit.txt') }}" |
| 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 | + pip install -e . |
| 56 | + - name: Generate pre-commit restore key |
| 57 | + id: generate-pre-commit-key |
| 58 | + run: >- |
| 59 | + echo "::set-output name=key::pre-commit-${{ env.CACHE_VERSION }}-${{ |
| 60 | + hashFiles('.pre-commit-config.yaml') }}" |
| 61 | + - name: Restore pre-commit environment |
| 62 | + id: cache-precommit |
| 63 | + |
| 64 | + with: |
| 65 | + path: ${{ env.PRE_COMMIT_CACHE }} |
| 66 | + key: >- |
| 67 | + ${{ runner.os }}-${{ steps.generate-pre-commit-key.outputs.key }} |
| 68 | + restore-keys: | |
| 69 | + ${{ runner.os }}-pre-commit-${{ env.CACHE_VERSION }}- |
| 70 | + - name: Install pre-commit dependencies |
| 71 | + if: steps.cache-precommit.outputs.cache-hit != 'true' |
| 72 | + run: | |
| 73 | + . venv/bin/activate |
| 74 | + pre-commit install --install-hooks |
| 75 | +
|
| 76 | + formatting: |
| 77 | + name: Run pre-commit checks |
| 78 | + runs-on: ubuntu-latest |
| 79 | + needs: prepare-base |
| 80 | + steps: |
| 81 | + - name: Check out code from GitHub |
| 82 | + |
| 83 | + - name: Set up Python ${{ env.DEFAULT_PYTHON }} |
| 84 | + id: python |
| 85 | + |
| 86 | + with: |
| 87 | + python-version: ${{ env.DEFAULT_PYTHON }} |
| 88 | + - name: Restore Python virtual environment |
| 89 | + id: cache-venv |
| 90 | + |
| 91 | + with: |
| 92 | + path: venv |
| 93 | + key: ${{ 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 --all-files |
| 116 | +
|
| 117 | + pylint: |
| 118 | + name: Check pylint |
| 119 | + runs-on: ubuntu-latest |
| 120 | + needs: prepare-base |
| 121 | + steps: |
| 122 | + - name: Check out code from GitHub |
| 123 | + |
| 124 | + - name: Set up Python ${{ env.DEFAULT_PYTHON }} |
| 125 | + id: python |
| 126 | + |
| 127 | + with: |
| 128 | + python-version: ${{ env.DEFAULT_PYTHON }} |
| 129 | + - name: Restore Python virtual environment |
| 130 | + id: cache-venv |
| 131 | + |
| 132 | + with: |
| 133 | + path: venv |
| 134 | + key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ |
| 135 | + needs.prepare-base.outputs.python-key }} |
| 136 | + - name: Fail job if Python cache restore failed |
| 137 | + if: steps.cache-venv.outputs.cache-hit != 'true' |
| 138 | + run: | |
| 139 | + echo "Failed to restore Python venv from cache" |
| 140 | + exit 1 |
| 141 | + - name: Run pylint |
| 142 | + run: | |
| 143 | + . venv/bin/activate |
| 144 | + pip install -e . |
| 145 | + pylint ${{ env.LIB_FOLDER }} tests |
| 146 | +
|
| 147 | + mypy: |
| 148 | + name: Check mypy |
| 149 | + runs-on: ubuntu-latest |
| 150 | + needs: prepare-base |
| 151 | + steps: |
| 152 | + - name: Check out code from GitHub |
| 153 | + |
| 154 | + - name: Set up Python ${{ env.DEFAULT_PYTHON }} |
| 155 | + id: python |
| 156 | + |
| 157 | + with: |
| 158 | + python-version: ${{ env.DEFAULT_PYTHON }} |
| 159 | + - name: Restore Python virtual environment |
| 160 | + id: cache-venv |
| 161 | + |
| 162 | + with: |
| 163 | + path: venv |
| 164 | + key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ |
| 165 | + needs.prepare-base.outputs.python-key }} |
| 166 | + - name: Fail job if Python cache restore failed |
| 167 | + if: steps.cache-venv.outputs.cache-hit != 'true' |
| 168 | + run: | |
| 169 | + echo "Failed to restore Python venv from cache" |
| 170 | + exit 1 |
| 171 | + - name: Run mypy |
| 172 | + run: | |
| 173 | + . venv/bin/activate |
| 174 | + mypy ${{ env.LIB_FOLDER }} tests |
| 175 | +
|
| 176 | +
|
| 177 | + prepare-tests-linux: |
| 178 | + name: Prepare tests for Python ${{ matrix.python-version }} (Linux) |
| 179 | + runs-on: ubuntu-latest |
| 180 | + strategy: |
| 181 | + matrix: |
| 182 | + python-version: [3.8, 3.9] |
| 183 | + outputs: |
| 184 | + python-key: ${{ steps.generate-python-key.outputs.key }} |
| 185 | + steps: |
| 186 | + - name: Check out code from GitHub |
| 187 | + |
| 188 | + - name: Set up Python ${{ matrix.python-version }} |
| 189 | + id: python |
| 190 | + |
| 191 | + with: |
| 192 | + python-version: ${{ matrix.python-version }} |
| 193 | + - name: Generate partial Python venv restore key |
| 194 | + id: generate-python-key |
| 195 | + run: >- |
| 196 | + echo "::set-output name=key::venv-${{ env.CACHE_VERSION }}-${{ |
| 197 | + hashFiles('requirements.txt', 'requirements_test.txt', |
| 198 | + 'requirements_test_pre_commit.txt') }}" |
| 199 | + - name: Restore Python virtual environment |
| 200 | + id: cache-venv |
| 201 | + |
| 202 | + with: |
| 203 | + path: venv |
| 204 | + key: >- |
| 205 | + ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ |
| 206 | + steps.generate-python-key.outputs.key }} |
| 207 | + restore-keys: | |
| 208 | + ${{ runner.os }}-${{ steps.python.outputs.python-version }}-venv-${{ env.CACHE_VERSION }}- |
| 209 | + - name: Create Python virtual environment |
| 210 | + if: steps.cache-venv.outputs.cache-hit != 'true' |
| 211 | + run: | |
| 212 | + python -m venv venv |
| 213 | + . venv/bin/activate |
| 214 | + python -m pip install -U pip setuptools wheel |
| 215 | + pip install -U -r requirements_test.txt |
| 216 | + pip install -e . |
| 217 | +
|
| 218 | + pytest-linux: |
| 219 | + name: Run tests Python ${{ matrix.python-version }} (Linux) |
| 220 | + runs-on: ubuntu-latest |
| 221 | + needs: prepare-tests-linux |
| 222 | + strategy: |
| 223 | + fail-fast: false |
| 224 | + matrix: |
| 225 | + python-version: [3.8, 3.9] |
| 226 | + steps: |
| 227 | + - name: Check out code from GitHub |
| 228 | + |
| 229 | + - name: Set up Python ${{ matrix.python-version }} |
| 230 | + id: python |
| 231 | + |
| 232 | + with: |
| 233 | + python-version: ${{ matrix.python-version }} |
| 234 | + - name: Restore Python virtual environment |
| 235 | + id: cache-venv |
| 236 | + |
| 237 | + with: |
| 238 | + path: venv |
| 239 | + key: ${{ runner.os }}-${{ steps.python.outputs.python-version }}-${{ |
| 240 | + needs.prepare-tests-linux.outputs.python-key }} |
| 241 | + - name: Fail job if Python cache restore failed |
| 242 | + if: steps.cache-venv.outputs.cache-hit != 'true' |
| 243 | + run: | |
| 244 | + echo "Failed to restore Python venv from cache" |
| 245 | + exit 1 |
| 246 | + - name: Run pytest |
| 247 | + run: | |
| 248 | + . venv/bin/activate |
| 249 | + pytest tests/ |
0 commit comments