Skip to content

Add Homebrew Utilities Migration with Bash and Comprehensive Testing#17

Merged
ooloth merged 2 commits intomainfrom
feature/homebrew-utils-bash
Jul 11, 2025
Merged

Add Homebrew Utilities Migration with Bash and Comprehensive Testing#17
ooloth merged 2 commits intomainfrom
feature/homebrew-utils-bash

Conversation

@ooloth
Copy link
Owner

@ooloth ooloth commented Jul 10, 2025

💪 What

Homebrew Utilities Migration: Complete migration of Homebrew functionality from zsh to bash following the established bash migration pattern.

Files Changed

  • lib/homebrew-utils.bash - Core Homebrew utility functions with zero shellcheck warnings
  • test/install/test-homebrew-utils.bats - Comprehensive unit tests (9 test cases, all passing)
  • bin/install/homebrew.bash - Installation script using shared utilities

New Functionality

  • get_homebrew_prefix() - Architecture-specific Homebrew prefix detection (Apple Silicon vs Intel)
  • ensure_homebrew_in_path() - Smart PATH management without duplication
  • is_homebrew_package_installed() - Package installation checking
  • detect_homebrew(), get_homebrew_version(), validate_homebrew_installation() - Existing functions migrated

🤔 Why

Phase 1 of bash migration project: Extract shared Homebrew utilities that are reused across multiple installation scripts, following the successful patterns established in GitHub and SSH utility migrations.

Benefits demonstrated:

  • Industry-standard tooling - Shellcheck compliance and bats testing
  • Comprehensive test coverage - All functions tested with edge cases
  • Architecture awareness - Proper Apple Silicon vs Intel detection
  • Zero regressions - Maintains all existing functionality while improving code quality

👀 Usage

Installation script usage:

# Install Homebrew and Brewfile packages
./bin/install/homebrew.bash install

# Update existing Homebrew installation
./bin/install/homebrew.bash update

# Install only Brewfile packages
./bin/install/homebrew.bash packages

Utility functions for other scripts:

source "$DOTFILES_ROOT/lib/homebrew-utils.bash"

if detect_homebrew; then
    ensure_homebrew_in_path
    if is_homebrew_package_installed "git"; then
        echo "Git is available via Homebrew"
    fi
fi

👩‍🔬 How to validate

Run all unit tests:

./test/run-tests.zsh test-homebrew-utils
# OR
bats test/install/test-homebrew-utils.bats

Test installation script:

# Dry run to see what would happen
DRY_RUN=true ./bin/install/homebrew.bash install

# Test architecture detection
./lib/homebrew-utils.bash
get_homebrew_prefix  # Should return /opt/homebrew or /usr/local

Verify shellcheck compliance:

shellcheck lib/homebrew-utils.bash
shellcheck bin/install/homebrew.bash

All tests pass, zero shellcheck warnings, and maintains feature parity with original zsh implementation.

🔗 Related links

- Create lib/homebrew-utils.bash with core Homebrew functions
- Add get_homebrew_prefix() for architecture-specific paths
- Add ensure_homebrew_in_path() for PATH management
- Add is_homebrew_package_installed() for package checking
- Add comprehensive unit tests with 9 test cases covering all functions
- Add bin/install/homebrew.bash installation script
- Follow established bash migration pattern with zero shellcheck warnings
- All unit tests pass, demonstrates working functionality
@ooloth ooloth marked this pull request as ready for review July 11, 2025 03:22
@ooloth ooloth merged commit 62c5479 into main Jul 11, 2025
1 check passed
@ooloth ooloth deleted the feature/homebrew-utils-bash branch July 11, 2025 03:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant