@@ -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
168133brew_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