-
Notifications
You must be signed in to change notification settings - Fork 2
73 lines (59 loc) · 2.28 KB
/
python-tests.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# Source: https://jacobian.org/til/github-actions-poetry/
# Run this job on pushes to `main`, and for pull requests. If you don't specify
# `branches: [main], then this actions runs _twice_ on pull requests, which is
# annoying.
name: Python Unit Tests with Poetry
on:
push:
branches: [main]
pull_request:
jobs:
poetry-run-pytest:
runs-on: ubuntu-latest
strategy:
fail-fast: false # This ensures all matrix jobs run even if some fail
matrix:
python-version: ['3.10', '3.11', '3.12', '3.12'] # Adjust these as per available versions
# Use Docker container to handle the GDAL dependencies
container:
image: osgeo/gdal:ubuntu-small-3.6.3
steps:
- uses: actions/checkout@v2
# Setup Python version specified in matrix
- uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
# Install essential build tools required for compiling Python packages
- name: Install build tools
run: |
apt-get update
apt-get install -y build-essential
# Cache the installation of Poetry
- name: cache poetry install
uses: actions/cache@v2
with:
path: ~/.local
key: poetry-1.6.1-${{ matrix.python-version }}
# Install Poetry using snok/install-poetry action
- uses: snok/install-poetry@v1
with:
version: 1.6.1
virtualenvs-create: true
virtualenvs-in-project: true
# Configure Poetry: virtualenvs will be created in the project's folder
- name: Configure Poetry
run: poetry config virtualenvs.in-project true
# Cache your project dependencies
- name: cache deps
id: cache-deps
uses: actions/cache@v2
with:
path: ./.venv
key: ${{ runner.os }}-venv-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
# Install dependencies with Poetry, avoiding caching of the project itself
- run: poetry install --no-interaction --no-root
if: steps.cache-deps.outputs.cache-hit != 'true'
# Install the project using Poetry to fully-exercise pyproject.toml
- run: poetry install --no-interaction
# Run tests with pytest as configured in pyproject.toml
- run: poetry run pytest