From 58ccf6762a0c00a29cd496ab892245a30566fff2 Mon Sep 17 00:00:00 2001 From: ilia-shipitsin <125650415+ilia-shipitsin@users.noreply.github.com> Date: Mon, 23 Oct 2023 09:17:15 +0200 Subject: [PATCH] [macos] improve brew caching approach (#8630) --- images/macos/provision/core/homebrew.sh | 4 ++-- images/macos/provision/core/nvm.sh | 3 ++- images/macos/provision/utils/utils.sh | 24 +++++++++++++++--------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/images/macos/provision/core/homebrew.sh b/images/macos/provision/core/homebrew.sh index e68db37b..dea00c93 100755 --- a/images/macos/provision/core/homebrew.sh +++ b/images/macos/provision/core/homebrew.sh @@ -5,8 +5,8 @@ source ~/utils/utils.sh arch=$(get_arch) echo "Installing Homebrew..." -HOMEBREW_INSTALL_URL="https://raw.githubusercontent.com/Homebrew/install/master/install.sh" -/bin/bash -c "$(curl -fsSL ${HOMEBREW_INSTALL_URL})" +download_with_retries "https://raw.githubusercontent.com/Homebrew/install/master/install.sh" "/tmp" "homebrew-install.sh" +/bin/bash /tmp/homebrew-install.sh if [[ $arch == "arm64" ]]; then /opt/homebrew/bin/brew update diff --git a/images/macos/provision/core/nvm.sh b/images/macos/provision/core/nvm.sh index 7d30908b..7eaa2fcd 100755 --- a/images/macos/provision/core/nvm.sh +++ b/images/macos/provision/core/nvm.sh @@ -7,7 +7,8 @@ source ~/utils/utils.sh [ -n "$API_PAT" ] && authString=(-H "Authorization: token ${API_PAT}") VERSION=$(curl "${authString[@]}" -fsSL https://api.github.com/repos/nvm-sh/nvm/releases/latest | jq -r '.tag_name') -curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/$VERSION/install.sh | bash +download_with_retries "https://raw.githubusercontent.com/nvm-sh/nvm/$VERSION/install.sh" "/tmp" "nvm-install.sh" +bash /tmp/nvm-install.sh if [ $? -eq 0 ]; then . ~/.bashrc diff --git a/images/macos/provision/utils/utils.sh b/images/macos/provision/utils/utils.sh index 023701f2..5cb86690 100755 --- a/images/macos/provision/utils/utils.sh +++ b/images/macos/provision/utils/utils.sh @@ -179,9 +179,7 @@ brew_smart_install() { failed=true for i in {1..10}; do brew deps $tool_name > /tmp/$tool_name && failed=false || sleep 60 - if [ "$failed" = false ]; then - break - fi + [ "$failed" = false ] && break done if [ "$failed" = true ]; then @@ -189,14 +187,12 @@ brew_smart_install() { exit 1; fi - for dep in $(cat /tmp/$tool_name); do + for dep in $(cat /tmp/$tool_name) $tool_name; do failed=true for i in {1..10}; do - brew --cache $dep && failed=false || sleep 60 - if [ "$failed" = false ]; then - break - fi + brew --cache $dep >/dev/null && failed=false || sleep 60 + [ "$failed" = false ] && break done if [ "$failed" = true ]; then @@ -205,7 +201,17 @@ brew_smart_install() { fi done - brew install $tool_name + failed=true + for i in {1..10}; do + brew install $tool_name >/dev/null && failed=false || sleep 60 + [ "$failed" = false ] && break + done + + if [ "$failed" = true ]; then + echo "Failed: brew install $tool_name" + exit 1; + fi + fi }