Skip to content

Commit

Permalink
fix: fix cache deletion (#39)
Browse files Browse the repository at this point in the history
Signed-off-by: Mogyuchi <[email protected]>
  • Loading branch information
Mogyuchi authored Feb 6, 2024
1 parent b844bd7 commit 22c3bda
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
28 changes: 13 additions & 15 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 17 additions & 14 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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<typeof github.getOctokit>,
repo: { owner: string; repo: string },
ref: string
): Promise<void> => {
// Get the list of cache IDs
const deleteCache = async (cache: Cache): Promise<void> => {
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)))
}

/**
Expand Down

0 comments on commit 22c3bda

Please sign in to comment.