-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yaml
More file actions
115 lines (101 loc) · 3.26 KB
/
Copy pathaction.yaml
File metadata and controls
115 lines (101 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
---
name: Free Disk Space
description: This action frees up disk space on a runner.
runs:
using: composite
steps:
- name: Free Disk Space (Parallel)
shell: bash
run: |
# WARNING: `set -e` is not set as we purposefully want this to run optimistically.
function cleanup_android() {
(
sudo rm -rf /usr/local/lib/android || true
)>/dev/null
}
function cleanup_apt() {
(
sudo apt-get remove --fix-missing -y '^aspnetcore-.*' \
'^dotnet-.*' \
'^llvm-.*' \
'php.*' \
'^mongodb-.*' \
'^mysql-.*' \
azure-cli \
google-chrome-stable \
firefox \
powershell \
mono-devel \
libgl1-mesa-dri \
google-cloud-sdk \
google-cloud-cli || true
sudo apt-get autoremove -y
sudo apt-get clean
)>/dev/null
}
function cleanup_dotnet() {
(
sudo rm -rf /usr/share/dotnet || true
)>/dev/null
}
function cleanup_haskell() {
(
sudo rm -rf /opt/ghc || true
sudo rm -rf /usr/local/.ghcup || true
)>/dev/null
}
function cleanup_docker() {
(
sudo docker image prune --all --force || true
)>/dev/null
}
function cleanup_agenttools() {
(
sudo rm -rf "$AGENT_TOOLSDIRECTORY" || true
)>/dev/null
}
function disable_swap() {
(
sudo swapoff -a || true
sudo rm -f /mnt/swapfile || true
free -h
)>/dev/null
}
# The bash `time` built-in can be given subshells, and the output format
# is configured via the TIMEFORMAT environment variable.
# The binary `time` output format can be configured via a `--format`
# flag.
# Since we are calling the cleanup functions in parallel, we need to
# wrap the built-in `time` so that each concurrent invokation doesn't
# affect the output format of another.
function time_it() {
local MESSAGE="$1"
local FUNCTION="$2"
local TIMEFORMAT="$MESSAGE (%Rs)"
time "$FUNCTION"
}
echo "::group::Disk usage before"
echo "In GiB:"
df -h -BGiB /
echo "In MiB:"
df -h -BMiB /
echo "::endgroup::"
echo "::group::Parallel cleanup"
time_it 'Removed Android libraries' cleanup_android &
time_it 'Removed apt packages' cleanup_apt &
time_it 'Removed dotnet packages' cleanup_dotnet &
time_it 'Removed haskell' cleanup_haskell &
time_it 'Pruned docker images' cleanup_docker &
time_it 'Disabled swap' disable_swap &
# This might remove tools that are actually needed, if set to "true" but
# frees about 6 GB.
# time_it 'Removed agent tools' cleanup_agenttools &
echo "Waiting for cleanup tasks"
wait
echo "::endgroup::"
echo "::group::Disk usage after"
echo "In GiB:"
df -h -BGiB /
echo "In MiB:"
df -h -BMiB /
echo "::endgroup::"