Skip to content

Commit 883df05

Browse files
[macos] simplify "brew_smart_install" helper (#8639)
* [macos] homebrew: use hardcoded condition for jq installation we cannot use "jq" if we are asked to install "jq" * [macos] always use "brew install" * [macos] add retries to "get_github_package_download_url" helper * [macos] add retries to chrome install script * [macos] add retries to OpenJDK install script * [macos] add retries to miniconda installer * Update images/macos/provision/core/openjdk.sh Co-authored-by: Vasilii Polikarpov <126792224+vpolikarpov-akvelon@users.noreply.github.com> * fix copy-paste error * Update images/macos/provision/core/openjdk.sh Co-authored-by: Vasilii Polikarpov <126792224+vpolikarpov-akvelon@users.noreply.github.com> * Update images/macos/provision/core/openjdk.sh Co-authored-by: Vasilii Polikarpov <126792224+vpolikarpov-akvelon@users.noreply.github.com> --------- Co-authored-by: Vasilii Polikarpov <126792224+vpolikarpov-akvelon@users.noreply.github.com>
1 parent 7ca7296 commit 883df05

File tree

4 files changed

+55
-89
lines changed

4 files changed

+55
-89
lines changed

images/macos/provision/core/chrome.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ echo "Google Chrome version is $FULL_CHROME_VERSION"
1414
# Get Google Chrome versions information
1515
CHROME_PLATFORM="mac-$arch"
1616
CHROME_VERSIONS_URL="https://googlechromelabs.github.io/chrome-for-testing/latest-patch-versions-per-build-with-downloads.json"
17-
CHROME_VERSIONS_JSON=$(curl -fsSL "${CHROME_VERSIONS_URL}")
17+
download_with_retries "$CHROME_VERSIONS_URL" "/tmp" "latest-patch-versions-per-build-with-downloads.json"
18+
CHROME_VERSIONS_JSON=$(cat /tmp/latest-patch-versions-per-build-with-downloads.json)
1819

1920
# Download and unpack the latest release of Chrome Driver
2021
CHROMEDRIVER_VERSION=$(echo "${CHROME_VERSIONS_JSON}" | jq -r '.builds["'"$CHROME_VERSION"'"].version')

images/macos/provision/core/miniconda.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/bin/bash -e -o pipefail
22

3-
MINICONDA_INSTALLER="/tmp/miniconda.sh"
4-
curl -fsSL https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -o $MINICONDA_INSTALLER
5-
chmod +x $MINICONDA_INSTALLER
6-
sudo $MINICONDA_INSTALLER -b -p /usr/local/miniconda
3+
source ~/utils/utils.sh
4+
5+
download_with_retries "https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh" "/tmp" "miniconda.sh"
6+
7+
chmod +x /tmp/miniconda.sh
8+
sudo /tmp/miniconda.sh -b -p /usr/local/miniconda
79

810
# Chmod with full permissions recursively to avoid permissions restrictions
911
sudo chmod -R 777 /usr/local/miniconda

images/macos/provision/core/openjdk.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ installOpenJDK() {
2929
local JAVA_VERSION=$1
3030

3131
# Get link for Java binaries and Java version
32-
assetUrl=$(curl -fsSL "https://api.adoptium.net/v3/assets/latest/${JAVA_VERSION}/hotspot")
32+
download_with_retries "https://api.adoptium.net/v3/assets/latest/${JAVA_VERSION}/hotspot" "/tmp" "openjdk-hotspot.json"
3333

3434
if [[ $arch == "arm64" ]]; then
35-
asset=$(echo ${assetUrl} | jq -r '.[] | select(.binary.os=="mac" and .binary.image_type=="jdk" and .binary.architecture=="aarch64")')
35+
asset=$(jq -r '.[] | select(.binary.os=="mac" and .binary.image_type=="jdk" and .binary.architecture=="aarch64")' /tmp/openjdk-hotspot.json)
3636
else
37-
asset=$(echo ${assetUrl} | jq -r '.[] | select(.binary.os=="mac" and .binary.image_type=="jdk" and .binary.architecture=="x64")')
37+
asset=$(jq -r '.[] | select(.binary.os=="mac" and .binary.image_type=="jdk" and .binary.architecture=="x64")' /tmp/openjdk-hotspot.json)
3838
fi
3939

4040
archivePath=$(echo ${asset} | jq -r '.binary.package.link')

images/macos/provision/utils/utils.sh

Lines changed: 44 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -127,98 +127,50 @@ get_brew_os_keyword() {
127127
fi
128128
}
129129

130-
should_build_from_source() {
131-
local tool_name=$1
132-
local os_name=$2
133-
# If one of the parsers aborts with an error,
134-
# we will get an empty variable notification in the logs
135-
set -u
136-
137-
# Geting tool info from brew to find available install methods except build from source
138-
local tool_info=$(brew info --json=v1 $tool_name)
139-
140-
# No need to build from source if a bottle is disabled
141-
local bottle_disabled=$(echo -E $tool_info | jq ".[0].bottle_disabled")
142-
if [[ $bottle_disabled == "true" ]]; then
143-
echo "false"
144-
return
145-
fi
146-
147-
# No need to build from source if a universal bottle is available
148-
local all_bottle=$(echo -E $tool_info | jq ".[0].bottle.stable.files.all")
149-
if [[ "$all_bottle" != "null" ]]; then
150-
echo "false"
151-
return
152-
fi
153-
154-
# No need to build from source if a bottle for current OS is available
155-
local os_bottle=$(echo -E $tool_info | jq ".[0].bottle.stable.files.$os_name")
156-
if [[ "$os_bottle" != "null" ]]; then
157-
echo "false"
158-
return
159-
fi
160-
161-
# Available method wasn't found - should build from source
162-
echo "true"
163-
}
164-
165130
# brew provides package bottles for different macOS versions
166131
# The 'brew install' command will fail if a package bottle does not exist
167132
# Use the '--build-from-source' option to build from source in this case
168133
brew_smart_install() {
169134
local tool_name=$1
170135

171-
local os_name=$(get_brew_os_keyword)
172-
if [[ "$os_name" == "null" ]]; then
173-
echo "$OSTYPE is unknown operating system"
174-
exit 1
175-
fi
136+
echo "Downloading $tool_name..."
176137

177-
local build_from_source=$(should_build_from_source "$tool_name" "$os_name")
178-
if $build_from_source; then
179-
echo "Bottle of the $tool_name for the $os_name was not found. Building $tool_name from source..."
180-
brew install --build-from-source $tool_name
181-
else
182-
echo "Downloading $tool_name..."
138+
# get deps & cache em
139+
140+
failed=true
141+
for i in {1..10}; do
142+
brew deps $tool_name > /tmp/$tool_name && failed=false || sleep 60
143+
[ "$failed" = false ] && break
144+
done
183145

184-
# get deps & cache em
146+
if [ "$failed" = true ]; then
147+
echo "Failed: brew deps $tool_name"
148+
exit 1;
149+
fi
185150

186-
failed=true
187-
for i in {1..10}; do
188-
brew deps $tool_name > /tmp/$tool_name && failed=false || sleep 60
189-
[ "$failed" = false ] && break
190-
done
151+
for dep in $(cat /tmp/$tool_name) $tool_name; do
191152

192-
if [ "$failed" = true ]; then
193-
echo "Failed: brew deps $tool_name"
194-
exit 1;
195-
fi
153+
failed=true
154+
for i in {1..10}; do
155+
brew --cache $dep >/dev/null && failed=false || sleep 60
156+
[ "$failed" = false ] && break
157+
done
196158

197-
for dep in $(cat /tmp/$tool_name) $tool_name; do
198-
199-
failed=true
200-
for i in {1..10}; do
201-
brew --cache $dep >/dev/null && failed=false || sleep 60
202-
[ "$failed" = false ] && break
203-
done
204-
205-
if [ "$failed" = true ]; then
206-
echo "Failed: brew --cache $dep"
207-
exit 1;
208-
fi
209-
done
210-
211-
failed=true
212-
for i in {1..10}; do
213-
brew install $tool_name >/dev/null && failed=false || sleep 60
214-
[ "$failed" = false ] && break
215-
done
216-
217-
if [ "$failed" = true ]; then
218-
echo "Failed: brew install $tool_name"
219-
exit 1;
220-
fi
159+
if [ "$failed" = true ]; then
160+
echo "Failed: brew --cache $dep"
161+
exit 1;
162+
fi
163+
done
221164

165+
failed=true
166+
for i in {1..10}; do
167+
brew install $tool_name >/dev/null && failed=false || sleep 60
168+
[ "$failed" = false ] && break
169+
done
170+
171+
if [ "$failed" = true ]; then
172+
echo "Failed: brew install $tool_name"
173+
exit 1;
222174
fi
223175
}
224176

@@ -247,7 +199,18 @@ get_github_package_download_url() {
247199

248200
[ -n "$API_PAT" ] && authString=(-H "Authorization: token ${API_PAT}")
249201

250-
json=$(curl "${authString[@]}" -fsSL "https://api.github.com/repos/${REPO_ORG}/releases?per_page=${SEARCH_IN_COUNT}")
202+
failed=true
203+
for i in {1..10}; do
204+
curl "${authString[@]}" -fsSL "https://api.github.com/repos/${REPO_ORG}/releases?per_page=${SEARCH_IN_COUNT}" >/tmp/get_github_package_download_url.json && failed=false || sleep 60
205+
[ "$failed" = false ] && break
206+
done
207+
208+
if [ "$failed" = true ]; then
209+
echo "Failed: get_github_package_download_url"
210+
exit 1;
211+
fi
212+
213+
json=$(cat /tmp/get_github_package_download_url.json)
251214

252215
if [[ "$VERSION" == "latest" ]]; then
253216
tagName=$(echo $json | jq -r '.[] | select((.prerelease==false) and (.assets | length > 0)).tag_name' | sort --unique --version-sort | egrep -v ".*-[a-z]" | tail -1)

0 commit comments

Comments
 (0)