gabrielfalcao / pyenv-action

Enables pyenv within your github actions workflow
MIT License
39 stars 17 forks source link

Tool cache is not working #320

Closed ursetto closed 2 years ago

ursetto commented 2 years ago

The tool cache is not working in a couple ways:

  1. pyenv-archive.zip is always downloaded fresh, even if it is already in the cache.
  2. pyenv_root is always recreated, even if it already exists.

The second is a critical bug. On the first run, python installs successfully. On the second run, pyenv is reinstalled, overwriting the installed python in pyenv_root. However, the cache believes python is installed (since that tool cache is working) and does not rebuild and reinstall it. Attempting to switch to that python now fails.

The second issue manifests if you try to run the action twice in a row or twice in the same container. For example it can be reproduced in a self-hosted runner, or tested with act --reuse, or seen on a standard runner by using the action twice in the same job. It is not caught in the npm tests because that simply installs pyenv twice, but does not attempt to install python itself twice.

The fix is simple and a pull request is forthcoming.

ursetto commented 2 years ago

Attached example bad run, which uses the action twice in a row. The second one fails due to assuming Python 3.7.5 is installed when it has been overwritten.

test_pyenv_375_twice.txt

Extract below from the second run shows the cached archive.zip is redownloaded, pyenv_root recreated, and python 3.7.5 run fails despite the Using cached python installation 3.7.5 message.

[Continuous Integration/install pyenv]   💬  ::debug::checking cache: /opt/hostedtoolcache/pyenv-archive.zip/2.2.4/x64
[Continuous Integration/install pyenv]   💬  ::debug::Found tool in cache pyenv-archive.zip 2.2.4 x64
[Continuous Integration/install pyenv]   | downloading https://github.com/pyenv/pyenv/archive/v2.2.4.zip
[Continuous Integration/install pyenv]   💬  ::debug::Downloading https://github.com/pyenv/pyenv/archive/v2.2.4.zip
..
[Continuous Integration/install pyenv]   💬  ::debug::checking cache: /opt/hostedtoolcache/pyenv_archive/2.2.4/x64
[Continuous Integration/install pyenv]   💬  ::debug::not found
[Continuous Integration/install pyenv]   | [command]/usr/bin/unzip -q /opt/hostedtoolcache/pyenv-archive.zip/2.2.4/x64/pyenv-archive.zip
[Continuous Integration/install pyenv]   | Extracted /opt/hostedtoolcache/pyenv-archive.zip/2.2.4/x64/pyenv-archive.zip to /tmp/cc97708e-a459-42c7-842f-c04488fe4616.
[Continuous Integration/install pyenv]   💬  ::debug::Caching tool pyenv_root 2.2.4 x64
...
[Continuous Integration/install pyenv]   💬  ::debug::checking cache: /opt/hostedtoolcache/pyenv-2.2.4-python/3.7.5/x64
[Continuous Integration/install pyenv]   💬  ::debug::Found tool in cache pyenv-2.2.4-python 3.7.5 x64
[Continuous Integration/install pyenv]   | Using cached python installation 3.7.5
[Continuous Integration/install pyenv]   💬  ::debug::isExplicit: 3.7.5
[Continuous Integration/install pyenv]   💬  ::debug::explicit? true
[Continuous Integration/install pyenv]   💬  ::debug::checking cache: /opt/hostedtoolcache/pyenv-2.2.4-python/3.7.5/x64
[Continuous Integration/install pyenv]   💬  ::debug::Found tool in cache pyenv-2.2.4-python 3.7.5 x64
[Continuous Integration/install pyenv]   | [command]/opt/hostedtoolcache/pyenv_root/2.2.4/x64/bin/pyenv local 3.7.5
[Continuous Integration/install pyenv]   | pyenv: version `3.7.5' not installed
[Continuous Integration/install pyenv]   | Failed to set python 3.7.5: {error.message}
[Continuous Integration/install pyenv]   ❗  ::error::The process '/opt/hostedtoolcache/pyenv_root/2.2.4/x64/bin/pyenv' failed with exit code 1
[Continuous Integration/install pyenv]   ❌  Failure - setup pyenv
elliotmakuh commented 2 years ago

Any update on this issue? I'm running into this on a self hosted runner and am not sure how to work around it.

ursetto commented 2 years ago

If you want to try my PR in #321, feel free. It works perfectly for me. Just try

uses: ursetto/pyenv-action@cache-fix

Having another tester might help it get merged.

elliotmakuh commented 2 years ago

I've been using this on my self hosted Pi for the last few days and it seems to be working. I have only run ~5 actions but haven't run into the caching issue.