Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 64 additions & 2 deletions NewMachineSetup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,12 @@ validate_inputs() {

for endpoint in "https://brew.sh" "https://pypi.org/simple/" "https://rubygems.org"; do
if ! check_url_connectivity "$endpoint"; then
record_failure "preflight-validation" "network_unreachable_$(echo "$endpoint" | sed 's#https\?://##; s#[^A-Za-z0-9]#_#g')"
valid=false
if is_ci_environment && [ "$endpoint" = "https://brew.sh" ]; then
echo "Warning: $endpoint unreachable in CI environment; skipping as non-fatal"
else
record_failure "preflight-validation" "network_unreachable_$(echo "$endpoint" | sed 's#https\?://##; s#[^A-Za-z0-9]#_#g')"
valid=false
fi
fi
done

Expand Down Expand Up @@ -403,6 +407,62 @@ update_homebrew() {
return 0
}

cleanup_unmanaged_homebrew_taps() {
if ! command_exists brew; then
return 0
fi

local brewfile_path="Brewfile"
if [ ! -f "$brewfile_path" ]; then
local script_dir
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
brewfile_path="$script_dir/Brewfile"
if [ ! -f "$brewfile_path" ]; then
return 0
fi
fi

local tap required_tap
local keep_tap
local -a required_taps=() installed_taps=()

while IFS= read -r tap; do
if [ -n "$tap" ]; then
required_taps+=("$tap")
fi
done < <(sed -n 's/^tap[[:space:]]*"\([^"]*\)".*/\1/p' "$brewfile_path")

while IFS= read -r tap; do
if [ -n "$tap" ]; then
installed_taps+=("$tap")
fi
done < <(brew tap 2>/dev/null)

for tap in ${installed_taps[@]+"${installed_taps[@]}"}; do
keep_tap=false
for required_tap in ${required_taps[@]+"${required_taps[@]}"}; do
if [ "$tap" = "$required_tap" ]; then
keep_tap=true
break
fi
done

if [ "$keep_tap" = true ]; then
continue
fi

if [[ "$tap" == homebrew/* ]]; then
continue
fi

if ! brew untap "$tap"; then
echo "Warning: Unable to untap '$tap'. It is likely still required by an installed formula; remove the dependent formula first." >&2
fi
done

return 0
}

install_brewfile() {
echo "Installing packages and applications from Brewfile..."
local brew_bundle_args=(--verbose)
Expand Down Expand Up @@ -667,6 +727,8 @@ run_post_checks() {
return 1
fi

cleanup_unmanaged_homebrew_taps

if ! invoke_with_retry "Run brew doctor" brew doctor; then
if is_ci_environment; then
echo "Ignoring brew doctor failure in CI due to hosted-runner Homebrew warnings."
Expand Down
Loading