Fix checking state cache (fix #1136), also switch to octokit methods

This commit is contained in:
itchyny 2024-04-10 17:49:14 +09:00
parent 3f3b0175e8
commit 0980a21d84
2 changed files with 24 additions and 14 deletions

17
dist/index.js vendored
View File

@ -1618,9 +1618,13 @@ const getOctokitClient = () => {
const checkIfCacheExists = (cacheKey) => __awaiter(void 0, void 0, void 0, function* () { const checkIfCacheExists = (cacheKey) => __awaiter(void 0, void 0, void 0, function* () {
const client = getOctokitClient(); const client = getOctokitClient();
try { try {
const issueResult = yield client.request(`/repos/${github_1.context.repo.owner}/${github_1.context.repo.repo}/actions/caches`); const cachesResult = yield client.rest.actions.getActionsCacheList({
const caches = issueResult.data['actions_caches'] || []; owner: github_1.context.repo.owner,
return Boolean(caches.find(cache => cache['key'] === cacheKey)); 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) { catch (error) {
core.debug(`Error checking if cache exist: ${error.message}`); core.debug(`Error checking if cache exist: ${error.message}`);
@ -1631,8 +1635,11 @@ const resetCacheWithOctokit = (cacheKey) => __awaiter(void 0, void 0, void 0, fu
const client = getOctokitClient(); const client = getOctokitClient();
core.debug(`remove cache "${cacheKey}"`); core.debug(`remove cache "${cacheKey}"`);
try { try {
// TODO: replace with client.rest. yield client.rest.actions.deleteActionsCacheByKey({
yield client.request(`DELETE /repos/${github_1.context.repo.owner}/${github_1.context.repo.repo}/actions/caches?key=${cacheKey}`); owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
key: cacheKey,
});
} }
catch (error) { catch (error) {
if (error.status) { if (error.status) {

View File

@ -33,12 +33,14 @@ const getOctokitClient = () => {
const checkIfCacheExists = async (cacheKey: string): Promise<boolean> => { const checkIfCacheExists = async (cacheKey: string): Promise<boolean> => {
const client = getOctokitClient(); const client = getOctokitClient();
try { try {
const issueResult = await client.request( const cachesResult = await client.rest.actions.getActionsCacheList({
`/repos/${context.repo.owner}/${context.repo.repo}/actions/caches` owner: context.repo.owner,
); repo: context.repo.repo,
key: cacheKey, // prefix matching
});
const caches: Array<{key?: string}> = const caches: Array<{key?: string}> =
issueResult.data['actions_caches'] || []; cachesResult.data['actions_caches'] || [];
return Boolean(caches.find(cache => cache['key'] === cacheKey)); return caches.some(cache => cache['key'] === cacheKey);
} catch (error) { } catch (error) {
core.debug(`Error checking if cache exist: ${error.message}`); core.debug(`Error checking if cache exist: ${error.message}`);
} }
@ -48,10 +50,11 @@ const resetCacheWithOctokit = async (cacheKey: string): Promise<void> => {
const client = getOctokitClient(); const client = getOctokitClient();
core.debug(`remove cache "${cacheKey}"`); core.debug(`remove cache "${cacheKey}"`);
try { try {
// TODO: replace with client.rest. await client.rest.actions.deleteActionsCacheByKey({
await client.request( owner: context.repo.owner,
`DELETE /repos/${context.repo.owner}/${context.repo.repo}/actions/caches?key=${cacheKey}` repo: context.repo.repo,
); key: cacheKey,
});
} catch (error) { } catch (error) {
if (error.status) { if (error.status) {
core.warning( core.warning(