abatilo / actions-poetry

GitHub Actions for Python projects using poetry
MIT License
427 stars 43 forks source link

please document how the cache should be configured using this action #64

Closed lucsorel closed 1 year ago

lucsorel commented 1 year ago

thank you @abatilo for this github action :pray:

Before using your action, I:

    steps:
      - uses: actions/checkout@v3
      - name: Install poetry
        run: pipx install poetry
      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version-file: '.python-version'
          cache: 'poetry' # <- this is where a cache was defined for poetry
      - name: Install dependencies
        run: poetry install

I tried using the actions-poetry action like this:

    steps:
      - uses: actions/checkout@v3
      - name: Install Python
        uses: actions/setup-python@v4
        with:
          python-version-file: '.python-version'
          cache: 'poetry' # <- this cause the installation to fail
      - name: Install poetry
        uses: abatilo/actions-poetry@v2
        with:
          poetry-version: 1.5.1
      - name: Install project dependencies
        run: poetry install

The cache 'poetry' line in the actions/setup-python@v4 action causes the job to fail:

Error: Unable to locate executable file: poetry. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also check the file mode to verify the file is executable.

Can you please tell me (and add in the README file) how one should set up a cache for poetry to speed up the download of dependencies? :pray:

kosinal commented 1 year ago

I use caching in my project with following setting:

In definition of the github action job:

- uses: actions/cache@v3
  name: Cache .venv
  with:
    path: ./.venv
    key: venv-${{ hashFiles('poetry.lock') }}

Add poetry.toml file in root of project with following settings:

[virtualenvs]
create = true
in-project = true

How does it work:

Received 855004 (100.0%), 144.3 MBs/sec Cache Size: ~82 MB (85500470 B) /usr/bin/tar -xf /home/runner/work/_temp/8cca7c6a-f27b-448d-8c10-5f718fafd2ed/cache.tzst -P -C Cache restored successfully Cache restored from key: venv-1cdf2[9]

poetry install

Installing dependencies from lock file

No dependencies to install or update



Using this, when dependencies do not change in build, I do not have to download and install it again, but I can skip this step and do testing.
lucsorel commented 1 year ago

:pray: thank you very much for your comprehensive explanation :smiley:

Just to make sure I got it right, can you confirm that the steps would be in the following order, please?

name: Python package
# ...
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install Python
        uses: actions/setup-python@v4
        with:
          python-version-file: '.python-version'
      - name: Install poetry
        uses: abatilo/actions-poetry@v2
        with:
          poetry-version: 1.5.1
      - uses: actions/cache@v3
        name: Cache .venv
        with:
          path: ./.venv
          key: venv-${{ hashFiles('poetry.lock') }}
      - name: Install project dependencies
        run: poetry install
      - name: Run automated tests
        run: poetry run pytest -v 

Is that ok? [edit: it seems to work as expected like this - @kosinal I would like to write a pull-request which would add a section in the README file explaining the process of caching the virtual environment: what do you think? Would that be of interest to you?]

[edit2: hi @abatilo; would you be interested in a pull-request adding a section in the README file to document how to combine actions-poetry with actions/cache for faster poetry install calls?]

kosinal commented 1 year ago

I am neither owner nor contributer to this repo.

It is more up to @abatilo what should or should not be in his project readme :)

lucsorel commented 1 year ago

I am neither owner nor contributer to this repo.

It is more up to abatilo what should or should not be in his project readme :)

Forgive me for the confusion :+1:

Beside that, does the workflow proposed in https://github.com/abatilo/actions-poetry/issues/64#issuecomment-1621917036 seem ok to you?

abatilo commented 1 year ago

Sorry for the delay here. I was traveling for work.

I think it makes sense that the original workflow steps would fail. You are trying to reference the poetry cash in this step that installs Python but poetry hasn't actually been installed yet. So there's a chicken and egg problem.

Installing Python and then installing poetry and then doing the cache steps make sense to me.

I would definitely be open to a pull request that adds the guidance to the readme.

Thank you both

kosinal commented 1 year ago

I am neither owner nor contributer to this repo. It is more up to abatilo what should or should not be in his project readme :)

Forgive me for the confusion 👍

Beside that, does the workflow proposed in #64 (comment) seem ok to you?

It looks good.

lucsorel commented 1 year ago

hi @abatilo

I created this PR: https://github.com/abatilo/actions-poetry/pull/65. Feel free to comment and amend it :smiley:

github-actions[bot] commented 10 months ago

:tada: This issue has been resolved in version 2.4.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: