Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/cacheHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ArtifactCacheEntry } from "./contracts";

export async function getCacheEntry(
keys: string[]
): Promise<ArtifactCacheEntry> {
): Promise<ArtifactCacheEntry | null> {
const cacheUrl = getCacheUrl();
const token = process.env["ACTIONS_RUNTIME_TOKEN"] || "";
const bearerCredentialHandler = new BearerCredentialHandler(token);
Expand All @@ -28,9 +28,7 @@ export async function getCacheEntry(
getRequestOptions()
);
if (response.statusCode === 204) {
throw new Error(
`Cache not found for input keys: ${JSON.stringify(keys)}.`
);
return null;
}
if (response.statusCode !== 200) {
throw new Error(`Cache service responded with ${response.statusCode}`);
Expand Down
12 changes: 9 additions & 3 deletions src/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,20 @@ async function run() {
}

try {
const cacheEntry = await cacheHttpClient.getCacheEntry(keys);
if (!cacheEntry) {
core.info(
`Cache not found for input keys: ${JSON.stringify(keys)}.`
);
return;
}

let archivePath = path.join(
await utils.createTempDirectory(),
"cache.tgz"
);
core.debug(`Archive Path: ${archivePath}`);

const cacheEntry = await cacheHttpClient.getCacheEntry(keys);

// Store the cache result
utils.setCacheState(cacheEntry);

Expand Down Expand Up @@ -92,7 +98,7 @@ async function run() {
utils.setCacheHitOutput(isExactKeyMatch);

core.info(
`Cache restored from key:${cacheEntry && cacheEntry.cacheKey}`
`Cache restored from key: ${cacheEntry && cacheEntry.cacheKey}`
);
} catch (error) {
core.warning(error.message);
Expand Down