| 1 |
name: Main |
| 2 |
|
| 3 |
on: |
| 4 |
push: |
| 5 |
branches: |
| 6 |
- master |
| 7 |
tags: |
| 8 |
- '**' |
| 9 |
pull_request: |
| 10 |
branches: |
| 11 |
- '**' |
| 12 |
|
| 13 |
jobs: |
| 14 |
tests: |
| 15 |
name: ${{ matrix.os }} / ${{ matrix.python-version }} |
| 16 |
runs-on: ${{ matrix.os }}-latest |
| 17 |
strategy: |
| 18 |
max-parallel: 4 |
| 19 |
matrix: |
| 20 |
os: [Ubuntu, MacOS, Windows] |
| 21 |
python-version: [3.7, 3.8, 3.9, "3.10", "3.11"] |
| 22 |
|
| 23 |
defaults: |
| 24 |
run: |
| 25 |
shell: bash |
| 26 |
|
| 27 |
steps: |
| 28 |
- uses: actions/checkout@v3 |
| 29 |
|
| 30 |
- name: Set up Python ${{ matrix.python-version }} |
| 31 |
uses: actions/setup-python@v4 |
| 32 |
with: |
| 33 |
python-version: ${{ matrix.python-version }} |
| 34 |
|
| 35 |
- name: Get full Python version |
| 36 |
id: full-python-version |
| 37 |
run: | |
| 38 |
echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))") |
| 39 |
|
| 40 |
- name: Install poetry |
| 41 |
run: | |
| 42 |
curl -sL https://install.python-poetry.org | python - -y |
| 43 |
|
| 44 |
- name: Update PATH |
| 45 |
if: ${{ matrix.os != 'Windows' }} |
| 46 |
run: echo "$HOME/.local/bin" >> $GITHUB_PATH |
| 47 |
|
| 48 |
- name: Update PATH for Windows |
| 49 |
if: ${{ matrix.os == 'Windows' }} |
| 50 |
run: echo "$APPDATA\Python\Scripts" >> $GITHUB_PATH |
| 51 |
|
| 52 |
- name: Configure poetry |
| 53 |
run: | |
| 54 |
poetry config virtualenvs.in-project true |
| 55 |
|
| 56 |
- name: Set up cache |
| 57 |
uses: actions/cache@v3 |
| 58 |
id: cache |
| 59 |
with: |
| 60 |
path: .venv |
| 61 |
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }} |
| 62 |
|
| 63 |
- name: Ensure cache is healthy |
| 64 |
if: steps.cache.outputs.cache-hit == 'true' |
| 65 |
run: | |
| 66 |
# `timeout` is not available on macOS, so we define a custom function. |
| 67 |
[ "$(command -v timeout)" ] || function timeout() { perl -e 'alarm shift; exec @ARGV' "$@"; } |
| 68 |
# Using `timeout` is a safeguard against the Poetry command hanging for some reason. |
| 69 |
timeout 10s poetry run pip --version || rm -rf .venv |
| 70 |
|
| 71 |
- name: Install dependencies |
| 72 |
shell: bash |
| 73 |
run: poetry install |
| 74 |
|
| 75 |
- name: Run mypy |
| 76 |
run: poetry run mypy |
| 77 |
|
| 78 |
- name: Run pytest |
| 79 |
shell: bash |
| 80 |
run: poetry run pytest -v tests |