• Stars
    star
    414
  • Rank 103,933 (Top 3 %)
  • Language
  • License
    MIT License
  • Created over 5 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

GitHub Actions for Python projects using poetry

actions-poetry

GitHub Actions for Python projects using poetry

license release GitHub release date

Getting started

Breaking changes for v2

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.

Create your workflow

name: CI
on: pull_request

jobs:
  ci:
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
        poetry-version: ["1.0", "1.1.15"]
        os: [ubuntu-18.04, macos-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
      - name: Run image
        uses: abatilo/actions-poetry@v2
        with:
          poetry-version: ${{ matrix.poetry-version }}
      - name: View poetry --help
        run: poetry --help

Workflow example: cache the virtual environment

It is possible to combine actions/poetry with actions/cache to speed up the installation of dependencies. The recipe is:

  1. to ask poetry to create a virtual environment inside the project: it creates a local .venv/ folder that can be cached
  2. to create a cache key that involves the contents of the poetry.lock file: if the contents change (meaning that dependencies have changed), then the cache needs to be invalidated and recreated

For the 1st step, you either need:

  • to have a poetry.toml file at the root of your project with these 2 settings:
[virtualenvs]
create = true
in-project = true
  • or to run the following commands in the github actions to create the 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@v3
      - 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@v2
      - 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

License

MIT License - abatilo/actions-poetry

About the author

More Repositories

1

typed-json-dataclass

A python3.7 dataclass supplemental library. Enhances dataclasses to perform basic type checking and makes the dataclass JSON serializable.
Python
78
star
2

github-action-locks

Guarantee atomic execution of your GitHub Action workflows
Go
16
star
3

sanic-swagger

Easily document your Sanic API with a UI (and attrs!)
Python
14
star
4

ec2throughput.info

A website to see and measure EC2 network throughput baselines vs burst performance.
TypeScript
13
star
5

aws-assume-role-action

A GitHub Action which sets your AWS environment variables so that it can assume a role
Shell
11
star
6

newsletter-bake-monorepo

TypeScript
7
star
7

release-info-action

Get the latest release of some GitHub repository
7
star
8

catfacts

Learn something new about cats once per day
Mustache
3
star
9

github-ratelimit-metrics

Expose GitHub App rate limits as Prometheus metrics
Go
3
star
10

sliceofexperiments

Projects and code samples that are featured on https://sliceofexperiments.substack.com
Mustache
3
star
11

readinglevel

https://www.readinglevel.app
TypeScript
2
star
12

groupcache-k8s-sample

Example of using groupcache in k8s
Go
2
star
13

asdf-argo-rollouts

asdf-vm plugin for https://github.com/argoproj/argo-rollouts
Shell
2
star
14

multiple-choice-ai

Service that will answer multiple choice questions using word vectors
Java
2
star
15

summarybox

Keyword extraction from an unlabeled corpus.
Java
1
star
16

istio-https-grpc

Fully declarative Istio 1.8 installation using helmfile with cert-manager http01 challenge for TLS / https termination of gRPC services and Kiali for visualization
1
star
17

vimrc

My personal vim settings
Lua
1
star
18

sealedmessages

Adjournment as a service
TypeScript
1
star
19

contract-ai

Read a document and ask questions about it
Python
1
star
20

go-gcache-redis-sample

Using Redis as the backend for Go's gcache library
Go
1
star
21

asdf-httpie-go

asdf-vm plugin for https://github.com/nojima/httpie-go
Shell
1
star
22

digitalocean-kubernetes-challenge

My entry for https://www.digitalocean.com/community/pages/kubernetes-challenge
1
star
23

grpc-todo

A place for me to experiment with grpc services
Go
1
star
24

aoc2021

Advent of Code 2021 done entirely with copilot
Go
1
star
25

streamlit-preview-environments-demo

A demonstration of using Traefik IngressRoute and Kubernetes for dynamically creating preview environments.
Go
1
star
26

sanic-healthchecks

A small wrapper for making it easy to add a healthcheck server to your Sanic application
Python
1
star
27

argo-rollouts-canary-demo

A demonstration repository for performing canary deployments using argo-rollouts
Makefile
1
star
28

asdf-gitops

Experimenting with asdf based installations for various GitOps pipelines.
HCL
1
star
29

pushgateway-cleaner

Go
1
star