Add GitHub Actions workflow for Python tests with Poetry #9
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 of the workflow | |
name: Python Unit Tests with Poetry | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
# Use Docker container | |
container: | |
image: osgeo/gdal:ubuntu-small-latest | |
steps: | |
- uses: actions/checkout@v2 | |
# Setup Python version specified | |
- uses: actions/setup-python@v2 | |
with: | |
python-version: '3.10' | |
# Install specific version of GDAL | |
- name: Install GDAL 3.6.0 | |
run: | | |
apt-get update | |
apt-get install -y software-properties-common | |
add-apt-repository ppa:ubuntugis/ppa | |
apt-get update | |
apt-get install -y gdal-bin=3.6.0-0~focal0 libgdal-dev=3.6.0-0~focal0 | |
# Cache the installation of Poetry | |
- name: cache poetry install | |
uses: actions/cache@v2 | |
with: | |
path: ~/.local | |
key: poetry-1.6.1-0 | |
# Install Poetry using snok/install-poetry action | |
- uses: snok/install-poetry@v1 | |
with: | |
version: 1.6.1 | |
virtualenvs-create: true | |
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-${{ hashFiles('**/poetry.lock') }} | |
# Install dependencies with Poetry | |
- run: poetry install --no-interaction --no-root | |
if: steps.cache-deps.outputs.cache-hit != 'true' | |
- run: poetry install --no-interaction | |
# Run tests with pytest | |
- run: poetry run pytest |