Skip to content

Commit bacba73

Browse files
committed
Run bundle clean when reusing a cache and the lockfile changed
* Fixes #113
1 parent 21351ec commit bacba73

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

dist/index.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ async function bundleInstall(gemfile, lockFile, platform, engine, version) {
249249
const paths = [path]
250250
const baseKey = await computeBaseKey(platform, engine, version, lockFile)
251251
const key = `${baseKey}-${await common.hashFile(lockFile)}`
252-
// If only Gemfile.lock changes we can reuse part of the cache (but it will keep old gem versions in the cache)
252+
// If only Gemfile.lock changes we can reuse part of the cache, and clean old gem versions below
253253
const restoreKeys = [`${baseKey}-`]
254254
console.log(`Cache key: ${key}`)
255255

@@ -274,6 +274,10 @@ async function bundleInstall(gemfile, lockFile, platform, engine, version) {
274274

275275
// @actions/cache only allows to save for non-existing keys
276276
if (cachedKey !== key) {
277+
if (cachedKey) { // existing cache but Gemfile.lock differs, clean old gems
278+
await exec.exec('bundle', ['clean'])
279+
}
280+
277281
// Error handling from https://github.com/actions/cache/blob/master/src/save.ts
278282
console.log('Saving cache')
279283
try {

0 commit comments

Comments
 (0)