This is an automated email from the ASF dual-hosted git repository.

yuluo-yx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 85ee8bef93 ci: skip disk cleanup when space is sufficient (#7349)
85ee8bef93 is described below

commit 85ee8bef931e17143847d82a076b2c8be76b58d8
Author: aias00 <[email protected]>
AuthorDate: Mon Sep 28 06:22:52 2026 -0700

    ci: skip disk cleanup when space is sufficient (#7349)
---
 .github/scripts/free-disk-space-test.sh | 40 ++++++++++++++++++++
 .github/scripts/free-disk-space.sh      | 67 +++++++++++++++++++++++++++++++++
 .github/workflows/e2e-k8s.yml           | 33 ++++------------
 .github/workflows/k8s-examples-http.yml | 13 ++-----
 4 files changed, 119 insertions(+), 34 deletions(-)

diff --git a/.github/scripts/free-disk-space-test.sh 
b/.github/scripts/free-disk-space-test.sh
new file mode 100644
index 0000000000..ba2b5beb53
--- /dev/null
+++ b/.github/scripts/free-disk-space-test.sh
@@ -0,0 +1,40 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -euo pipefail
+
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+readonly SCRIPT_DIR
+readonly CLEANUP_SCRIPT="${SCRIPT_DIR}/free-disk-space.sh"
+
+skip_output="$(AVAILABLE_DISK_KB=31457280 MIN_FREE_DISK_KB=20971520 
DRY_RUN=true bash "${CLEANUP_SCRIPT}")"
+if [[ "${skip_output}" != *"Skipping disk cleanup"* ]]; then
+  echo "Expected cleanup to be skipped when 30 GiB is available" >&2
+  exit 1
+fi
+
+cleanup_output="$(AVAILABLE_DISK_KB=10485760 MIN_FREE_DISK_KB=20971520 
DRY_RUN=true bash "${CLEANUP_SCRIPT}")"
+if [[ "${cleanup_output}" != *"Disk cleanup required"* ]]; then
+  echo "Expected cleanup to be required when only 10 GiB is available" >&2
+  exit 1
+fi
+if [[ "${cleanup_output}" != *"DRY_RUN enabled"* ]]; then
+  echo "Expected dry-run cleanup to avoid destructive commands" >&2
+  exit 1
+fi
+
+echo "free disk space tests passed"
diff --git a/.github/scripts/free-disk-space.sh 
b/.github/scripts/free-disk-space.sh
new file mode 100644
index 0000000000..6778f1796a
--- /dev/null
+++ b/.github/scripts/free-disk-space.sh
@@ -0,0 +1,67 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -euo pipefail
+
+readonly MIN_FREE_DISK_KB="${MIN_FREE_DISK_KB:-20971520}"
+readonly DRY_RUN="${DRY_RUN:-false}"
+
+if [[ -n "${AVAILABLE_DISK_KB:-}" ]]; then
+  available_disk_kb="${AVAILABLE_DISK_KB}"
+else
+  available_disk_kb="$(df --output=avail -k / | tail -n 1 | tr -d ' ')"
+fi
+readonly available_disk_kb
+
+if [[ ! "${MIN_FREE_DISK_KB}" =~ ^[0-9]+$ || ! "${available_disk_kb}" =~ 
^[0-9]+$ ]]; then
+  echo "Disk thresholds must be integer values in KiB" >&2
+  exit 1
+fi
+
+echo "Available disk: ${available_disk_kb} KiB; required: ${MIN_FREE_DISK_KB} 
KiB"
+if ((available_disk_kb >= MIN_FREE_DISK_KB)); then
+  echo "Skipping disk cleanup because sufficient space is available"
+  exit 0
+fi
+
+echo "Disk cleanup required because available space is below the threshold"
+if [[ "${DRY_RUN}" == "true" ]]; then
+  echo "DRY_RUN enabled; cleanup commands were not executed"
+  exit 0
+fi
+
+df --human-readable
+sudo apt clean
+while IFS= read -r image; do
+  [[ -n "${image}" ]] || continue
+  docker rmi "${image}" || true
+done < <(docker image ls --all --quiet)
+
+case "${AGENT_TOOLSDIRECTORY:-}" in
+  /opt/hostedtoolcache|/opt/hostedtoolcache/*)
+    sudo rm -rf -- "${AGENT_TOOLSDIRECTORY}"
+    ;;
+  "")
+    echo "AGENT_TOOLSDIRECTORY is not set; skipping tool cache cleanup"
+    ;;
+  *)
+    echo "Refusing to remove unexpected AGENT_TOOLSDIRECTORY: 
${AGENT_TOOLSDIRECTORY}" >&2
+    exit 1
+    ;;
+esac
+
+df --human-readable
diff --git a/.github/workflows/e2e-k8s.yml b/.github/workflows/e2e-k8s.yml
index fe0b0b2941..0b41a75c07 100644
--- a/.github/workflows/e2e-k8s.yml
+++ b/.github/workflows/e2e-k8s.yml
@@ -81,6 +81,8 @@ jobs:
       - uses: actions/checkout@v3
         with:
           submodules: true
+      - name: Test conditional disk cleanup
+        run: bash .github/scripts/free-disk-space-test.sh
       - uses: ./actions/paths-filter
         id: filter
         with:
@@ -120,15 +122,8 @@ jobs:
       - uses: actions/checkout@v3
         with:
           submodules: true
-      - name: Free disk space
-        run: |
-          df --human-readable
-          sudo apt clean
-          for image in $(docker image ls --all --quiet); do
-            docker rmi $image
-          done
-          rm --recursive --force "$AGENT_TOOLSDIRECTORY"
-          df --human-readable
+      - name: Free disk space when needed
+        run: bash .github/scripts/free-disk-space.sh
 
       - name: Set up JDK 17 for Building ShenYu
         uses: ./actions/setup-java-with-retry
@@ -225,15 +220,9 @@ jobs:
         with:
           submodules: true
 
-      - name: Free disk space
+      - name: Free disk space when needed
         run: |
-          df --human-readable
-          sudo apt clean
-          for image in $(docker image ls --all --quiet); do
-            docker rmi $image
-          done
-          rm --recursive --force "$AGENT_TOOLSDIRECTORY"
-          df --human-readable
+          bash .github/scripts/free-disk-space.sh
           rm -rf /tmp/shenyu
           mkdir -p /tmp/shenyu
 
@@ -301,15 +290,9 @@ jobs:
         with:
           submodules: true
 
-      - name: Free disk space
+      - name: Free disk space when needed
         run: |
-          df --human-readable
-          sudo apt clean
-          for image in $(docker image ls --all --quiet); do
-            docker rmi $image
-          done
-          rm --recursive --force "$AGENT_TOOLSDIRECTORY"
-          df --human-readable
+          bash .github/scripts/free-disk-space.sh
           rm -rf /tmp/shenyu
           mkdir -p /tmp/shenyu
 
diff --git a/.github/workflows/k8s-examples-http.yml 
b/.github/workflows/k8s-examples-http.yml
index e02f5b9fa7..90a131f3f6 100644
--- a/.github/workflows/k8s-examples-http.yml
+++ b/.github/workflows/k8s-examples-http.yml
@@ -75,6 +75,8 @@ jobs:
       - uses: actions/checkout@v3
         with:
           submodules: true
+      - name: Test conditional disk cleanup
+        run: bash .github/scripts/free-disk-space-test.sh
       - uses: ./actions/paths-filter
         id: filter
         with:
@@ -103,16 +105,9 @@ jobs:
           CHANGED_FILES_JSON: ${{ steps.filter.outputs['k8s-examples_files'] }}
           CI_CASE_MODE: k8s-examples-http
         run: bash .github/scripts/resolve-test-case-matrix.sh
-      - name: Free disk space
+      - name: Free disk space when needed
         if: steps.cases.outputs.run_k8s_examples == 'true'
-        run: |
-          df --human-readable
-          sudo apt clean
-          for image in $(docker image ls --all --quiet); do
-            docker rmi $image
-          done
-          rm --recursive --force "$AGENT_TOOLSDIRECTORY"
-          df --human-readable
+        run: bash .github/scripts/free-disk-space.sh
       - name: Install k8s
         if: steps.cases.outputs.run_k8s_examples == 'true'
         run: |

Reply via email to