Przeglądaj źródła

Fix cache restore split extraction and cache stats helper scope

TheWildJames 4 miesięcy temu
rodzic
commit
bfe62fc00a

+ 12 - 8
.github/actions/cache-restore/action.yml

@@ -114,7 +114,7 @@ runs:
           BASE_URL="https://github.com/${TARGET_REPO}/releases/download/$TAG_NAME"
           ASSETS_URL="https://github.com/${TARGET_REPO}/releases/expanded_assets/$TAG_NAME"
           
-          echo "::group:: [$((idx+1))/$${#PATHS_ARRAY[@]}] Cache: $CACHE_BUCKET - Fetching Asset List"
+          echo "::group:: [$((idx+1))/${#PATHS_ARRAY[@]}] Cache: $CACHE_BUCKET - Fetching Asset List"
           HTTP_RESPONSE=$(curl -sL -A "Mozilla/5.0" -w "%{http_code}" "$ASSETS_URL" -o assets.html || echo "404")
           
           if [ "$HTTP_RESPONSE" -eq 200 ]; then
@@ -139,7 +139,7 @@ runs:
           FOUND=false
           while read -r KEY; do
             [ -z "$KEY" ] && continue
-            echo "::group:: [$((idx+1))/$${#PATHS_ARRAY[@]}] Searching Prefix: $KEY"
+            echo "::group:: [$((idx+1))/${#PATHS_ARRAY[@]}] Searching Prefix: $KEY"
             
             MATCH=$(echo "$ALL_ASSETS" | grep "^cache-$KEY" | sort -r | head -n 1 || true)
             
@@ -159,7 +159,7 @@ runs:
             echo "✅ Hit! Restoring $BASE_FILENAME$EXT"
             echo "::endgroup::"
             
-            echo "::group:: [$((idx+1))/$${#PATHS_ARRAY[@]}] Downloading Cache"
+            echo "::group:: [$((idx+1))/${#PATHS_ARRAY[@]}] Downloading Cache"
             
             download_asset() {
               local filename="$1"
@@ -199,20 +199,24 @@ runs:
             fi
             echo "::endgroup::"
             
-            echo "::group:: [$((idx+1))/$${#PATHS_ARRAY[@]}] Extracting Cache"
+            echo "::group:: [$((idx+1))/${#PATHS_ARRAY[@]}] Extracting Cache"
             mkdir -p "$CACHE_PATH"
             FINAL_ARCHIVE="$BASE_FILENAME$EXT"
             EXTRACT_DIR="$(dirname "$CACHE_PATH")"
             
             if [ "$IS_SPLIT" = "true" ]; then
-              PARTS=$(ls "$FINAL_ARCHIVE.part"* | sort)
+              mapfile -t PARTS_ARRAY < <(printf '%s\n' "$FINAL_ARCHIVE".part* | sort)
+              if [ ${#PARTS_ARRAY[@]} -eq 0 ] || [ ! -e "${PARTS_ARRAY[0]}" ]; then
+                echo "::error::Split archive parts not found for $FINAL_ARCHIVE"
+                exit 1
+              fi
               if [ "$COMPRESSED" = "true" ]; then
                 # Extract quietly (no verbose listing)
-                cat $PARTS | tar -I "zstd -d -T0" -xf - -C "$EXTRACT_DIR"
+                cat "${PARTS_ARRAY[@]}" | tar -I "zstd -d -T0" -xf - -C "$EXTRACT_DIR"
               else
-                cat $PARTS | tar -xf - -C "$EXTRACT_DIR"
+                cat "${PARTS_ARRAY[@]}" | tar -xf - -C "$EXTRACT_DIR"
               fi
-              rm -f $PARTS
+              rm -f "${PARTS_ARRAY[@]}"
             else
               if [ "$COMPRESSED" = "true" ]; then
                 tar -I "zstd -d -T0" -xf "$FINAL_ARCHIVE" -C "$EXTRACT_DIR"

+ 39 - 24
.github/actions/cache-stats/action.yml

@@ -10,6 +10,39 @@ inputs:
 runs:
   using: 'composite'
   steps:
+    - name: Define cache summary helper
+      shell: bash
+      working-directory: ${{ github.workspace }}
+      run: |
+        set -euo pipefail
+        cat > /tmp/cache_summary.sh <<'EOF'
+        summarize_dir() {
+          local path="$1"
+          local top_n=${2:-10}
+          local sub_n=${3:-5}
+          if [ ! -e "$path" ]; then
+            echo "Path $path not found"
+            return
+          fi
+          echo "---------------"
+          echo "Summary: $path"
+          du -sh "$path" || true
+          echo "Top ${top_n} entries at top level:"
+          du -h --max-depth=1 "$path" 2>/dev/null | sort -hr | head -n "$top_n" || true
+          echo "Showing up to ${sub_n} entries one level deeper for the largest top-level items:"
+          while read -r line; do
+            entry_path=$(echo "$line" | awk '{print $2}')
+            [ -z "$entry_path" ] && continue
+            if [ "$entry_path" = "$path" ]; then
+              continue
+            fi
+            echo "-> $entry_path :"
+            du -h --max-depth=1 "$entry_path" 2>/dev/null | sort -hr | head -n "$sub_n" || true
+          done < <(du -h --max-depth=1 "$path" 2>/dev/null | sort -hr | head -n "$top_n")
+          echo "---------------"
+        }
+        EOF
+
     - name: Show ccache Stats
       shell: bash
       working-directory: ${{ github.workspace }}
@@ -74,30 +107,8 @@ runs:
       working-directory: ${{ github.workspace }}
       run: |
         set -euo pipefail
-        summarize_dir() {
-          local path="$1"
-          local top_n=${2:-10}
-          local sub_n=${3:-5}
-          if [ ! -e "$path" ]; then
-            echo "Path $path not found"
-            return
-          fi
-          echo "---------------"
-          echo "Summary: $path"
-          du -sh "$path" || true
-          echo "Top ${top_n} entries at top level:"
-          du -h --max-depth=1 "$path" 2>/dev/null | sort -hr | head -n $top_n || true
-          echo "\nShowing up to ${sub_n} entries one level deeper for the largest top-level items:"
-          while read -r size name; do
-            # skip the root entry which matches the path itself
-            if [ "${name%/}" = "${path%/}" ]; then
-              continue
-            fi
-            echo "-> $name :"
-            du -h --max-depth=1 "$name" 2>/dev/null | sort -hr | head -n $sub_n || true
-          done < <(du -h --max-depth=1 "$path" 2>/dev/null | sort -hr | head -n $top_n)
-          echo "---------------"
-        }
+        # shellcheck disable=SC1091
+        source /tmp/cache_summary.sh
 
         echo "==============="
         echo "=== .ccache ==="
@@ -109,6 +120,8 @@ runs:
       working-directory: ${{ github.workspace }}
       run: |
         set -euo pipefail
+        # shellcheck disable=SC1091
+        source /tmp/cache_summary.sh
         echo "===================="
         echo "=== .cache/bazel ==="
         echo "===================="
@@ -119,6 +132,8 @@ runs:
       working-directory: ${{ github.workspace }}
       run: |
         set -euo pipefail
+        # shellcheck disable=SC1091
+        source /tmp/cache_summary.sh
         echo "================="
         echo "=== .ld_cache ==="
         echo "================="