Git Product home page Git Product logo

action-setup-cache-python-poetry's Introduction

GitHub Action - Setup and Cache Python Poetry

This action simplifies the setup and caching of Poetry, and provides the following functionality for GitHub Actions users:

Basic Usage

Note:

  • We assume you already have pyproject.toml, poetry.lock and a test module created for pytest to run this workflow example.
  • For your first push to main, the workflow will download Poetry and the required project dependencies, then save it to the cache.
  • For your second run (whether it's on a different job, re-run the job or a different workflow based on your first cached commit) this Action will use the cache.
  • You can see list of cache entries by going to: Your Repo -> Actions tab -> Caches under Managements (left navbar, at the bottom).

Don't forget the limitation of cache.

name: ci

on:
  # Triggers the workflow on push but only for the main branch
  push:
    branches: [ main ]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      #-------------------------------------#
      #  Check out repo and set up Python   #
      #-------------------------------------#
      - name: Check out the repository
        uses: actions/checkout@v3
      - name: "Setup Python, Poetry and Dependencies"
        uses: packetcoders/action-setup-cache-python-poetry@main
        with:
          python-version: 3.8
          poetry-version: 1.2.2

      #------------------------#
      #  Run your actual job   #
      #------------------------#
      - name: Run tests
        run: |
          poetry run pytest

With a matrix strategy, several "workflows" are generated based on your matrix inputs. In this case, multiple caches for each of the matrix workflows will be generated.

name: ci

on:
  # Triggers the workflow on push but only for the main branch
  push:
    branches: [ main ]

jobs:
  test:
    # Using matrix strategy
    strategy:
      matrix:
        python-version: [3.8, 3.9, 3.10]
        poetry-version: [1.2.2]
    runs-on: ubuntu-latest
    steps:
      #------------------------------------#
      #  Check out repo and set up Python  #
      #------------------------------------#
      - name: Check out the repository
        uses: actions/checkout@v3
      - name: "Setup Python, Poetry and Dependencies"
        uses: packetcoders/action-setup-cache-python-poetry@main
        with:
          python-version: ${{matrix.python-version}}
          poetry-version: ${{matrix.poetry-version}}

      #-----------------------#
      #  Run your actual job  #
      #-----------------------#
      - name: Run tests
        run: |
          poetry run pytest

Advanced usage

Passing extra arguments to poetry install

By default the action will install your dendencies with poetry install --no-interaction --no-root You can specify extra arguments with install-args, e.g.

      - name: "Setup Python, Poetry and Dependencies"
        uses: packetcoders/action-setup-cache-python-poetry@main
        with:
          python-version: "3.12"
          poetry-version: "1.6.1"
          install-args: --all-extras

to install any optional dependencies alongside the required ones.

License

The scripts and documentation in this project are released under the MIT License.

action-setup-cache-python-poetry's People

Contributors

jvansanten avatar rickdonato avatar tegarimansyah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.