Skip to content

Commit

Permalink
Prune cache before saving
Browse files Browse the repository at this point in the history
  • Loading branch information
eifinger committed Aug 24, 2024
1 parent 6c37ad0 commit 332ac35
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
13 changes: 12 additions & 1 deletion dist/save-cache/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion src/save-cache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as cache from '@actions/cache'
import * as core from '@actions/core'
import * as exec from '@actions/exec'
import {STATE_CACHE_MATCHED_KEY, STATE_CACHE_KEY} from './cache/restore-cache'
import {cacheLocalPath, enableCache} from './utils/inputs'

Expand All @@ -23,14 +24,26 @@ async function saveCache(): Promise<void> {
core.warning('Error retrieving cache key from state.')
return
} else if (matchedKey === cacheKey) {
// no change in target directories
core.info(`Cache hit occurred on key ${cacheKey}, not saving cache.`)
return
}

await pruneCache()

core.info(`Saving cache path: ${cacheLocalPath}`)
await cache.saveCache([cacheLocalPath], cacheKey)

core.info(`cache saved with the key: ${cacheKey}`)
}

async function pruneCache(): Promise<void> {
const options: exec.ExecOptions = {
silent: !core.isDebug()
}
const execArgs = ['cache', 'prune', '--ci']

core.info('Pruning cache...')
await exec.exec('uv', execArgs, options)
}

run()

0 comments on commit 332ac35

Please sign in to comment.