GitHub Actions for Python projects using poetry
We've started installing poetry with pipx to keep the installed artifacts
isolated away from any of your application dependencies. v3 will install pipx
for you as well.
We've drastically simplified this GitHub Action for v2.
This is no longer a Docker action that runs as its own container,
it's just a simplified way for you to install poetry.
This action now makes an assumption that you've already setup Python via setup-python or some other way.
Since we're installing poetry directly to your environment,
this also means that you can cache your dependencies more easily since everything is running on the host runner instead of an isolated container environment.
name: CI
on: pull_request
jobs:
ci:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
poetry-version: ["latest", "main", "1.8.4"]
os: [ubuntu-22.04, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Run image
uses: abatilo/actions-poetry@v3
with:
poetry-version: ${{ matrix.poetry-version }}
- name: View poetry --help
run: poetry --help
It is possible to combine actions/poetry with actions/cache to speed up the installation of dependencies.
The recipe is:
poetry to create a virtual environment inside the project:
it creates a local .venv/ folder that can be cachedpoetry.lock file:
if the contents change (meaning that dependencies have changed), then the cache needs to be invalidated and recreatedFor the 1st step, you either need:
poetry.toml file
(and not pyproject.toml)
at the root of your project with these 2 settings:[virtualenvs]
create = true
in-project = true
poetry.toml file:poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
Here is an example of how the steps must be declared:
jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v4
# see details (matrix, python-version, python-version-file, etc.)
# https://github.com/actions/setup-python
- name: Install poetry
uses: abatilo/actions-poetry@v4
- name: Setup a local virtual environment (if no poetry.toml file)
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
- uses: actions/cache@v3
name: Define a cache for the virtual environment based on the dependencies lock file
with:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}
- name: Install the project dependencies
run: poetry install
- name: Run the automated tests (for example)
run: poetry run pytest -v
MIT License - abatilo/actions-poetry
765 followers · starred Jul 2021
7,139 followers · starred Jan 2025
657 followers · starred Sep 2022
486 followers · starred Sep 2023
GitHub Actions for Python projects using poetry
We've started installing poetry with pipx to keep the installed artifacts
isolated away from any of your application dependencies. v3 will install pipx
for you as well.
We've drastically simplified this GitHub Action for v2.
This is no longer a Docker action that runs as its own container,
it's just a simplified way for you to install poetry.
This action now makes an assumption that you've already setup Python via setup-python or some other way.
Since we're installing poetry directly to your environment,
this also means that you can cache your dependencies more easily since everything is running on the host runner instead of an isolated container environment.
name: CI
on: pull_request
jobs:
ci:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
poetry-version: ["latest", "main", "1.8.4"]
os: [ubuntu-22.04, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Run image
uses: abatilo/actions-poetry@v3
with:
poetry-version: ${{ matrix.poetry-version }}
- name: View poetry --help
run: poetry --help
It is possible to combine actions/poetry with actions/cache to speed up the installation of dependencies.
The recipe is:
poetry to create a virtual environment inside the project:
it creates a local .venv/ folder that can be cachedpoetry.lock file:
if the contents change (meaning that dependencies have changed), then the cache needs to be invalidated and recreatedFor the 1st step, you either need:
poetry.toml file
(and not pyproject.toml)
at the root of your project with these 2 settings:[virtualenvs]
create = true
in-project = true
poetry.toml file:poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
Here is an example of how the steps must be declared:
jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v4
# see details (matrix, python-version, python-version-file, etc.)
# https://github.com/actions/setup-python
- name: Install poetry
uses: abatilo/actions-poetry@v4
- name: Setup a local virtual environment (if no poetry.toml file)
run: |
poetry config virtualenvs.create true --local
poetry config virtualenvs.in-project true --local
- uses: actions/cache@v3
name: Define a cache for the virtual environment based on the dependencies lock file
with:
path: ./.venv
key: venv-${{ hashFiles('poetry.lock') }}
- name: Install the project dependencies
run: poetry install
- name: Run the automated tests (for example)
run: poetry run pytest -v
MIT License - abatilo/actions-poetry
765 followers · starred Jul 2021
7,139 followers · starred Jan 2025
657 followers · starred Sep 2022
486 followers · starred Sep 2023