Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lucsorel opened this issue Jul 3, 2023 · 8 comments 路 Fixed by #65
Closed

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

lucsorel opened this issue Jul 3, 2023 · 8 comments 路 Fixed by #65
Labels

Comments

@lucsorel
Copy link
Contributor

lucsorel commented Jul 3, 2023

thank you @abatilo for this github action 馃檹

Before using your action, I:

  • installed poetry
  • then installed python defining a cache
    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? 馃檹

@kosinal
Copy link

kosinal commented Jul 4, 2023

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:

  • With settings in poetry.toml, virtual environment is being created inside project in .venv folder
  • I do cache .venv folder based on hash of my poetry.lock file, which contains current dependencies
  • When my CI job stars, I can see following:
Run actions/cache@v3
  with:
    path: ./.venv
    key: venv-1cdf[2]
    enableCrossOsArchive: false
    fail-on-cache-miss: false
    lookup-only: false
 
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
Copy link
Contributor Author

lucsorel commented Jul 5, 2023

馃檹 thank you very much for your comprehensive explanation 馃槂

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
Copy link

kosinal commented Jul 5, 2023

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
Copy link
Contributor Author

lucsorel commented Jul 5, 2023

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?

@abatilo
Copy link
Owner

abatilo commented Jul 5, 2023

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
Copy link

kosinal commented Jul 6, 2023

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
Copy link
Contributor Author

lucsorel commented Jul 6, 2023

hi @abatilo

I created this PR: #65. Feel free to comment and amend it 馃槂

Copy link

馃帀 This issue has been resolved in version 2.4.0 馃帀

The release is available on GitHub release

Your semantic-release bot 馃摝馃殌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants