Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix cache deletion #39

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading