Skip to content

Commit 4aa485b

Browse files
committed
Don't try to upload cache if we have restored a cache with the same key
1 parent 4087e50 commit 4aa485b

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/analyze-action.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.

src/dependency-caching.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,18 @@ export async function uploadDependencyCaches(
385385
continue;
386386
}
387387

388+
// Now that we have verified that there are suitable files, compute the hash for the cache key.
389+
const key = await cacheKey(codeql, features, language, patterns);
390+
391+
// Check that we haven't previously restored this exact key. If a cache with this key
392+
// already exists in the Actions Cache, performing the next steps is pointless as the cache
393+
// will not get overwritten. We can therefore skip the expensive work of measuring the size
394+
// of the cache contents and attempting to upload it if we know that the cache already exists.
395+
if (config.dependencyCachingRestoredKeys.includes(key)) {
396+
status.push({ language, result: CacheStoreResult.Duplicate });
397+
continue;
398+
}
399+
388400
// Calculate the size of the files that we would store in the cache. We use this to determine whether the
389401
// cache should be saved or not. For example, if there are no files to store, then we skip creating the
390402
// cache. In the future, we could also:
@@ -410,8 +422,6 @@ export async function uploadDependencyCaches(
410422
continue;
411423
}
412424

413-
const key = await cacheKey(codeql, features, language, patterns);
414-
415425
logger.info(
416426
`Uploading cache of size ${size} for ${language} with key ${key}...`,
417427
);

0 commit comments

Comments
 (0)