Skip to content

Commit

Permalink
Fix checking state cache (fix #1136), also switch to octokit methods
Browse files Browse the repository at this point in the history
  • Loading branch information
itchyny committed Apr 10, 2024
1 parent 3f3b017 commit 0980a21
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
17 changes: 12 additions & 5 deletions dist/index.js
Expand Up @@ -1618,9 +1618,13 @@ const getOctokitClient = () => {
const checkIfCacheExists = (cacheKey) => __awaiter(void 0, void 0, void 0, function* () {
const client = getOctokitClient();
try {
const issueResult = yield client.request(`/repos/${github_1.context.repo.owner}/${github_1.context.repo.repo}/actions/caches`);
const caches = issueResult.data['actions_caches'] || [];
return Boolean(caches.find(cache => cache['key'] === cacheKey));
const cachesResult = yield client.rest.actions.getActionsCacheList({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
key: cacheKey, // prefix matching
});
const caches = cachesResult.data['actions_caches'] || [];
return caches.some(cache => cache['key'] === cacheKey);
}
catch (error) {
core.debug(`Error checking if cache exist: ${error.message}`);
Expand All @@ -1631,8 +1635,11 @@ const resetCacheWithOctokit = (cacheKey) => __awaiter(void 0, void 0, void 0, fu
const client = getOctokitClient();
core.debug(`remove cache "${cacheKey}"`);
try {
// TODO: replace with client.rest.
yield client.request(`DELETE /repos/${github_1.context.repo.owner}/${github_1.context.repo.repo}/actions/caches?key=${cacheKey}`);
yield client.rest.actions.deleteActionsCacheByKey({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
key: cacheKey,
});
}
catch (error) {
if (error.status) {
Expand Down
21 changes: 12 additions & 9 deletions src/classes/state/state-cache-storage.ts
Expand Up @@ -33,12 +33,14 @@ const getOctokitClient = () => {
const checkIfCacheExists = async (cacheKey: string): Promise<boolean> => {
const client = getOctokitClient();
try {
const issueResult = await client.request(
`/repos/${context.repo.owner}/${context.repo.repo}/actions/caches`
);
const cachesResult = await client.rest.actions.getActionsCacheList({
owner: context.repo.owner,
repo: context.repo.repo,
key: cacheKey, // prefix matching
});
const caches: Array<{key?: string}> =
issueResult.data['actions_caches'] || [];
return Boolean(caches.find(cache => cache['key'] === cacheKey));
cachesResult.data['actions_caches'] || [];
return caches.some(cache => cache['key'] === cacheKey);
} catch (error) {
core.debug(`Error checking if cache exist: ${error.message}`);
}
Expand All @@ -48,10 +50,11 @@ const resetCacheWithOctokit = async (cacheKey: string): Promise<void> => {
const client = getOctokitClient();
core.debug(`remove cache "${cacheKey}"`);
try {
// TODO: replace with client.rest.
await client.request(
`DELETE /repos/${context.repo.owner}/${context.repo.repo}/actions/caches?key=${cacheKey}`
);
await client.rest.actions.deleteActionsCacheByKey({
owner: context.repo.owner,
repo: context.repo.repo,
key: cacheKey,
});
} catch (error) {
if (error.status) {
core.warning(
Expand Down

0 comments on commit 0980a21

Please sign in to comment.