Cache Cleanup #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}`); | |
| } | |
| } | |
| } |