From 4be99a16b5bade8d146fae914efa5b5b71308b5f Mon Sep 17 00:00:00 2001 From: Vito Castellano Date: Mon, 29 Dec 2025 23:13:31 +0100 Subject: [PATCH] fix(ci): properly detect and remove pre-installed Homebrew GitHub Actions runners have Homebrew pre-installed but not in PATH. Check for directory existence, not just command availability. Force remove all Homebrew directories to ensure clean state. --- .github/workflows/test-install.yml | 38 ++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test-install.yml b/.github/workflows/test-install.yml index 9919040..a571582 100644 --- a/.github/workflows/test-install.yml +++ b/.github/workflows/test-install.yml @@ -21,10 +21,21 @@ jobs: - name: Ensure clean state (no Homebrew) run: | - if command -v brew &> /dev/null; then + # Check both PATH and direct path + if command -v brew &> /dev/null || [ -d /home/linuxbrew/.linuxbrew ]; then echo "Removing existing Homebrew..." - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)" -- --force || true + # Try official uninstaller first + if [ -x /home/linuxbrew/.linuxbrew/bin/brew ]; then + NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)" || true + fi + # Force remove directories sudo rm -rf /home/linuxbrew/.linuxbrew + sudo rm -rf /home/linuxbrew + fi + # Verify clean + if [ -d /home/linuxbrew ]; then + echo "ERROR: Failed to remove Homebrew" + exit 1 fi echo "✓ Clean state confirmed" @@ -52,11 +63,17 @@ jobs: - name: Ensure clean state (no Homebrew) run: | - if command -v brew &> /dev/null; then + if command -v brew &> /dev/null || [ -d /opt/homebrew ]; then echo "Removing existing Homebrew..." - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)" -- --force || true + if [ -x /opt/homebrew/bin/brew ]; then + NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)" || true + fi sudo rm -rf /opt/homebrew fi + if [ -d /opt/homebrew ]; then + echo "ERROR: Failed to remove Homebrew" + exit 1 + fi echo "✓ Clean state confirmed" - name: Run install script @@ -83,12 +100,19 @@ jobs: - name: Ensure clean state (no Homebrew) run: | - if command -v brew &> /dev/null; then + if command -v brew &> /dev/null || [ -d /usr/local/Homebrew ]; then echo "Removing existing Homebrew..." - /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)" -- --force || true + if [ -x /usr/local/bin/brew ]; then + NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)" || true + fi sudo rm -rf /usr/local/Homebrew sudo rm -rf /usr/local/Cellar - sudo rm -rf /usr/local/bin/brew + sudo rm -rf /usr/local/Caskroom + sudo rm -f /usr/local/bin/brew + fi + if [ -d /usr/local/Homebrew ]; then + echo "ERROR: Failed to remove Homebrew" + exit 1 fi echo "✓ Clean state confirmed"