Run bundle clean when reusing a cache and the lockfile changed

* Fixes https://github.com/ruby/setup-ruby/issues/113
This commit is contained in:
Benoit Daloze
2020-12-02 17:36:27 +01:00
parent 21351ecc0a
commit bacba738b2
2 changed files with 10 additions and 2 deletions
Generated Vendored
+5 -1
View File
@@ -51421,7 +51421,7 @@ async function bundleInstall(gemfile, lockFile, platform, engine, version) {
const paths = [path]
const baseKey = await computeBaseKey(platform, engine, version, lockFile)
const key = `${baseKey}-${await common.hashFile(lockFile)}`
// If only Gemfile.lock changes we can reuse part of the cache (but it will keep old gem versions in the cache)
// If only Gemfile.lock changes we can reuse part of the cache, and clean old gem versions below
const restoreKeys = [`${baseKey}-`]
console.log(`Cache key: ${key}`)
@@ -51446,6 +51446,10 @@ async function bundleInstall(gemfile, lockFile, platform, engine, version) {
// @actions/cache only allows to save for non-existing keys
if (cachedKey !== key) {
if (cachedKey) { // existing cache but Gemfile.lock differs, clean old gems
await exec.exec('bundle', ['clean'])
}
// Error handling from https://github.com/actions/cache/blob/master/src/save.ts
console.log('Saving cache')
try {
+5 -1
View File
@@ -249,7 +249,7 @@ async function bundleInstall(gemfile, lockFile, platform, engine, version) {
const paths = [path]
const baseKey = await computeBaseKey(platform, engine, version, lockFile)
const key = `${baseKey}-${await common.hashFile(lockFile)}`
// If only Gemfile.lock changes we can reuse part of the cache (but it will keep old gem versions in the cache)
// If only Gemfile.lock changes we can reuse part of the cache, and clean old gem versions below
const restoreKeys = [`${baseKey}-`]
console.log(`Cache key: ${key}`)
@@ -274,6 +274,10 @@ async function bundleInstall(gemfile, lockFile, platform, engine, version) {
// @actions/cache only allows to save for non-existing keys
if (cachedKey !== key) {
if (cachedKey) { // existing cache but Gemfile.lock differs, clean old gems
await exec.exec('bundle', ['clean'])
}
// Error handling from https://github.com/actions/cache/blob/master/src/save.ts
console.log('Saving cache')
try {