diff --git a/SWITCHING_CI_CONFIGS.md b/SWITCHING_CI_CONFIGS.md index 6bd8f4293e..6eeb1d0ad5 100644 --- a/SWITCHING_CI_CONFIGS.md +++ b/SWITCHING_CI_CONFIGS.md @@ -53,24 +53,53 @@ The project runs tests against two configurations: ## Prerequisites -You must have a version manager like [mise](https://mise.jdx.dev/) (recommended) or [asdf](https://asdf-vm.com/) installed to manage Ruby and Node versions. +You must have a version manager installed to manage Ruby and Node versions. The script supports: + +- **[mise](https://mise.jdx.dev/)** - Recommended, modern, manages both Ruby and Node +- **[asdf](https://asdf-vm.com/)** - Legacy option, manages both Ruby and Node +- **[rvm](https://rvm.io/) + [nvm](https://github.com/nvm-sh/nvm)** - Separate managers for Ruby and Node + +### Option 1: mise (Recommended) ```bash -# Install mise (recommended, modern alternative to asdf) +# Install mise brew install mise echo 'eval "$(mise activate zsh)"' >> ~/.zshrc source ~/.zshrc -# OR install asdf (legacy option) +# mise automatically reads from .tool-versions +``` + +### Option 2: asdf + +```bash +# Install asdf brew install asdf echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ~/.zshrc source ~/.zshrc -# Install plugins (only needed for asdf, mise reads from mise.toml) +# Install plugins asdf plugin add ruby asdf plugin add nodejs ``` +### Option 3: rvm + nvm + +```bash +# Install rvm for Ruby +\curl -sSL https://get.rvm.io | bash -s stable +source ~/.rvm/scripts/rvm + +# Install nvm for Node +curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash +# Add to shell config (the installer usually does this automatically) +``` + +**Important Notes:** + +- If you only have rvm (no nvm) or only nvm (no rvm), the script will detect this and provide helpful error messages guiding you to install the missing manager or switch to mise/asdf. +- **Do not mix version managers** (e.g., don't install both mise and rvm). The script prioritizes mise > asdf > rvm+nvm, so mise/asdf will always take precedence. Using multiple managers can cause confusion about which versions are active. + ## Detailed Usage ### 1. Check Current Configuration @@ -107,7 +136,9 @@ This will: ```bash # Reload your shell to pick up new Ruby/Node versions cd -mise current # or: asdf current +mise current # For mise users +# asdf current # For asdf users +# rvm current && nvm current # For rvm+nvm users # Build and test rake node_package @@ -137,7 +168,9 @@ This will: ```bash # Reload your shell to pick up new Ruby/Node versions cd -mise current # or: asdf current +mise current # For mise users +# asdf current # For asdf users +# rvm current && nvm current # For rvm+nvm users # Build and test rake node_package @@ -243,6 +276,22 @@ asdf reshim ruby asdf reshim nodejs ``` +**For rvm + nvm:** + +```bash +# Install and use specific Ruby version +rvm install 3.2.8 # or 3.4.3 +rvm use 3.2.8 + +# Install and use specific Node version +nvm install 20.18.1 # or 22.12.0 +nvm use 20.18.1 + +# Verify versions +ruby --version +node --version +``` + ### Yarn install fails If you get package resolution errors: diff --git a/bin/ci-switch-config b/bin/ci-switch-config index 18a90d9851..3c969ffc73 100755 --- a/bin/ci-switch-config +++ b/bin/ci-switch-config @@ -39,14 +39,120 @@ check_version_manager() { echo "mise" elif command -v asdf &> /dev/null; then echo "asdf" + elif command -v rvm &> /dev/null && command -v nvm &> /dev/null; then + echo "rvm+nvm" + elif command -v rvm &> /dev/null; then + echo "rvm" + elif command -v nvm &> /dev/null; then + echo "nvm" else - print_error "No version manager found. Please install mise or asdf:" + print_error "No version manager found. Please install one of:" echo " mise (recommended): https://mise.jdx.dev/" - echo " asdf (legacy): https://asdf-vm.com/" + echo " asdf: https://asdf-vm.com/" + echo " rvm + nvm: https://rvm.io/ + https://github.com/nvm-sh/nvm" exit 1 fi } +set_ruby_version() { + local version="$1" + local version_manager="$2" + + case "$version_manager" in + mise|asdf) + # Handled via .tool-versions + ;; + rvm|rvm+nvm) + print_header "Setting Ruby $version with rvm" + # Check if version exists using rvm list rubies for consistent output + # Anchor to start of line to avoid false matches (e.g., 3.2.8 shouldn't match 13.2.8) + # Allow optional leading whitespace and ruby- prefix, no end anchor to allow patch suffixes + if ! rvm list rubies | grep -qE "^[[:space:]]*(ruby-)?${version}"; then + print_warning "Ruby $version not installed. Installing..." + if ! rvm install "$version"; then + print_error "Failed to install Ruby $version with rvm" + print_warning "Make sure rvm is properly configured. Try running: source ~/.rvm/scripts/rvm" + exit 1 + fi + fi + if ! rvm use "$version"; then + print_error "Failed to switch to Ruby $version" + print_warning "Make sure rvm is properly configured. Try running: source ~/.rvm/scripts/rvm" + exit 1 + fi + print_success "Switched to Ruby $version" + ;; + nvm) + print_error "Cannot set Ruby version: nvm doesn't manage Ruby" + echo "Please install one of the following to manage Ruby versions:" + echo " - rvm: https://rvm.io/" + echo " - mise: https://mise.jdx.dev/ (recommended, manages both Ruby and Node)" + echo " - asdf: https://asdf-vm.com/ (manages both Ruby and Node)" + exit 1 + ;; + esac +} + +set_node_version() { + local version="$1" + local version_manager="$2" + + case "$version_manager" in + mise|asdf) + # Handled via .tool-versions + ;; + nvm|rvm+nvm) + print_header "Setting Node $version with nvm" + + # Source nvm if not already loaded - try multiple common locations + if ! command -v nvm &> /dev/null; then + # Try standard nvm location + if [ -s "$HOME/.nvm/nvm.sh" ]; then + export NVM_DIR="$HOME/.nvm" + \. "$NVM_DIR/nvm.sh" + # Try Homebrew location (macOS) + elif [ -s "/opt/homebrew/opt/nvm/nvm.sh" ]; then + export NVM_DIR="/opt/homebrew/opt/nvm" + \. "/opt/homebrew/opt/nvm/nvm.sh" + # Try XDG config location + elif [ -s "${XDG_CONFIG_HOME:-$HOME/.config}/nvm/nvm.sh" ]; then + export NVM_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/nvm" + \. "$NVM_DIR/nvm.sh" + else + print_error "Could not find nvm installation" + print_warning "Tried locations: ~/.nvm, /opt/homebrew/opt/nvm, ~/.config/nvm" + echo "Please source nvm manually or install it from: https://github.com/nvm-sh/nvm" + exit 1 + fi + fi + + # Check if version is already installed using nvm version for reliability + if ! nvm version "$version" &> /dev/null; then + print_warning "Node $version not installed. Installing..." + if ! nvm install "$version"; then + print_error "Failed to install Node $version with nvm" + exit 1 + fi + fi + + if ! nvm use "$version"; then + print_error "Failed to switch to Node $version" + print_warning "Make sure nvm is properly configured. Try running: nvm use $version" + exit 1 + fi + print_success "Switched to Node $version" + ;; + rvm) + print_error "Cannot set Node version: rvm doesn't manage Node" + echo "Please install one of the following to manage Node versions:" + echo " - nvm: https://github.com/nvm-sh/nvm" + echo " - mise: https://mise.jdx.dev/ (recommended, manages both Ruby and Node)" + echo " - asdf: https://asdf-vm.com/ (manages both Ruby and Node)" + exit 1 + ;; + esac +} + show_status() { print_header "Current Configuration" echo "" @@ -121,12 +227,32 @@ switch_to_minimum() { fi # Set Ruby and Node versions - print_header "Setting runtime versions in .tool-versions" - cat > "$PROJECT_ROOT/.tool-versions" < "$PROJECT_ROOT/.tool-versions" < "$PROJECT_ROOT/.ruby-version" + print_success "Created .ruby-version with Ruby 3.2.8" + ;; + esac + + case "$VERSION_MANAGER" in + nvm|rvm+nvm) + print_header "Creating .nvmrc for nvm" + echo "20.18.1" > "$PROJECT_ROOT/.nvmrc" + print_success "Created .nvmrc with Node 20.18.1" + ;; + esac + + set_ruby_version "3.2.8" "$VERSION_MANAGER" + set_node_version "20.18.1" "$VERSION_MANAGER" # Run conversion script print_header "Running script/convert to downgrade dependencies" @@ -158,22 +284,60 @@ EOF # Reload version manager to pick up new versions print_header "Reloading $VERSION_MANAGER to use new versions" - if [[ "$VERSION_MANAGER" == "mise" ]]; then - # mise will auto-detect .tool-versions on next cd - : - elif [ -f "$HOME/.asdf/asdf.sh" ]; then - source "$HOME/.asdf/asdf.sh" - fi + case "$VERSION_MANAGER" in + mise) + # mise will auto-detect .tool-versions on next cd + ;; + asdf) + # Note: This only affects the script's subshell, not the user's current shell + if [ -f "$HOME/.asdf/asdf.sh" ]; then + source "$HOME/.asdf/asdf.sh" + fi + ;; + rvm|rvm+nvm) + # Versions already set via rvm use + ;; + nvm) + # Version already set via nvm use + ;; + esac echo "" print_success "Switched to MINIMUM configuration" - print_warning "Run these commands to reload your shell and verify:" + + case "$VERSION_MANAGER" in + rvm+nvm|rvm|nvm) + print_warning "IMPORTANT: Version changes in this script don't persist to your current shell." + print_warning "The rvm/nvm commands run in a subshell and cannot affect your terminal." + echo "" + print_warning "Choose one of these options to activate the new versions:" + echo " Option 1 (Recommended): Open a new terminal and cd into the project" + echo " Option 2: Source your shell config:" + [ "$VERSION_MANAGER" = "rvm" ] || [ "$VERSION_MANAGER" = "rvm+nvm" ] && echo " source ~/.rvm/scripts/rvm" + [ "$VERSION_MANAGER" = "nvm" ] || [ "$VERSION_MANAGER" = "rvm+nvm" ] && echo " source \$NVM_DIR/nvm.sh" + echo "" + ;; + esac + + print_warning "After activating versions, verify with:" echo " cd $PROJECT_ROOT" - if [[ "$VERSION_MANAGER" == "mise" ]]; then - echo " mise current" - else - echo " asdf current" - fi + case "$VERSION_MANAGER" in + mise) + echo " mise current" + ;; + asdf) + echo " asdf current" + ;; + rvm+nvm) + echo " rvm current && nvm current" + ;; + rvm) + echo " rvm current" + ;; + nvm) + echo " nvm current" + ;; + esac echo "" print_warning "Next steps to build and test:" echo " rake node_package" @@ -201,12 +365,32 @@ restore_to_latest() { fi # Set Ruby and Node versions - print_header "Setting runtime versions in .tool-versions" - cat > "$PROJECT_ROOT/.tool-versions" < "$PROJECT_ROOT/.tool-versions" < "$PROJECT_ROOT/.ruby-version" + print_success "Created .ruby-version with Ruby 3.4.3" + ;; + esac + + case "$VERSION_MANAGER" in + nvm|rvm+nvm) + print_header "Creating .nvmrc for nvm" + echo "22.12.0" > "$PROJECT_ROOT/.nvmrc" + print_success "Created .nvmrc with Node 22.12.0" + ;; + esac + + set_ruby_version "3.4.3" "$VERSION_MANAGER" + set_node_version "22.12.0" "$VERSION_MANAGER" # Restore files from git print_header "Restoring dependency files from git" @@ -238,22 +422,60 @@ EOF # Reload version manager to pick up new versions print_header "Reloading $VERSION_MANAGER to use new versions" - if [[ "$VERSION_MANAGER" == "mise" ]]; then - # mise will auto-detect .tool-versions on next cd - : - elif [ -f "$HOME/.asdf/asdf.sh" ]; then - source "$HOME/.asdf/asdf.sh" - fi + case "$VERSION_MANAGER" in + mise) + # mise will auto-detect .tool-versions on next cd + ;; + asdf) + # Note: This only affects the script's subshell, not the user's current shell + if [ -f "$HOME/.asdf/asdf.sh" ]; then + source "$HOME/.asdf/asdf.sh" + fi + ;; + rvm|rvm+nvm) + # Versions already set via rvm use + ;; + nvm) + # Version already set via nvm use + ;; + esac echo "" print_success "Restored to LATEST configuration" - print_warning "Run these commands to reload your shell and verify:" + + case "$VERSION_MANAGER" in + rvm+nvm|rvm|nvm) + print_warning "IMPORTANT: Version changes in this script don't persist to your current shell." + print_warning "The rvm/nvm commands run in a subshell and cannot affect your terminal." + echo "" + print_warning "Choose one of these options to activate the new versions:" + echo " Option 1 (Recommended): Open a new terminal and cd into the project" + echo " Option 2: Source your shell config:" + [ "$VERSION_MANAGER" = "rvm" ] || [ "$VERSION_MANAGER" = "rvm+nvm" ] && echo " source ~/.rvm/scripts/rvm" + [ "$VERSION_MANAGER" = "nvm" ] || [ "$VERSION_MANAGER" = "rvm+nvm" ] && echo " source \$NVM_DIR/nvm.sh" + echo "" + ;; + esac + + print_warning "After activating versions, verify with:" echo " cd $PROJECT_ROOT" - if [[ "$VERSION_MANAGER" == "mise" ]]; then - echo " mise current" - else - echo " asdf current" - fi + case "$VERSION_MANAGER" in + mise) + echo " mise current" + ;; + asdf) + echo " asdf current" + ;; + rvm+nvm) + echo " rvm current && nvm current" + ;; + rvm) + echo " rvm current" + ;; + nvm) + echo " nvm current" + ;; + esac echo "" print_warning "Next steps to build and test:" echo " rake node_package"