abatilo / actions-poetry

GitHub Actions for Python projects using poetry
MIT License
423 stars 40 forks source link

Add caching #26

Closed NixBiks closed 4 years ago

NixBiks commented 4 years ago

Good job on a very simple api for this action.

Is it possible to add some caching though? In your example python is being installed twice even. It would be nice if the environment would be cached between pushes so only the testing would be run on pushes (unless there is a dependency or similar change of course)

name: Run Tests
on: push

jobs:
  pytest:
    name: pytest
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@master
    - name: Install
      uses: abatilo/actions-poetry@v1.5.0
      with:
        python_version: 3.8.0
        poetry_version: 1.0
        working_directory: ./working_dir # Optional, defaults to '.'
        args: install
    - name: Run pytest
      uses: abatilo/actions-poetry@v1.5.0
      with:
        python_version: 3.8.0
        poetry_version: 1.0
        working_directory: ./working_dir
        args: run python -m pytest --cov=src --cov-branch --cov-fail-under=100 tests/
abatilo commented 4 years ago

Since these steps run as two different containers, I'm honestly not sure if we can do any caching between the two. Have you seen any examples of this on any other projects?

marcosfelt commented 4 years ago

I've been trying to get the cache action to play with poetry, but I'm not sure where the virtual environments are being stored in this action.

trickeydan commented 4 years ago

I've been trying to get the cache action to play with poetry, but I'm not sure where the virtual environments are being stored in this action.

I've been calling poetry config virtualenvs.in-project true which puts the virtualenv in .venv

It's not ideal, but seems to work. I'd prefer if I could do it a better way.

abatilo commented 4 years ago

I've been trying to get the cache action to play with poetry, but I'm not sure where the virtual environments are being stored in this action.

@marcosfelt

Looks like the default location for the poetry virtualenv is under ~/.cache/pypoetry

That being said, because this action works as its own container, it doesn't benefit from the same caching that the usual action cache enables.

If you want to use the official cache action to play nicely, you'll need to install Poetry using this (or similar) action: https://github.com/marketplace/actions/setup-poetry#cache-dependencies-to-speed-up-workflows

Instead of running poetry in its own container, the setup-poetry action installs poetry to the actual GitHub Action runner host environment, which is where the cache actions store things as well.

The setup-* pattern seems to be more or less become the standard pattern these days as well.