Эх сурвалжийг харах

fix: cache upload failures, eviction, and cpufreq build error

- cache-save: increase chunk size 250MB→1500MB, add old asset cleanup
- cache-save: unify upload timeout to 10m for all cache types
- cache-stats: add atime touch for ccache and LTO cache to prevent LRU eviction
- main.yml: add prepare-ccache job to download ccache once, shared via artifact
- build.yml: download ccache artifact before cache-setup
- cache-setup: use shared ccache artifact with direct-curl fallback
TheWildJames 2 сар өмнө
parent
commit
0048bda24e

+ 46 - 8
.github/actions/cache-save/action.yml

@@ -114,10 +114,6 @@ runs:
             local max_attempts=3
             local timeout_duration="10m"
 
-            if [ "$TAG_NAME" != "bazel-cache" ]; then
-              timeout_duration="30m"
-            fi
-
             for ((i=1; i<=max_attempts; i++)); do
               echo "  Attempt $i for $file..."
               
@@ -141,19 +137,50 @@ runs:
             return 1
           }
           
+          # Fetch existing assets to clean up stale entries
+          ASSETS_URL="https://github.com/${TARGET_REPO}/releases/expanded_assets/$TAG_NAME"
+          HTTP_RESPONSE=$(curl -sL -A "Mozilla/5.0" -w "%{http_code}" "$ASSETS_URL" -o assets.html || echo "404")
+          if [ "$HTTP_RESPONSE" -eq 200 ]; then
+            ALL_ASSETS=$(grep -oP "download/$TAG_NAME/\K[^\"' ]+" assets.html | sort || echo "")
+          else
+            ALL_ASSETS=""
+          fi
+          rm -f assets.html
+          
           chunk_size="1500M"
           split_required=false
 
-          if [ "$TAG_NAME" != "bazel-cache" ]; then
-            chunk_size="250M"
-            split_required=true
-          elif [ "$FILE_SIZE" -gt "$MAX_SIZE" ]; then
+          if [ "$FILE_SIZE" -gt "$MAX_SIZE" ]; then
             split_required=true
           fi
 
           if [ "$split_required" = "true" ]; then
             echo "⚠ Splitting into ${chunk_size} chunks..."
             split -b "$chunk_size" -a 2 "$FILENAME" "${FILENAME}.part"
+            
+            NEW_PARTS=(${FILENAME}.part*)
+            NEW_PARTS_COUNT=${#NEW_PARTS[@]}
+            
+            # Remove old single-file asset if switching to split parts
+            if echo "$ALL_ASSETS" | grep -xF "${FILENAME}" >/dev/null 2>&1; then
+              echo "Removing old single asset to make way for split parts: ${FILENAME}"
+              gh release delete-asset "$TAG_NAME" "${FILENAME}" --repo "$TARGET_REPO" -y || true
+            fi
+            
+            # Clean up excess trailing parts from previous builds
+            OLD_PARTS=$(echo "$ALL_ASSETS" | grep -F "${FILENAME}.part" || echo "")
+            if [ -n "$OLD_PARTS" ]; then
+              OLD_PARTS_COUNT=$(echo "$OLD_PARTS" | wc -l)
+              if [ "$OLD_PARTS_COUNT" -gt "$NEW_PARTS_COUNT" ]; then
+                echo "Old build had $OLD_PARTS_COUNT parts, new has $NEW_PARTS_COUNT. Cleaning up excess parts..."
+                EXT_PARTS=$(echo "$OLD_PARTS" | awk -v skip="$NEW_PARTS_COUNT" 'NR>skip')
+                for asset in $EXT_PARTS; do
+                  echo "Removing leftover trailing part: $asset"
+                  gh release delete-asset "$TAG_NAME" "$asset" --repo "$TARGET_REPO" -y || true
+                done
+              fi
+            fi
+            
             for part in "${FILENAME}".part*; do
               echo "Uploading $part..."
               if ! upload_with_retry "$part"; then
@@ -164,6 +191,17 @@ runs:
             done
             rm -rf "$FILENAME"
           else
+            # Remove old split parts if new build fits in a single file
+            OLD_PARTS=$(echo "$ALL_ASSETS" | grep -F "${FILENAME}.part" || echo "")
+            if [ -n "$OLD_PARTS" ]; then
+              echo "New build shrunk to single file. Cleaning up old split parts for ${FILENAME}..."
+              while read -r asset; do
+                [ -z "$asset" ] && continue
+                echo "Removing ghost split part: $asset"
+                gh release delete-asset "$TAG_NAME" "$asset" --repo "$TARGET_REPO" -y || true
+              done <<< "$OLD_PARTS"
+            fi
+            
             echo "Uploading $FILENAME..."
             if ! upload_with_retry "$FILENAME"; then
               echo "::error::Failed to upload $FILENAME after multiple attempts."

+ 14 - 5
.github/actions/cache-setup/action.yml

@@ -26,12 +26,21 @@ runs:
       working-directory: ${{ github.workspace }}
       run: |
         set -euo pipefail
-        # Download and install ccache
+        # Install ccache from shared artifact (downloaded once by prepare-ccache job)
         echo "Installing ccache..."
-        curl -LfsS --retry 5 --retry-delay 5 --retry-all-errors --connect-timeout 30 --tcp-fastopen -H "User-Agent: Mozilla/5.0" "https://github.com/WildKernels/kernel_patches/raw/refs/heads/main/ccache/ccache-x86-64" -o ccache || { echo "❌ Failed to download ccache"; exit 1; }
-        sudo cp -f ./ccache /usr/bin/ccache || { echo "❌ Failed to install ccache"; exit 1; }
-        sudo chmod +x /usr/bin/ccache
-        rm -f ./ccache
+        if [ -s "${{ github.workspace }}/ccache-dl/ccache" ]; then
+          sudo cp -f "${{ github.workspace }}/ccache-dl/ccache" /usr/bin/ccache || { echo "❌ Failed to install ccache"; exit 1; }
+          sudo chmod +x /usr/bin/ccache
+          rm -rf "${{ github.workspace }}/ccache-dl"
+          echo "✅ installed custom ccache from shared artifact"
+        else
+          # Fallback: download directly (prepare-ccache may have failed)
+          echo "⚠️ shared ccache artifact unavailable; downloading directly..."
+          curl -LfsS --retry 5 --retry-delay 5 --retry-all-errors --connect-timeout 30 --tcp-fastopen -H "User-Agent: Mozilla/5.0" "https://github.com/WildKernels/kernel_patches/raw/refs/heads/main/ccache/ccache-x86-64" -o ccache || { echo "❌ Failed to download ccache"; exit 1; }
+          sudo cp -f ./ccache /usr/bin/ccache || { echo "❌ Failed to install ccache"; exit 1; }
+          sudo chmod +x /usr/bin/ccache
+          rm -f ./ccache
+        fi
         
         # Verify ccache
         if ! /usr/bin/ccache --version > /dev/null 2>&1; then

+ 12 - 0
.github/actions/cache-stats/action.yml

@@ -98,6 +98,18 @@ runs:
           echo "====================="
           ccache -z || true
           echo "====================="
+          
+          # Touch all files to prevent LRU eviction of freshly restored cache
+          if [ -d /home/runner/.ccache ] && find /home/runner/.ccache -type f -print -quit 2>/dev/null | grep -q .; then
+            echo "Updating ccache atime to prevent cache eviction..."
+            find /home/runner/.ccache -type f -exec touch -t $(date -d "1 day ago" +%Y%m%d%H%M) {} +
+            echo "✅ ccache atime updated"
+          fi
+          if [ -d /home/runner/.ld_cache ] && find /home/runner/.ld_cache -type f -print -quit 2>/dev/null | grep -q .; then
+            echo "Updating LTO cache atime to prevent cache eviction..."
+            find /home/runner/.ld_cache -type f -exec touch -t $(date -d "1 day ago" +%Y%m%d%H%M) {} +
+            echo "✅ LTO cache atime updated"
+          fi
         else
           echo "Keeping ccache stats for next run"
         fi

+ 7 - 0
.github/workflows/build.yml

@@ -231,6 +231,13 @@ jobs:
         if-no-files-found: ignore
         compression-level: 9
 
+    - name: Get prebuilt ccache (downloaded once by prepare-ccache)
+      uses: actions/download-artifact@v8
+      with:
+        name: ccache-binary
+        path: ccache-dl
+      continue-on-error: true
+
     - name: 'Setup Cache and Build Environment'
       uses: ./.github/actions/cache-setup
       with:

+ 39 - 0
.github/workflows/main.yml

@@ -90,7 +90,40 @@ on:
         default: false
 
 jobs:
+  prepare-ccache:
+    name: Prepare ccache binary (download once)
+    runs-on: ubuntu-latest
+    steps:
+      - name: Download custom ccache once
+        run: |
+          set -uo pipefail
+          echo "::group::Download ccache"
+          url="https://raw.githubusercontent.com/WildKernels/kernel_patches/refs/heads/main/ccache/ccache-x86-64"
+          ok=0
+          for attempt in 1 2 3 4 5 6; do
+            if curl -LfsS --connect-timeout 30 --max-time 120 -H "User-Agent: Mozilla/5.0" "$url" -o ccache && [ -s ccache ]; then
+              ok=1; break
+            fi
+            echo "attempt $attempt failed (GitHub raw 504/throttle); backing off..."
+            sleep $(( attempt * 5 + RANDOM % 6 ))
+          done
+          if [ "$ok" = 1 ]; then
+            echo "✅ downloaded ccache once for all matrix jobs"
+          else
+            echo "::warning::custom ccache download failed; matrix jobs will fall back to the apt ccache"
+            rm -f ccache
+          fi
+          echo "::endgroup::"
+      - name: Upload ccache artifact
+        uses: actions/upload-artifact@v7
+        with:
+          name: ccache-binary
+          path: ccache
+          retention-days: 1
+          if-no-files-found: warn
+
   build-android12-5-10:
+    needs: prepare-ccache
     if: ${{ !inputs.test_release_notes && (inputs.kernel_build_version == 'All' || inputs.kernel_build_version == 'android12-5.10') }}
     uses: ./.github/workflows/prepare.yml
     with:
@@ -101,6 +134,7 @@ jobs:
     secrets: inherit
 
   build-android13-5-10:
+    needs: prepare-ccache
     if: ${{ !inputs.test_release_notes && (inputs.kernel_build_version == 'All' || inputs.kernel_build_version == 'android13-5-10') }}
     uses: ./.github/workflows/prepare.yml
     with:
@@ -111,6 +145,7 @@ jobs:
     secrets: inherit
 
   build-android13-5-15:
+    needs: prepare-ccache
     if: ${{ !inputs.test_release_notes && (inputs.kernel_build_version == 'All' || inputs.kernel_build_version == 'android13-5.15') }}
     uses: ./.github/workflows/prepare.yml
     with:
@@ -121,6 +156,7 @@ jobs:
     secrets: inherit
 
   build-android14-5-15:
+    needs: prepare-ccache
     if: ${{ !inputs.test_release_notes && (inputs.kernel_build_version == 'All' || inputs.kernel_build_version == 'android14-5-15') }}
     uses: ./.github/workflows/prepare.yml
     with:
@@ -131,6 +167,7 @@ jobs:
     secrets: inherit
 
   build-android14-6-1:
+    needs: prepare-ccache
     if: ${{ !inputs.test_release_notes && (inputs.kernel_build_version == 'All' || inputs.kernel_build_version == 'android14-6.1') }}
     uses: ./.github/workflows/prepare.yml
     with:
@@ -141,6 +178,7 @@ jobs:
     secrets: inherit
 
   build-android15-6-6:
+    needs: prepare-ccache
     if: ${{ !inputs.test_release_notes && (inputs.kernel_build_version == 'All' || inputs.kernel_build_version == 'android15-6.6') }}
     uses: ./.github/workflows/prepare.yml
     with:
@@ -151,6 +189,7 @@ jobs:
     secrets: inherit
 
   build-android16-6-12:
+    needs: prepare-ccache
     if: ${{ !inputs.test_release_notes && (inputs.kernel_build_version == 'All' || inputs.kernel_build_version == 'android16-6.12') }}
     uses: ./.github/workflows/prepare.yml
     with: