From 987faff25142d6707e6581f12e2d2330efdd4762 Mon Sep 17 00:00:00 2001 From: Mogyuchi Date: Tue, 6 Feb 2024 18:01:05 +0900 Subject: [PATCH] fix: fix cache deletion Signed-off-by: Mogyuchi --- dist/index.js | 28 +++++++++++++--------------- package.json | 1 + pnpm-lock.yaml | 4 +++- src/main.ts | 31 +++++++++++++++++-------------- 4 files changed, 34 insertions(+), 30 deletions(-) diff --git a/dist/index.js b/dist/index.js index b342cca..3506ee9 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29680,24 +29680,22 @@ const core = __importStar(__nccwpck_require__(9093)); const github = __importStar(__nccwpck_require__(5942)); const ref_1 = __nccwpck_require__(2636); const deleteRefActionsCaches = async (octokit, repo, ref) => { - // Get the list of cache IDs + const deleteCache = async (cache) => { + if (!cache.id) + return; + core.info(` - Cache with key ${cache.key}`); + await octokit.rest.actions.deleteActionsCacheById({ + ...repo, + cache_id: cache.id + }); + }; // https://github.com/octokit/plugin-paginate-rest.js#octokitpaginate - const iterator = octokit.paginate.iterator(octokit.rest.actions.getActionsCacheList, { + const caches = await octokit.paginate(octokit.rest.actions.getActionsCacheList, { ...repo, - ref + ref, + per_page: 100 }); - // https://github.com/octokit/octokit.js/tree/b831b6bce43d56b97e25a996e1b43525486d8bd3?tab=readme-ov-file#pagination - for await (const { data: cacheList } of iterator) { - for (const cache of cacheList) { - if (!cache.id) - continue; - core.info(` - Cache with key ${cache.key}`); - await octokit.rest.actions.deleteActionsCacheById({ - ...repo, - cache_id: cache.id - }); - } - } + await Promise.all(caches.map(async (cache) => deleteCache(cache))); }; /** * The main function for the action. diff --git a/package.json b/package.json index 94465e4..1d95090 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,7 @@ "valibot": "^0.27.1" }, "devDependencies": { + "@octokit/openapi-types": "^19.1.0", "@types/jest": "^29.5.12", "@types/node": "^20.11.16", "@typescript-eslint/eslint-plugin": "^6.20.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 071506e..34ad868 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,6 +16,9 @@ dependencies: version: 0.27.1 devDependencies: + '@octokit/openapi-types': + specifier: ^19.1.0 + version: 19.1.0 '@types/jest': specifier: ^29.5.12 version: 29.5.12 @@ -834,7 +837,6 @@ packages: /@octokit/openapi-types@19.1.0: resolution: {integrity: sha512-6G+ywGClliGQwRsjvqVYpklIfa7oRPA0vyhPQG/1Feh+B+wU0vGH1JiJ5T25d3g1JZYBHzR2qefLi9x8Gt+cpw==} - dev: false /@octokit/plugin-paginate-rest@9.1.5(@octokit/core@5.0.2): resolution: {integrity: sha512-WKTQXxK+bu49qzwv4qKbMMRXej1DU2gq017euWyKVudA6MldaSSQuxtz+vGbhxV4CjxpUxjZu6rM2wfc1FiWVg==} diff --git a/src/main.ts b/src/main.ts index 0f09653..b017326 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,33 +1,36 @@ import * as core from '@actions/core' import * as github from '@actions/github' import { getRef } from './ref' +import type * as types from '@octokit/openapi-types' + +type Cache = + types.components['schemas']['actions-cache-list']['actions_caches'][number] const deleteRefActionsCaches = async ( octokit: ReturnType, repo: { owner: string; repo: string }, ref: string ): Promise => { - // Get the list of cache IDs + const deleteCache = async (cache: Cache): Promise => { + if (!cache.id) return + core.info(` - Cache with key ${cache.key}`) + await octokit.rest.actions.deleteActionsCacheById({ + ...repo, + cache_id: cache.id + }) + } + // https://github.com/octokit/plugin-paginate-rest.js#octokitpaginate - const iterator = octokit.paginate.iterator( + const caches = await octokit.paginate( octokit.rest.actions.getActionsCacheList, { ...repo, - ref + ref, + per_page: 100 } ) - // https://github.com/octokit/octokit.js/tree/b831b6bce43d56b97e25a996e1b43525486d8bd3?tab=readme-ov-file#pagination - for await (const { data: cacheList } of iterator) { - for (const cache of cacheList) { - if (!cache.id) continue - core.info(` - Cache with key ${cache.key}`) - await octokit.rest.actions.deleteActionsCacheById({ - ...repo, - cache_id: cache.id - }) - } - } + await Promise.all(caches.map(async cache => deleteCache(cache))) } /**