mirror of
https://github.com/actions/runner-images.git
synced 2025-12-31 22:43:22 +08:00
[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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user