Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Rework cache handling
  • Loading branch information
Vladimir Safonkin committed Jun 28, 2022
1 parent 6036aa2 commit 0fd9200
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 49 deletions.
72 changes: 54 additions & 18 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -23,11 +23,11 @@
"author": "GitHub",
"license": "MIT",
"dependencies": {
"@actions/cache": "^2.0.2",
"@actions/cache": "^3.0.0",
"@actions/core": "^1.6.0",
"@actions/exec": "^1.1.0",
"@actions/glob": "^0.2.0",
"@actions/http-client": "^1.0.6",
"@actions/http-client": "^2.0.1",
"@actions/io": "^1.0.2",
"@actions/tool-cache": "^1.5.5",
"semver": "^6.1.1"
Expand Down
27 changes: 9 additions & 18 deletions src/cache-restore.ts
Expand Up @@ -34,26 +34,17 @@ export const restoreCache = async (

core.saveState(State.CachePrimaryKey, primaryKey);

try {
const cacheKey = await cache.restoreCache(cachePaths, primaryKey);
core.setOutput(Outputs.CacheHit, Boolean(cacheKey));
const cacheKey = await cache.restoreCache(cachePaths, primaryKey);
core.setOutput(Outputs.CacheHit, Boolean(cacheKey));

if (!cacheKey) {
core.info(`Cache is not found`);
return;
}

core.saveState(State.CacheMatchedKey, cacheKey);
core.info(`Cache restored from key: ${cacheKey}`);
} catch (error) {
const typedError = error as Error;
if (typedError.name === cache.ValidationError.name) {
throw error;
} else {
core.warning(typedError.message);
core.setOutput(Outputs.CacheHit, false);
}
if (!cacheKey) {
core.info(`Cache is not found`);
core.setOutput(Outputs.CacheHit, false);
return;
}

core.saveState(State.CacheMatchedKey, cacheKey);
core.info(`Cache restored from key: ${cacheKey}`);
};

const findDependencyFile = (packageManager: PackageManagerInfo) => {
Expand Down
15 changes: 4 additions & 11 deletions src/cache-save.ts
Expand Up @@ -58,18 +58,11 @@ const cachePackages = async () => {
return;
}

try {
await cache.saveCache(cachePaths, primaryKey);
core.info(`Cache saved with the key: ${primaryKey}`);
} catch (error) {
if (error.name === cache.ValidationError.name) {
throw error;
} else if (error.name === cache.ReserveCacheError.name) {
core.info(error.message);
} else {
core.warning(`${error.message}`);
}
const cacheId = await cache.saveCache(cachePaths, primaryKey);
if (cacheId == -1) {
return;
}
core.info(`Cache saved with the key: ${primaryKey}`);
};

export function logWarning(message: string): void {
Expand Down

0 comments on commit 0fd9200

Please sign in to comment.