Skip to content
Open
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
37 changes: 37 additions & 0 deletions .github/workflows/cleanup-pr-caches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Cleanup caches for closed PRs

on:
pull_request:
types:
- closed

permissions:
actions: write
contents: read

jobs:
cleanup:
name: Delete caches for the closed PR
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const ref = `refs/pull/${context.payload.pull_request.number}/merge`;
console.log(`Listing caches for ref: ${ref}`);
const { data } = await github.rest.actions.getActionsCacheList({
owner: context.repo.owner,
repo: context.repo.repo,
ref,
});
console.log(`Found ${data.actions_caches.length} cache(s) to delete.`);
for (const cache of data.actions_caches) {
console.log(`Deleting cache id=${cache.id} key=${cache.key}`);
await github.rest.actions.deleteActionsCacheById({
owner: context.repo.owner,
repo: context.repo.repo,
cache_id: cache.id,
});
}
console.log('Cleanup finished.');
Loading