forked from easimon/maximize-build-space
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathaction.yml
162 lines (157 loc) · 6 KB
/
action.yml
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
name: 'Maximize build disk space (Only remove unwanted software)'
description: 'Maximize the available disk space for your build job by removing unwanted software'
branding:
icon: 'crop'
color: 'blue'
inputs:
remove-dotnet:
description: 'Removes .NET runtime and libraries. (frees ~2 GB)'
required: false
default: 'false'
remove-android:
description: 'Removes Android SDKs and Tools. (frees ~9 GB)'
required: false
default: 'false'
remove-haskell:
description: 'Removes GHC (Haskell) artifacts. (frees ~5.2 GB)'
required: false
default: 'false'
remove-codeql:
description: 'Removes CodeQL Action Bundles. (frees ~5.4 GB)'
required: false
default: 'false'
remove-docker-images:
description: 'Removes cached Docker images. (frees ~3.2 GB)'
required: false
default: 'false'
remove-large-packages:
description: 'Removes unwanted large Apt packages. (frees ~3.1 GB)'
required: false
default: 'false'
remove-cached-tools:
description: 'Removes cached tools used by setup actions by GitHub. (frees ~8.3 GB)'
required: false
default: 'false'
remove-swapfile:
description: 'Removes the Swapfile. (frees ~4 GB)'
required: false
default: 'false'
verbose:
description: 'Enables detailed logging of the action'
required: false
default: 'false'
runs:
using: "composite"
steps:
- name: Disk space report before modification
shell: bash
run: |
echo "==> Available space before cleanup"
echo
df -h
- name: Maximize build disk space
shell: bash
run: |
set -euo pipefail
echo -n " Removing: "
if [[ ${{ inputs.remove-dotnet }} == 'true' ]]; then
echo -n "dotnet "
fi
if [[ ${{ inputs.remove-android }} == 'true' ]]; then
echo -n "android "
fi
if [[ ${{ inputs.remove-haskell }} == 'true' ]]; then
echo -n "haskell "
fi
if [[ ${{ inputs.remove-codeql }} == 'true' ]]; then
echo -n "codeql "
fi
if [[ ${{ inputs.remove-docker-images }} == 'true' ]]; then
echo -n "docker "
fi
if [[ ${{ inputs.remove-large-packages }} == 'true' ]]; then
echo -n "large_packages "
fi
if [[ ${{ inputs.remove-cached-tools }} == 'true' ]]; then
echo -n "cached_tools "
fi
if [[ ${{ inputs.remove-swapfile }} == 'true' ]]; then
echo -n "swapfile "
fi
echo
verbose=""
if [[ ${{ inputs.verbose }} == 'true' ]]; then
verbose=-v
fi
echo "Removing unwanted software... "
if [[ ${{ inputs.remove-dotnet }} == 'true' ]]; then
sudo rm -rf ${verbose} /usr/share/dotnet
fi
if [[ ${{ inputs.remove-android }} == 'true' ]]; then
sudo rm -rf ${verbose} /usr/local/lib/android
fi
if [[ ${{ inputs.remove-haskell }} == 'true' ]]; then
sudo rm -rf ${verbose} /opt/ghc
sudo rm -rf ${verbose} /usr/local/.ghcup
fi
if [[ ${{ inputs.remove-codeql }} == 'true' ]]; then
sudo rm -rf ${verbose} /opt/hostedtoolcache/CodeQL
fi
if [[ ${{ inputs.remove-docker-images }} == 'true' ]]; then
if [[ ${{ inputs.verbose }} == 'true' ]]; then
sudo docker image prune --all --force
else
sudo docker image prune --all --force > /dev/null
fi
fi
CODENAME=$(lsb_release -c | cut -d ":" -f 2 | xargs)
if [[ (${CODENAME} = focal) || (${CODENAME} = jammy) ]]; then
POWERSHELL=powershell
else
POWERSHELL=powershell-lts
fi
if [[ ${{ inputs.remove-large-packages }} == 'true' ]]; then
if [[ ${{ inputs.verbose }} == 'true' ]]; then
sudo apt-get remove -y '^aspnetcore-.*'
sudo apt-get remove -y '^dotnet-.*'
sudo apt-get remove -y '^llvm-.*'
sudo apt-get remove -y 'php.*'
sudo apt-get remove -y '^mongodb-.*'
sudo apt-get remove -y '^mysql-.*'
sudo apt-get remove -y azure-cli google-chrome-stable firefox ${POWERSHELL} mono-devel libgl1-mesa-dri --fix-missing
if [[ (${CODENAME} = focal) || (${CODENAME} = jammy) ]]; then
sudo apt-get remove -y google-cloud-sdk --fix-missing
sudo apt-get remove -y google-cloud-cli --fix-missing
fi
sudo apt-get autoremove -y
sudo apt-get clean
else
sudo apt-get remove -y '^aspnetcore-.*' > /dev/null
sudo apt-get remove -y '^dotnet-.*' > /dev/null
sudo apt-get remove -y '^llvm-.*' > /dev/null
sudo apt-get remove -y 'php.*' > /dev/null
sudo apt-get remove -y '^mongodb-.*' > /dev/null
sudo apt-get remove -y '^mysql-.*' > /dev/null
sudo apt-get remove -y azure-cli google-chrome-stable firefox ${POWERSHELL} mono-devel libgl1-mesa-dri --fix-missing > /dev/null
if [[ (${CODENAME} = focal) || (${CODENAME} = jammy) ]]; then
sudo apt-get remove -y google-cloud-sdk --fix-missing > /dev/null
sudo apt-get remove -y google-cloud-cli --fix-missing > /dev/null
fi
sudo apt-get autoremove -y > /dev/null
sudo apt-get clean > /dev/null
fi
fi
if [[ ${{ inputs.remove-cached-tools }} == 'true' ]]; then
sudo rm -rf ${verbose} "$AGENT_TOOLSDIRECTORY"
fi
if [[ ${{ inputs.remove-swapfile }} == 'true' ]]; then
sudo swapoff -a ${verbose}
sudo rm -f ${verbose} /mnt/swapfile
fi
echo "... done"
- name: Disk space report after modification
shell: bash
run: |
echo "==> Available space after cleanup"
echo
df -h