@@ -14,6 +14,17 @@ isX86() {
1414 fi
1515}
1616
17+ # Check if we're on a GitHub hosted runner.
18+ # In aws codebuild, the variable RUNNER_ENVIRONMENT is "self-hosted".
19+ isGitHubRunner () {
20+ # `:-` means "use the value of RUNNER_ENVIRONMENT if it exists, otherwise use an empty string".
21+ if [[ " ${RUNNER_ENVIRONMENT:- } " == " github-hosted" ]]; then
22+ return 0
23+ else
24+ return 1
25+ fi
26+ }
27+
1728# print a line of the specified character
1829printSeparationLine () {
1930 for (( i = 0 ; i < 80 ; i++ )) ; do
@@ -32,7 +43,7 @@ getAvailableSpace() {
3243# make Kb human readable (assume the input is Kb)
3344# REF: https://unix.stackexchange.com/a/44087/60849
3445formatByteCount () {
35- numfmt --to=iec-i --suffix=B --padding=7 " $1 " ' 000'
46+ numfmt --to=iec-i --suffix=B --padding=7 " ${1} 000"
3647}
3748
3849# macro to output saved space
@@ -45,6 +56,11 @@ printSavedSpace() {
4556 after=$( getAvailableSpace)
4657 local saved=$(( after - before))
4758
59+ if [ " $saved " -lt 0 ]; then
60+ echo " ::warning::Saved space is negative: $saved . Using ` 0` as saved space."
61+ saved=0
62+ fi
63+
4864 echo " "
4965 printSeparationLine " *"
5066 if [ -n " ${title} " ]; then
@@ -118,10 +134,14 @@ removeUnusedFilesAndDirs() {
118134 # Azure
119135 " /opt/az"
120136 " /usr/share/az_" *
137+ )
121138
139+ if [ -n " ${AGENT_TOOLSDIRECTORY:- } " ]; then
122140 # Environment variable set by GitHub Actions
123- " $AGENT_TOOLSDIRECTORY "
124- )
141+ to_remove+=(
142+ " ${AGENT_TOOLSDIRECTORY} "
143+ )
144+ fi
125145
126146 for element in " ${to_remove[@]} " ; do
127147 if [ ! -e " $element " ]; then
@@ -155,20 +175,25 @@ cleanPackages() {
155175 ' ^dotnet-.*'
156176 ' ^llvm-.*'
157177 ' ^mongodb-.*'
158- ' azure-cli'
159178 ' firefox'
160179 ' libgl1-mesa-dri'
161180 ' mono-devel'
162181 ' php.*'
163182 )
164183
165- if isX86 ; then
184+ if isGitHubRunner ; then
166185 packages+=(
167- ' google-chrome-stable'
168- ' google-cloud-cli'
169- ' google-cloud-sdk'
170- ' powershell'
186+ azure-cli
171187 )
188+
189+ if isX86; then
190+ packages+=(
191+ ' google-chrome-stable'
192+ ' google-cloud-cli'
193+ ' google-cloud-sdk'
194+ ' powershell'
195+ )
196+ fi
172197 fi
173198
174199 sudo apt-get -qq remove -y --fix-missing " ${packages[@]} "
0 commit comments