setup-ruby icon indicating copy to clipboard operation
setup-ruby copied to clipboard

bundler-cache doesn't work with different working-directories.

Open fsimonis opened this issue 2 years ago • 3 comments

Using the caching functionality of the action various times using different working-directories leads to incorrectly restored caches.

First workflow runs and caches website/vendor/bundle

- uses: ruby/setup-ruby@v1
  with:
    bundler-cache: true
    working-directory: website

Second workflow runs and restores the cache:

- uses: ruby/setup-ruby@v1
  with:
    bundler-cache: true

Then the cache gets restored in website/vendor/bundle instead of vendor/bundle. bundle install runs normally as it is configured to use vendor/bundle

Example of the second workflow. jekyll build fails here as it picks up files in website/vendor/bundle

fsimonis avatar Jun 27 '22 11:06 fsimonis

Right, so we need to make the value of working-directory: part of the cache key. Until then, a workaround is to use cache-version: <working-directory> to ensure a separate cache per working directory.

eregon avatar Jun 27 '22 19:06 eregon

An alternative would be to create and extract the cache relative to the working directory.

This way, both workflows use a single cache.

fsimonis avatar Jun 28 '22 07:06 fsimonis

I think that wouldn't work, there will be most likely absolute paths e.g. embedded in built C extensions.

eregon avatar Jun 28 '22 09:06 eregon