Procházet zdrojové kódy

fix(action): enhance ccache setup and cache management in build process

TheWildJames před 4 měsíci
rodič
revize
d4c3f19db7

+ 20 - 3
.github/actions/build-kernel/action.yml

@@ -8,20 +8,29 @@ runs:
       working-directory: ${{ github.workspace }}/kernel
       run: |
         set -euo pipefail
-        export CCACHE_DIR="$GITHUB_WORKSPACE/kernel/.ccache"
-        export PATH="/usr/lib/ccache:$PATH"
+        # Install ccache with ECS by cctv18
+        echo "Install ccache with ECS"
+        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
+        sudo cp -f ./ccache /usr/bin/ccache
+        sudo chmod +x /usr/bin/ccache
+        rm -f ./ccache
+        echo "/usr/lib/ccache" >> $GITHUB_PATH
+        export CCACHE_DIR="$GITHUB_WORKSPACE/.ccache"
+        export LDCACHE_DIR="${{ github.workspace }}/.ld_cache"
         export CC="ccache clang"
         export CXX="ccache clang++"
+        export HOSTCC="ccache clang"
+        export HOSTCXX="ccache clang++"
         export CCACHE_MAXSIZE=10G
         export CCACHE_COMPILERCHECK=content
         export CCACHE_BASEDIR="$GITHUB_WORKSPACE"
         export CCACHE_NOHASHDIR=true
-        export CCACHE_IGNOREOPTIONS=--sysroot*
         export CCACHE_COMPRESSION=true
         export CCACHE_COMPRESSION_LEVEL=3
         export CCACHE_DIRECT=true
         export CCACHE_FILE_CLONE=true
         export CCACHE_INODE_CACHE=true
+        CCACHE_IS_KERNEL_COMPILING=true
         export CCACHE_UMASK=002
         export CCACHE_SLOPPINESS="file_macro,time_macros,include_file_mtime,include_file_ctime,pch_defines,system_headers,locale"
         if ccache --help 2>&1 | grep -q 'depend_mode'; then
@@ -29,9 +38,17 @@ runs:
         fi
         echo "✅ ccache environment variables set"
         ccache -p
+
         if [ -f "build/build.sh" ]; then
           SKIP_MRPROPER=1 LTO=thin SKIP_EXT_MODULES=1 SKIP_CP_KERNEL_HDR=1 GKI_DEFCONFIG_FRAGMENT="$GITHUB_WORKSPACE/wild_gki.fragment" BUILD_CONFIG=common/build.config.gki.aarch64 CC="$CC" CXX="$CXX" build/build.sh
         else
           cp "$GITHUB_WORKSPACE/wild_gki.fragment" common/arch/arm64/configs/wild_gki.fragment
           tools/bazel build --config=release --notrim --defconfig_fragment=//common:arch/arm64/configs/wild_gki.fragment --cache_dir=$GITHUB_WORKSPACE/kernel/.cache/bazel //common:kernel_aarch64
         fi
+        
+        echo "Clear Temporary cache files..."
+        ccache -c
+        
+        echo "Perform cache eviction!"
+        # 3h = 10800s using seconds to support older ccache
+        ccache --evict-older-than 10800s

+ 52 - 0
.github/actions/save-cache/action.yml

@@ -0,0 +1,52 @@
+name: 'Build Kernel'
+description: 'Builds kernel using legacy build.sh or Bazel (kleaf)'
+
+runs:
+  using: composite
+  steps:
+    - shell: bash
+      working-directory: ${{ github.workspace }}/kernel
+      run: |
+        set -euo pipefail
+        # Install ccache with ECS by cctv18
+        echo "Install ccache with ECS"
+        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
+        sudo cp -f ./ccache /usr/bin/ccache
+        sudo chmod +x /usr/bin/ccache
+        rm -f ./ccache
+        echo "/usr/lib/ccache" >> $GITHUB_PATH
+        export CCACHE_DIR="$GITHUB_WORKSPACE/.ccache"
+        export LDCACHE_DIR="${{ github.workspace }}/.ld_cache"
+        export CC="ccache clang"
+        export CXX="ccache clang++"
+        export HOSTCC="ccache clang"
+        export HOSTCXX="ccache clang++"
+        export CCACHE_MAXSIZE=10G
+        export CCACHE_COMPILERCHECK=content
+        export CCACHE_BASEDIR="$GITHUB_WORKSPACE"
+        export CCACHE_NOHASHDIR=true
+        export CCACHE_COMPRESSION=true
+        export CCACHE_COMPRESSION_LEVEL=3
+        export CCACHE_DIRECT=true
+        export CCACHE_FILE_CLONE=true
+        export CCACHE_INODE_CACHE=true
+        CCACHE_IS_KERNEL_COMPILING=true
+        export CCACHE_UMASK=002
+        export CCACHE_SLOPPINESS="file_macro,time_macros,include_file_mtime,include_file_ctime,pch_defines,system_headers,locale"
+        if ccache --help 2>&1 | grep -q 'depend_mode'; then
+          export CCACHE_DEPEND=true
+        fi
+        echo "✅ ccache environment variables set"
+        ccache -p
+        if [ -f "build/build.sh" ]; then
+          SKIP_MRPROPER=1 LTO=thin SKIP_EXT_MODULES=1 SKIP_CP_KERNEL_HDR=1 GKI_DEFCONFIG_FRAGMENT="$GITHUB_WORKSPACE/wild_gki.fragment" BUILD_CONFIG=common/build.config.gki.aarch64 CC="$CC" CXX="$CXX" build/build.sh
+        else
+          cp "$GITHUB_WORKSPACE/wild_gki.fragment" common/arch/arm64/configs/wild_gki.fragment
+          tools/bazel build --config=release --notrim --defconfig_fragment=//common:arch/arm64/configs/wild_gki.fragment --cache_dir=$GITHUB_WORKSPACE/kernel/.cache/bazel //common:kernel_aarch64
+        fi
+        echo "Clear Temporary cache files..."
+        ccache -c
+        
+        echo "Perform cache eviction!"
+        # 3h = 10800s using seconds to support older ccache
+        ccache --evict-older-than 10800s

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

@@ -188,13 +188,22 @@ jobs:
 
 
     - name: Restore build caches (ccache, Bazel)
-      uses: actions/cache@v4
+      uses: ./action-source/.github/actions/cache/restore
       with:
-        path: |
-          kernel/.ccache
-          kernel/bazel-*
-          kernel/.cache/bazel
-        key: buildcache-${{ inputs.kernel_version }}
+        cache_path: ${{ github.workspace }}/.ccache
+        cache_key: buildcache-${{ inputs.kernel_version }}
+        cache_bucket: "ccache-cache"
+        compression_level: 9
+        restore-keys: |
+          buildcache-
+
+    - name: Restore build caches (ccache, Bazel)
+      uses: ./action-source/.github/actions/cache/restore
+      with:
+        cache_path: ${{ github.workspace }}/.ld_cache
+        cache_key: buildcache-${{ inputs.kernel_version }}
+        cache_bucket: "lto-cache"
+        compression_level: 9
         restore-keys: |
           buildcache-
 
@@ -205,7 +214,7 @@ jobs:
       uses: ./.github/actions/build-kernel
 
     - name: List cache contents
-      working-directory: ${{ github.workspace }}/kernel
+      working-directory: ${{ github.workspace }}
       run: |
         echo "=== .ccache ==="
         du -sh .ccache || true
@@ -214,6 +223,22 @@ jobs:
         du -sh .cache/bazel || true
         ls -l .cache/bazel || true
 
+    - name: Save ccache cache
+      uses: ./action-source/.github/actions/cache/save
+      with:
+        cache_path: ${{ github.workspace }}/.ccache
+        cache_key: buildcache-${{ inputs.kernel_version }}
+        cache_bucket: "ccache-cache"
+        compression_level: 9
+
+    - name: Save LTO LD cache
+      uses: ./action-source/.github/actions/cache/save
+      with:
+        cache_path: ${{ github.workspace }}/.ld_cache
+        cache_key: buildcache-${{ inputs.kernel_version }}
+        cache_bucket: "lto-cache"
+        compression_level: 9
+
     - name: Create Bootimgs Folder and Build Boot Images
       uses: ./.github/actions/build-boot-images