Skip to content

Cache Cleanup

Cache Cleanup #11

Workflow file for this run

name: Cache Cleanup
on:
schedule:
# Run weekly on Sundays at 3 AM UTC
- cron: '0 3 * * 0'
workflow_dispatch:
jobs:
cleanup:
name: Clean up old caches
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Clean up old caches
run: |
echo "Cache cleanup would be performed here"
echo "GitHub automatically manages cache cleanup, but this workflow"
echo "can be extended to perform custom cleanup tasks if needed"
- name: Clean up old artifacts
uses: actions/github-script@v7
with:
script: |
const { data: artifacts } = await github.rest.actions.listArtifactsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100
});
const cutoffDate = new Date();
cutoffDate.setDate(cutoffDate.getDate() - 30); // Keep artifacts for 30 days
for (const artifact of artifacts.artifacts) {
const createdAt = new Date(artifact.created_at);
if (createdAt < cutoffDate) {
console.log(`Deleting artifact: ${artifact.name} (created: ${artifact.created_at})`);
try {
await github.rest.actions.deleteArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: artifact.id
});
} catch (error) {
console.log(`Failed to delete artifact ${artifact.name}: ${error.message}`);
}
}
}