5
0
mirror of https://github.com/pnpm/action-setup.git synced 2026-08-05 02:31:37 +00:00

refactor: introduce restore keys for cache (#280)

This commit is contained in:
Sukka
2026-08-03 16:32:23 +08:00
committed by GitHub
parent 6fed91f804
commit 769ae71fb3
2 changed files with 102 additions and 93 deletions
+91 -91
View File
File diff suppressed because one or more lines are too long
+11 -2
View File
@@ -18,9 +18,18 @@ export async function runRestoreCache(inputs: Inputs) {
debug(`Primary key is ${primaryKey}`) debug(`Primary key is ${primaryKey}`)
saveState('cache_primary_key', primaryKey) saveState('cache_primary_key', primaryKey)
let cacheKey = await restoreCache([cachePath], primaryKey) // We don't need to download everything again if only one dependency changed
// We can still re-use previous store to cache the rest of the unchanged dependencies
const restoreKeys = [
`pnpm-cache-${process.env.RUNNER_OS}-${os.arch()}-`
];
setOutput('cache-hit', Boolean(cacheKey)) let cacheKey = await restoreCache([cachePath], primaryKey, restoreKeys)
// A restore-key (prefix) match still restores an older store, but "cache-hit"
// must only report an exact primary-key match, so dependency installation
// is not skipped when the lockfile has changed.
setOutput('cache-hit', cacheKey === primaryKey)
if (!cacheKey) { if (!cacheKey) {
info(`Cache is not found`) info(`Cache is not found`)