name: Clear cache on: schedule: - cron: "0 0 1 * *" # Run at midnight on the first day of every month workflow_dispatch: # Restrict permissions by default permissions: actions: write # Required for cache management jobs: clear-cache: name: Clear cache runs-on: ubuntu-latest timeout-minutes: 10 steps: - name: Clear cache uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 with: script: | console.log("Starting cache cleanup...") const caches = await github.rest.actions.getActionsCacheList({ owner: context.repo.owner, repo: context.repo.repo, }) let deletedCount = 0 for (const cache of caches.data.actions_caches) { console.log(`Deleting cache: ${cache.key} (${cache.size_in_bytes} bytes)`) try { await github.rest.actions.deleteActionsCacheById({ owner: context.repo.owner, repo: context.repo.repo, cache_id: cache.id, }) deletedCount++ } catch (error) { console.error(`Failed to delete cache ${cache.key}: ${error.message}`) } } console.log(`Cache cleanup completed. Deleted ${deletedCount} caches.`)