Skip to content

Commit 58ccf67

Browse files
[macos] improve brew caching approach (#8630)
1 parent 6a98903 commit 58ccf67

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

images/macos/provision/core/homebrew.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ source ~/utils/utils.sh
55
arch=$(get_arch)
66

77
echo "Installing Homebrew..."
8-
HOMEBREW_INSTALL_URL="https://raw.githubusercontent.com/Homebrew/install/master/install.sh"
9-
/bin/bash -c "$(curl -fsSL ${HOMEBREW_INSTALL_URL})"
8+
download_with_retries "https://raw.githubusercontent.com/Homebrew/install/master/install.sh" "/tmp" "homebrew-install.sh"
9+
/bin/bash /tmp/homebrew-install.sh
1010

1111
if [[ $arch == "arm64" ]]; then
1212
/opt/homebrew/bin/brew update

images/macos/provision/core/nvm.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ source ~/utils/utils.sh
77

88
[ -n "$API_PAT" ] && authString=(-H "Authorization: token ${API_PAT}")
99
VERSION=$(curl "${authString[@]}" -fsSL https://api.github.com/repos/nvm-sh/nvm/releases/latest | jq -r '.tag_name')
10-
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/$VERSION/install.sh | bash
10+
download_with_retries "https://raw.githubusercontent.com/nvm-sh/nvm/$VERSION/install.sh" "/tmp" "nvm-install.sh"
11+
bash /tmp/nvm-install.sh
1112

1213
if [ $? -eq 0 ]; then
1314
. ~/.bashrc

images/macos/provision/utils/utils.sh

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,24 +179,20 @@ brew_smart_install() {
179179
failed=true
180180
for i in {1..10}; do
181181
brew deps $tool_name > /tmp/$tool_name && failed=false || sleep 60
182-
if [ "$failed" = false ]; then
183-
break
184-
fi
182+
[ "$failed" = false ] && break
185183
done
186184

187185
if [ "$failed" = true ]; then
188186
echo "Failed: brew deps $tool_name"
189187
exit 1;
190188
fi
191189

192-
for dep in $(cat /tmp/$tool_name); do
190+
for dep in $(cat /tmp/$tool_name) $tool_name; do
193191

194192
failed=true
195193
for i in {1..10}; do
196-
brew --cache $dep && failed=false || sleep 60
197-
if [ "$failed" = false ]; then
198-
break
199-
fi
194+
brew --cache $dep >/dev/null && failed=false || sleep 60
195+
[ "$failed" = false ] && break
200196
done
201197

202198
if [ "$failed" = true ]; then
@@ -205,7 +201,17 @@ brew_smart_install() {
205201
fi
206202
done
207203

208-
brew install $tool_name
204+
failed=true
205+
for i in {1..10}; do
206+
brew install $tool_name >/dev/null && failed=false || sleep 60
207+
[ "$failed" = false ] && break
208+
done
209+
210+
if [ "$failed" = true ]; then
211+
echo "Failed: brew install $tool_name"
212+
exit 1;
213+
fi
214+
209215
fi
210216
}
211217

0 commit comments

Comments
 (0)