11#! /bin/bash
22set -euo pipefail
33
4- # Free disk space on Linux GitHub action runners
4+ # Free disk space on Linux GitHub action runners.
55# Script inspired by https://github.com/jlumbroso/free-disk-space
66
77# When updating to a new ubuntu version (e.g. from ubuntu-24.04):
88# - Check that there are no docker images preinstalled with `docker image ls`
99# - Check that there are no big packages preinstalled that we aren't using
1010# - Check that all directores we are removing are still present (look at the warnings)
1111
12- # print a line of the specified character
12+ # Print a line of the specified character.
1313printSeparationLine () {
1414 for (( i = 0 ; i < 80 ; i++ )) ; do
1515 printf " %s" " $1 "
1616 done
1717 printf " \n"
1818}
1919
20- # compute available space
20+ # Compute available space.
2121# REF: https://unix.stackexchange.com/a/42049/60849
2222# REF: https://stackoverflow.com/a/450821/408734
2323getAvailableSpace () {
2424 df -a | awk ' NR > 1 {avail+=$4} END {print avail}'
2525}
2626
27- # make Kb human readable (assume the input is Kb)
27+ # Make Kb human readable (assume the input is Kb).
2828# REF: https://unix.stackexchange.com/a/44087/60849
2929formatByteCount () {
3030 numfmt --to=iec-i --suffix=B --padding=7 " $1 " ' 000'
3131}
3232
33+ # Check if the architecture is x86.
3334isX86 () {
3435 local arch
3536 arch=$( uname -m)
@@ -55,16 +56,19 @@ execAndMeasure() {
5556
5657 local end
5758 end=$( date +%s)
59+
5860 local after
5961 after=$( getAvailableSpace)
6062
63+ # How much space was saved.
6164 local saved=$(( after - before))
65+ # How long the task took.
6266 local seconds_taken=$(( end - start))
6367
6468 echo " ==> ${task_name} : Saved $( formatByteCount " $saved " ) in $seconds_taken seconds"
6569}
6670
67- # macro to print output of df with caption
71+ # Print output of df with caption. It shows information about disk space.
6872printDF () {
6973 local caption=${1}
7074
@@ -158,8 +162,7 @@ removeNodeModules() {
158162 " yarn"
159163}
160164
161- # Remove large packages
162- # REF: https://github.com/apache/flink/blob/master/tools/azure-pipelines/free_disk_space.sh
165+ # Remove unused packages.
163166cleanPackages () {
164167 local packages=(
165168 ' .*-icon-theme$'
0 commit comments