action.yml 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. name: Cache Cleanup
  2. description: Deletes cache releases for the specified cache buckets.
  3. inputs:
  4. cache_bucket:
  5. description: Single release tag name to delete (use cache_buckets for multiple)
  6. required: false
  7. default: 'general-cache'
  8. cache_buckets:
  9. description: Multiline list of release tag names to delete
  10. required: false
  11. default: ""
  12. github_token:
  13. description: GitHub token for release deletion authentication
  14. required: true
  15. confirm:
  16. description: Must be true to actually delete releases
  17. required: false
  18. default: false
  19. runs:
  20. using: "composite"
  21. steps:
  22. - name: Delete Cache Releases
  23. shell: bash
  24. env:
  25. GITHUB_TOKEN: ${{ inputs.github_token }}
  26. TARGET_REPO: "${{ github.repository }}"
  27. run: |
  28. set -euo pipefail
  29. if [ "${{ inputs.confirm }}" != "true" ]; then
  30. echo "Cache cleanup is disabled. Re-run with confirm=true to delete releases."
  31. exit 0
  32. fi
  33. BUCKETS_INPUT="${{ inputs.cache_buckets }}"
  34. if [ -z "$BUCKETS_INPUT" ]; then
  35. BUCKETS_INPUT="${{ inputs.cache_bucket }}"
  36. fi
  37. IFS=$'\n' read -rd '' -a BUCKETS_ARRAY <<<"$BUCKETS_INPUT" || true
  38. for TAG_NAME in "${BUCKETS_ARRAY[@]}"; do
  39. [ -z "$TAG_NAME" ] && continue
  40. echo "Checking cache release: $TAG_NAME"
  41. if gh release view "$TAG_NAME" --repo "$TARGET_REPO" >/dev/null 2>&1; then
  42. echo "Deleting cache release and tag: $TAG_NAME"
  43. gh release delete "$TAG_NAME" --cleanup-tag -y --repo "$TARGET_REPO"
  44. else
  45. echo "No cache release found for $TAG_NAME"
  46. fi
  47. done