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