GithubHelp home page GithubHelp logo

actions-poetry's Introduction

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.8", "3.9", "3.10", "3.11"]
        poetry-version: ["1.2.2", "1.7.1"]
        os: [ubuntu-22.04, macos-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - 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 (and not pyproject.toml) 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@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@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

actions-poetry's People

Contributors

abatilo avatar dependabot-preview[bot] avatar browniebroke avatar jennydaman avatar cclauss avatar jamesbraza avatar lucsorel avatar nargit avatar mrflynn avatar noritada avatar rockymm avatar siddhantgoel avatar 515hikaru avatar xsavikx avatar aisensiy avatar duarte-pompeu avatar mammo0 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.