1
1
#! /bin/bash
2
2
set -euo pipefail
3
3
4
- # Free disk space on Linux GitHub action runners
4
+ # Free disk space on Linux GitHub action runners.
5
5
# Script inspired by https://github.com/jlumbroso/free-disk-space
6
6
7
7
# When updating to a new ubuntu version (e.g. from ubuntu-24.04):
8
8
# - Check that there are no docker images preinstalled with `docker image ls`
9
9
# - Check that there are no big packages preinstalled that we aren't using
10
10
# - Check that all directores we are removing are still present (look at the warnings)
11
11
12
- # print a line of the specified character
12
+ # Print a line of the specified character.
13
13
printSeparationLine () {
14
14
for (( i = 0 ; i < 80 ; i++ )) ; do
15
15
printf " %s" " $1 "
16
16
done
17
17
printf " \n"
18
18
}
19
19
20
- # compute available space
20
+ # Compute available space.
21
21
# REF: https://unix.stackexchange.com/a/42049/60849
22
22
# REF: https://stackoverflow.com/a/450821/408734
23
23
getAvailableSpace () {
24
24
df -a | awk ' NR > 1 {avail+=$4} END {print avail}'
25
25
}
26
26
27
- # make Kb human readable (assume the input is Kb)
27
+ # Make Kb human readable (assume the input is Kb).
28
28
# REF: https://unix.stackexchange.com/a/44087/60849
29
29
formatByteCount () {
30
30
numfmt --to=iec-i --suffix=B --padding=7 " $1 " ' 000'
31
31
}
32
32
33
+ # Check if the architecture is x86.
33
34
isX86 () {
34
35
local arch
35
36
arch=$( uname -m)
@@ -55,16 +56,19 @@ execAndMeasure() {
55
56
56
57
local end
57
58
end=$( date +%s)
59
+
58
60
local after
59
61
after=$( getAvailableSpace)
60
62
63
+ # How much space was saved.
61
64
local saved=$(( after - before))
65
+ # How long the task took.
62
66
local seconds_taken=$(( end - start))
63
67
64
68
echo " ==> ${task_name} : Saved $( formatByteCount " $saved " ) in $seconds_taken seconds"
65
69
}
66
70
67
- # macro to print output of df with caption
71
+ # Print output of df with caption. It shows information about disk space.
68
72
printDF () {
69
73
local caption=${1}
70
74
@@ -158,8 +162,7 @@ removeNodeModules() {
158
162
" yarn"
159
163
}
160
164
161
- # Remove large packages
162
- # REF: https://github.com/apache/flink/blob/master/tools/azure-pipelines/free_disk_space.sh
165
+ # Remove unused packages.
163
166
cleanPackages () {
164
167
local packages=(
165
168
' .*-icon-theme$'
0 commit comments