From f60ef1e8084a2e64569f928c3f1cfac6c7e12ad7 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Sat, 11 Feb 2023 14:17:29 +0100 Subject: [PATCH] Include working directory, $BUNDLE_WITH and $BUNDLE_WITHOUT in cache key * Fixes https://github.com/ruby/setup-ruby/issues/350 * Fixes https://github.com/ruby/setup-ruby/issues/176 --- bundler.js | 10 ++++++++-- dist/index.js | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/bundler.js b/bundler.js index 3d39290f6..c418c0d0f 100644 --- a/bundler.js +++ b/bundler.js @@ -232,8 +232,14 @@ export async function bundleInstall(gemfile, lockFile, platform, engine, rubyVer } async function computeBaseKey(platform, engine, version, lockFile, cacheVersion) { - const cacheVersionSuffix = DEFAULT_CACHE_VERSION === cacheVersion ? '' : `-cachever:${cacheVersion}` - let key = `setup-ruby-bundler-cache-v4-${platform}-${engine}-${version}${cacheVersionSuffix}` + const cwd = process.cwd() + const bundleWith = process.env['BUNDLE_WITH'] || '' + const bundleWithout = process.env['BUNDLE_WITHOUT'] || '' + let key = `setup-ruby-bundler-cache-v5-${platform}-${engine}-${version}-wd-${cwd}-with-${bundleWith}-without-${bundleWithout}` + + if (cacheVersion !== DEFAULT_CACHE_VERSION) { + key += `-v-${cacheVersion}` + } if (common.isHeadVersion(version)) { if (engine !== 'jruby') { diff --git a/dist/index.js b/dist/index.js index ba17f8664..565477eac 100644 --- a/dist/index.js +++ b/dist/index.js @@ -246,8 +246,14 @@ async function bundleInstall(gemfile, lockFile, platform, engine, rubyVersion, b } async function computeBaseKey(platform, engine, version, lockFile, cacheVersion) { - const cacheVersionSuffix = DEFAULT_CACHE_VERSION === cacheVersion ? '' : `-cachever:${cacheVersion}` - let key = `setup-ruby-bundler-cache-v4-${platform}-${engine}-${version}${cacheVersionSuffix}` + const cwd = process.cwd() + const bundleWith = process.env['BUNDLE_WITH'] || '' + const bundleWithout = process.env['BUNDLE_WITHOUT'] || '' + let key = `setup-ruby-bundler-cache-v5-${platform}-${engine}-${version}-wd-${cwd}-with-${bundleWith}-without-${bundleWithout}` + + if (cacheVersion !== DEFAULT_CACHE_VERSION) { + key += `-v-${cacheVersion}` + } if (common.isHeadVersion(version)) { if (engine !== 'jruby') {