[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>
This commit is contained in:
ilia-shipitsin
2023-10-26 15:17:57 +02:00
committed by GitHub
parent 7ca7296ba5
commit 883df0594b
4 changed files with 55 additions and 89 deletions

View File

@@ -14,7 +14,8 @@ echo "Google Chrome version is $FULL_CHROME_VERSION"
# Get Google Chrome versions information
CHROME_PLATFORM="mac-$arch"
CHROME_VERSIONS_URL="https://googlechromelabs.github.io/chrome-for-testing/latest-patch-versions-per-build-with-downloads.json"
CHROME_VERSIONS_JSON=$(curl -fsSL "${CHROME_VERSIONS_URL}")
download_with_retries "$CHROME_VERSIONS_URL" "/tmp" "latest-patch-versions-per-build-with-downloads.json"
CHROME_VERSIONS_JSON=$(cat /tmp/latest-patch-versions-per-build-with-downloads.json)
# Download and unpack the latest release of Chrome Driver
CHROMEDRIVER_VERSION=$(echo "${CHROME_VERSIONS_JSON}" | jq -r '.builds["'"$CHROME_VERSION"'"].version')

View File

@@ -1,9 +1,11 @@
#!/bin/bash -e -o pipefail
MINICONDA_INSTALLER="/tmp/miniconda.sh"
curl -fsSL https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -o $MINICONDA_INSTALLER
chmod +x $MINICONDA_INSTALLER
sudo $MINICONDA_INSTALLER -b -p /usr/local/miniconda
source ~/utils/utils.sh
download_with_retries "https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh" "/tmp" "miniconda.sh"
chmod +x /tmp/miniconda.sh
sudo /tmp/miniconda.sh -b -p /usr/local/miniconda
# Chmod with full permissions recursively to avoid permissions restrictions
sudo chmod -R 777 /usr/local/miniconda

View File

@@ -29,12 +29,12 @@ installOpenJDK() {
local JAVA_VERSION=$1
# Get link for Java binaries and Java version
assetUrl=$(curl -fsSL "https://api.adoptium.net/v3/assets/latest/${JAVA_VERSION}/hotspot")
download_with_retries "https://api.adoptium.net/v3/assets/latest/${JAVA_VERSION}/hotspot" "/tmp" "openjdk-hotspot.json"
if [[ $arch == "arm64" ]]; then
asset=$(echo ${assetUrl} | jq -r '.[] | select(.binary.os=="mac" and .binary.image_type=="jdk" and .binary.architecture=="aarch64")')
asset=$(jq -r '.[] | select(.binary.os=="mac" and .binary.image_type=="jdk" and .binary.architecture=="aarch64")' /tmp/openjdk-hotspot.json)
else
asset=$(echo ${assetUrl} | jq -r '.[] | select(.binary.os=="mac" and .binary.image_type=="jdk" and .binary.architecture=="x64")')
asset=$(jq -r '.[] | select(.binary.os=="mac" and .binary.image_type=="jdk" and .binary.architecture=="x64")' /tmp/openjdk-hotspot.json)
fi
archivePath=$(echo ${asset} | jq -r '.binary.package.link')

View File

@@ -127,98 +127,50 @@ get_brew_os_keyword() {
fi
}
should_build_from_source() {
local tool_name=$1
local os_name=$2
# If one of the parsers aborts with an error,
# we will get an empty variable notification in the logs
set -u
# Geting tool info from brew to find available install methods except build from source
local tool_info=$(brew info --json=v1 $tool_name)
# No need to build from source if a bottle is disabled
local bottle_disabled=$(echo -E $tool_info | jq ".[0].bottle_disabled")
if [[ $bottle_disabled == "true" ]]; then
echo "false"
return
fi
# No need to build from source if a universal bottle is available
local all_bottle=$(echo -E $tool_info | jq ".[0].bottle.stable.files.all")
if [[ "$all_bottle" != "null" ]]; then
echo "false"
return
fi
# No need to build from source if a bottle for current OS is available
local os_bottle=$(echo -E $tool_info | jq ".[0].bottle.stable.files.$os_name")
if [[ "$os_bottle" != "null" ]]; then
echo "false"
return
fi
# Available method wasn't found - should build from source
echo "true"
}
# brew provides package bottles for different macOS versions
# The 'brew install' command will fail if a package bottle does not exist
# Use the '--build-from-source' option to build from source in this case
brew_smart_install() {
local tool_name=$1
local os_name=$(get_brew_os_keyword)
if [[ "$os_name" == "null" ]]; then
echo "$OSTYPE is unknown operating system"
exit 1
echo "Downloading $tool_name..."
# get deps & cache em
failed=true
for i in {1..10}; do
brew deps $tool_name > /tmp/$tool_name && failed=false || sleep 60
[ "$failed" = false ] && break
done
if [ "$failed" = true ]; then
echo "Failed: brew deps $tool_name"
exit 1;
fi
local build_from_source=$(should_build_from_source "$tool_name" "$os_name")
if $build_from_source; then
echo "Bottle of the $tool_name for the $os_name was not found. Building $tool_name from source..."
brew install --build-from-source $tool_name
else
echo "Downloading $tool_name..."
for dep in $(cat /tmp/$tool_name) $tool_name; do
# get deps & cache em
failed=true
for i in {1..10}; do
brew --cache $dep >/dev/null && failed=false || sleep 60
[ "$failed" = false ] && break
done
failed=true
for i in {1..10}; do
brew deps $tool_name > /tmp/$tool_name && failed=false || sleep 60
[ "$failed" = false ] && break
done
if [ "$failed" = true ]; then
echo "Failed: brew --cache $dep"
exit 1;
fi
done
if [ "$failed" = true ]; then
echo "Failed: brew deps $tool_name"
exit 1;
fi
for dep in $(cat /tmp/$tool_name) $tool_name; do
failed=true
for i in {1..10}; do
brew --cache $dep >/dev/null && failed=false || sleep 60
[ "$failed" = false ] && break
done
if [ "$failed" = true ]; then
echo "Failed: brew --cache $dep"
exit 1;
fi
done
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
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
}
@@ -247,7 +199,18 @@ get_github_package_download_url() {
[ -n "$API_PAT" ] && authString=(-H "Authorization: token ${API_PAT}")
json=$(curl "${authString[@]}" -fsSL "https://api.github.com/repos/${REPO_ORG}/releases?per_page=${SEARCH_IN_COUNT}")
failed=true
for i in {1..10}; do
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
[ "$failed" = false ] && break
done
if [ "$failed" = true ]; then
echo "Failed: get_github_package_download_url"
exit 1;
fi
json=$(cat /tmp/get_github_package_download_url.json)
if [[ "$VERSION" == "latest" ]]; then
tagName=$(echo $json | jq -r '.[] | select((.prerelease==false) and (.assets | length > 0)).tag_name' | sort --unique --version-sort | egrep -v ".*-[a-z]" | tail -1)