Преглед изворни кода

Keep cache releases off latest and add cleanup action

TheWildJames пре 4 месеци
родитељ
комит
47e58aa105
2 измењених фајлова са 59 додато и 2 уклоњено
  1. 54 0
      .github/actions/cache-cleanup/action.yml
  2. 5 2
      .github/actions/cache-save/action.yml

+ 54 - 0
.github/actions/cache-cleanup/action.yml

@@ -0,0 +1,54 @@
+name: Cache Cleanup
+description: Deletes cache releases for the specified cache buckets.
+
+inputs:
+  cache_bucket:
+    description: Single release tag name to delete (use cache_buckets for multiple)
+    required: false
+    default: 'general-cache'
+  cache_buckets:
+    description: Multiline list of release tag names to delete
+    required: false
+    default: ""
+  github_token:
+    description: GitHub token for release deletion authentication
+    required: true
+  confirm:
+    description: Must be true to actually delete releases
+    required: false
+    default: false
+
+runs:
+  using: "composite"
+  steps:
+    - name: Delete Cache Releases
+      shell: bash
+      env:
+        GITHUB_TOKEN: ${{ inputs.github_token }}
+        TARGET_REPO: "${{ github.repository }}"
+      run: |
+        set -euo pipefail
+
+        if [ "${{ inputs.confirm }}" != "true" ]; then
+          echo "Cache cleanup is disabled. Re-run with confirm=true to delete releases."
+          exit 0
+        fi
+
+        BUCKETS_INPUT="${{ inputs.cache_buckets }}"
+        if [ -z "$BUCKETS_INPUT" ]; then
+          BUCKETS_INPUT="${{ inputs.cache_bucket }}"
+        fi
+
+        IFS=$'\n' read -rd '' -a BUCKETS_ARRAY <<<"$BUCKETS_INPUT" || true
+
+        for TAG_NAME in "${BUCKETS_ARRAY[@]}"; do
+          [ -z "$TAG_NAME" ] && continue
+
+          echo "Checking cache release: $TAG_NAME"
+          if gh release view "$TAG_NAME" --repo "$TARGET_REPO" >/dev/null 2>&1; then
+            echo "Deleting cache release and tag: $TAG_NAME"
+            gh release delete "$TAG_NAME" --cleanup-tag -y --repo "$TARGET_REPO"
+          else
+            echo "No cache release found for $TAG_NAME"
+          fi
+        done

+ 5 - 2
.github/actions/cache-save/action.yml

@@ -87,6 +87,7 @@ runs:
           
           if gh release view "$tag_name" --repo "$TARGET_REPO" >/dev/null 2>&1; then
             echo "Release '$tag_name' already exists. Ready for upload."
+            gh release edit "$tag_name" --latest=false --repo "$TARGET_REPO" >/dev/null 2>&1 || true
             return 0
           fi
 
@@ -94,13 +95,15 @@ runs:
             echo "Tag '$tag_name' not found. Creating backdated tag and release..."
             GIT_COMMITTER_DATE="2015-01-01T12:00:00" git tag -a "$tag_name" -m "Build Cache Storage"
             if git push origin "$tag_name" --force; then
-              gh release create "$tag_name" --title "Build Cache" --notes "Automated storage for build assets" --repo "$TARGET_REPO" || true
+              gh release create "$tag_name" --title "Build Cache" --notes "Automated storage for build assets" --latest=false --repo "$TARGET_REPO" || true
+              gh release edit "$tag_name" --latest=false --repo "$TARGET_REPO" >/dev/null 2>&1 || true
             else
               echo "Push failed, tag might have been created by a parallel job. Continuing..."
             fi
           else
             echo "Tag '$tag_name' already exists but release is missing. Creating release..."
-            gh release create "$tag_name" --title "Build Cache" --notes "Automated storage for build assets" --repo "$TARGET_REPO" || true
+            gh release create "$tag_name" --title "Build Cache" --notes "Automated storage for build assets" --latest=false --repo "$TARGET_REPO" || true
+            gh release edit "$tag_name" --latest=false --repo "$TARGET_REPO" >/dev/null 2>&1 || true
           fi
         }