Skip to content

Commit

Permalink
Added restoreCacheKeys so cache.restoreCache will restore closest match
Browse files Browse the repository at this point in the history
That way running pre-commit should only update envs that need changing.
If the restored cache doesn't match the cacheKey exactly (python version or config changed), it will try to save the envs  with the new cacheKey to cache.
  • Loading branch information
s-weigand committed Oct 12, 2020
1 parent 470aac6 commit 1081ded
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ async function main() {
const cachePaths = [path.join(os.homedir(), '.cache', 'pre-commit')];
const py = getPythonVersion();
const cacheKey = `pre-commit-2-${hashString(py)}-${hashFile('.pre-commit-config.yaml')}`;
const restored = await cache.restoreCache(cachePaths, cacheKey);
const restoreCacheKeys = [`pre-commit-2-${hashString(py)}-`, "pre-commit-2-"];
const restored = await cache.restoreCache(cachePaths, cacheKey, restoreCacheKeys);
const ret = await exec.exec('pre-commit', args, {ignoreReturnCode: push});
if (!restored) {
if (restored !== cacheKey) {
try {
await cache.saveCache(cachePaths, cacheKey);
} catch (e) {
Expand Down

0 comments on commit 1081ded

Please sign in to comment.