Compare commits

..

1 Commits
v10 ... main

Author SHA1 Message Date
itchyny
a21a081629 Fix checking state cache (fix #1136), also switch to octokit methods (#1152) 2025-12-23 16:53:06 -06:00
2 changed files with 24 additions and 14 deletions

17
dist/index.js vendored
View File

@@ -1646,9 +1646,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}`);
@@ -1659,8 +1663,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) {

View File

@@ -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}`);
}
@@ -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(