Parcourir la source

feat(action): add disk cleanup action to free up disk space

Co-authored-by: Copilot <copilot@github.com>
TheWildJames il y a 4 mois
Parent
commit
251264726b

+ 59 - 0
.github/actions/disk-cleanup/action.yml

@@ -0,0 +1,59 @@
+name: 'Disk Cleanup'
+description: 'Free up disk space by removing unnecessary software and files.'
+runs:
+  using: 'composite'
+  steps:
+    - name: Disk Cleanup by Deleting files
+      shell: bash
+      run: |
+        # Disk Cleanup by Deleting files
+        echo "::group::Disk Cleanup by Deleting files"
+        
+        echo "Instant relocation of unnecessary software..."
+        mkdir -p .background_trash/{1..18}
+        
+        safe_mv() {
+          if [ -e "$1" ]; then
+            sudo mv "$1" "$2"
+          fi
+        }
+        export -f safe_mv
+        
+        safe_mv /usr/share/dotnet ./.background_trash/1 &
+        safe_mv /usr/local/lib/android ./.background_trash/2 &
+        safe_mv /opt/ghc ./.background_trash/3 &
+        safe_mv /opt/hostedtoolcache/CodeQL ./.background_trash/4 &
+        safe_mv /usr/local/aws-sam-cli ./.background_trash/5 &
+        safe_mv /usr/local/share/chromium ./.background_trash/6 &
+        safe_mv /usr/local/share/powershell ./.background_trash/7 &
+        safe_mv /usr/local/lib/heroku ./.background_trash/8 &
+        safe_mv /usr/local/lib/node_modules ./.background_trash/9 &
+        safe_mv /opt/az ./.background_trash/10 &
+        safe_mv /opt/microsoft/powershell ./.background_trash/11 &
+        safe_mv /opt/hostedtoolcache/go ./.background_trash/12 &
+        safe_mv /opt/hostedtoolcache/PyPy ./.background_trash/13 &
+        safe_mv /opt/hostedtoolcache/node ./.background_trash/14 &
+        
+        sudo bash -c 'mv /usr/local/bin/aliyun /usr/local/bin/azcopy /usr/local/bin/bicep /usr/local/bin/cmake-gui /usr/local/bin/cpack /usr/local/bin/helm \
+        /usr/local/bin/hub /usr/local/bin/kubectl /usr/local/bin/minikube /usr/local/bin/node /usr/local/bin/packer /usr/local/bin/sam \
+        /usr/local/bin/stack /usr/local/bin/terraform /usr/local/bin/oc ./.background_trash/15 2>/dev/null || true' &
+        
+        sudo bash -c 'mv /usr/local/julia* ./.background_trash/16 2>/dev/null || true' &
+        sudo bash -c 'mv /usr/local/bin/pulumi* ./.background_trash/17 2>/dev/null || true' &
+        wait
+        
+        echo "Relocation complete."
+        echo "Launching background purge..."
+        (
+          sudo nice -n 19 ionice -c 3 rm -rf ./.background_trash
+          sudo apt-get purge -y firefox google-chrome-stable microsoft-edge-stable > /dev/null 2>&1 || true
+          sudo apt-get autoremove -y > /dev/null 2>&1 || true
+          sudo apt-get clean > /dev/null 2>&1 || true
+          if command -v docker >/dev/null 2>&1; then
+            docker rmi $(docker images -q) 2>/dev/null || true
+          fi
+        ) > /dev/null 2>&1 &
+        
+        disown
+        
+        echo "::endgroup::"

+ 31 - 31
.github/actions/download-kernel/action.yml

@@ -60,37 +60,37 @@ runs:
         NPROC = int(subprocess.check_output("nproc", shell=True).strip())
 
         def sync_project(task):
-        name, path, url, strip, rev, linkfiles, copyfiles = task
-        if path not in ["./", "."]:
-          os.makedirs(path, exist_ok=True)
-        print(f"Syncing: {name} -> {path}")
-        try:
-          aria_cmd = f"aria2c -x16 -s16 -k1M -j5 --file-allocation=none -o {name}.tar.gz '{url}'"
-          subprocess.run(aria_cmd, shell=True, check=True)
-          tar_cmd = f"tar -I 'pigz -p {NPROC} -b 256' -x --record-size=1M -C {path} {strip} -f {name}.tar.gz"
-          subprocess.run(tar_cmd, shell=True, check=True)
-          os.remove(f"{name}.tar.gz")
-          # Handle linkfiles and copyfiles
-          top_dir = os.getcwd()
-          for src_rel, dest_rel in linkfiles:
-            src_path = os.path.join(top_dir, path, src_rel)
-            dest_path = os.path.join(top_dir, dest_rel)
-            os.makedirs(os.path.dirname(dest_path), exist_ok=True)
-            if os.path.lexists(dest_path): os.remove(dest_path)
-            rel_target = os.path.relpath(src_path, os.path.dirname(dest_path))
-            os.symlink(rel_target, dest_path)
-            print(f"  [Link] {dest_rel} -> {src_rel}")
-          for src_rel, dest_rel in copyfiles:
-            src_path = os.path.join(top_dir, path, src_rel)
-            dest_path = os.path.join(top_dir, dest_rel)
-            os.makedirs(os.path.dirname(dest_path), exist_ok=True)
-            shutil.copy2(src_path, dest_path)
-            print(f"  [Copy] {dest_rel} from {src_rel}")
-          print(f"Synced {name} successfully!")
-          return True
-        except Exception as e:
-          print(f"Failed to sync {name}: {e}")
-          return False
+            name, path, url, strip, rev, linkfiles, copyfiles = task
+            if path not in ["./", "."]:
+                os.makedirs(path, exist_ok=True)
+            print(f"Syncing: {name} -> {path}")
+            try:
+                aria_cmd = f"aria2c -x16 -s16 -k1M -j5 --file-allocation=none -o {name}.tar.gz '{url}'"
+                subprocess.run(aria_cmd, shell=True, check=True)
+                tar_cmd = f"tar -I 'pigz -p {NPROC} -b 256' -x --record-size=1M -C {path} {strip} -f {name}.tar.gz"
+                subprocess.run(tar_cmd, shell=True, check=True)
+                os.remove(f"{name}.tar.gz")
+                # Handle linkfiles and copyfiles
+                top_dir = os.getcwd()
+                for src_rel, dest_rel in linkfiles:
+                    src_path = os.path.join(top_dir, path, src_rel)
+                    dest_path = os.path.join(top_dir, dest_rel)
+                    os.makedirs(os.path.dirname(dest_path), exist_ok=True)
+                    if os.path.lexists(dest_path): os.remove(dest_path)
+                    rel_target = os.path.relpath(src_path, os.path.dirname(dest_path))
+                    os.symlink(rel_target, dest_path)
+                    print(f"  [Link] {dest_rel} -> {src_rel}")
+                for src_rel, dest_rel in copyfiles:
+                    src_path = os.path.join(top_dir, path, src_rel)
+                    dest_path = os.path.join(top_dir, dest_rel)
+                    os.makedirs(os.path.dirname(dest_path), exist_ok=True)
+                    shutil.copy2(src_path, dest_path)
+                    print(f"  [Copy] {dest_rel} from {src_rel}")
+                print(f"Synced {name} successfully!")
+                return True
+            except Exception as e:
+                print(f"Failed to sync {name}: {e}")
+                return False
 
         with open('manifest.xml', 'r') as f:
           manifest_content = f.read()

+ 5 - 1
.github/workflows/build.yml

@@ -45,7 +45,7 @@ jobs:
         kernel_version: ${{ inputs.kernel_version }}
 
     - name: Free Disk Space
-      if: true
+      if: false
       uses: endersonmenezes/free-disk-space@v3  # Use @main for latest, @v3 for stable
       with:
         remove_android: true
@@ -59,6 +59,10 @@ jobs:
         rmz_version: "3.1.1"  # Required when rm_cmd is 'rmz'
         testing: false
 
+    - name: Disk Cleanup by Deleting files
+      if: true
+      uses: ./.github/actions/disk-cleanup
+
     - name: Setup more Swap (for LTO)
       uses: thejerrybao/setup-swap-space@v1   # or pierotofy/set-swap-space
       with: