|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2025 The Kubernetes Authors. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +set -o errexit |
| 18 | +set -o nounset |
| 19 | +set -o pipefail |
| 20 | + |
| 21 | +REPO_ROOT=$(git rev-parse --show-toplevel) |
| 22 | +cd "${REPO_ROOT}" |
| 23 | + |
| 24 | +# Free up disk space on GitHub Actions runners |
| 25 | +# Based on https://github.com/apache/flink/blob/02d30ace69dc18555a5085eccf70ee884e73a16e/tools/azure-pipelines/free_disk_space.sh |
| 26 | + |
| 27 | +if [[ -z "${GITHUB_ACTIONS:-}" ]]; then |
| 28 | + echo "Not running on GitHub Actions; skipping disk space cleanup (for safety)" |
| 29 | + exit 1 |
| 30 | +fi |
| 31 | + |
| 32 | +echo "==============================================================================" |
| 33 | +echo "Freeing up disk space on CI system" |
| 34 | +echo "==============================================================================" |
| 35 | + |
| 36 | +echo "Before cleanup:" |
| 37 | +echo "** 100 largest packages:" |
| 38 | +dpkg-query -Wf '${Installed-Size}\t${Status;1}\t${Package}\n' | sort -n | tail -n 100 |
| 39 | +echo "** Disk usage:" |
| 40 | +df -h |
| 41 | + |
| 42 | +echo "Removing man-db (to speed up further removals)" |
| 43 | +sudo apt-get remove -y man-db || true |
| 44 | + |
| 45 | +echo "Removing large packages" |
| 46 | +sudo apt-get remove -y '^mysql-server-.*' || true |
| 47 | +sudo apt-get remove -y '^dotnet-.*' || true |
| 48 | +sudo apt-get remove -y '^llvm-.*' '^libllvm.*' '^libclang.*' || true |
| 49 | +# Hard to remove gcc because it is a dependency for many things |
| 50 | +#sudo apt-get remove -y '^gcc-.*' '^g\+\+.*' '^gfortran-.*' '^cpp-.*' || true |
| 51 | +sudo apt-get remove -y '^openjdk.*' '^temurin-.*' ca-certificates-java || true |
| 52 | +sudo apt-get remove -y 'php.*' || true |
| 53 | +sudo apt-get remove -y '^ruby.*' || true |
| 54 | +sudo apt-get remove -y microsoft-edge-stable google-chrome-stable firefox powershell mercurial-common |
| 55 | +sudo apt-get autoremove -y |
| 56 | +sudo apt-get clean |
| 57 | + |
| 58 | +echo "Removing large directories" |
| 59 | +# deleting 15GB |
| 60 | +rm -rf /usr/share/dotnet/ |
| 61 | + |
| 62 | + |
| 63 | +echo "After cleanup:" |
| 64 | +echo "** 100 largest packages:" |
| 65 | +dpkg-query -Wf '${Installed-Size}\t${Status;1}\t${Package}\n' | sort -n | tail -n 100 |
| 66 | +echo "** Disk usage:" |
| 67 | +df -h |
0 commit comments