Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
58 changes: 52 additions & 6 deletions SWITCHING_CI_CONFIGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,50 @@ 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)
```

**Note:** 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.

## Detailed Usage

### 1. Check Current Configuration
Expand Down Expand Up @@ -107,7 +133,9 @@ This will:
```bash
# Reload your shell to pick up new Ruby/Node versions
cd <project-root>
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
Expand Down Expand Up @@ -137,7 +165,9 @@ This will:
```bash
# Reload your shell to pick up new Ruby/Node versions
cd <project-root>
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
Expand Down Expand Up @@ -243,6 +273,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:
Expand Down
236 changes: 206 additions & 30 deletions bin/ci-switch-config
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,118 @@ 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
if ! rvm list rubies | grep -qE "(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 ""
Expand Down Expand Up @@ -121,12 +225,17 @@ switch_to_minimum() {
fi

# Set Ruby and Node versions
print_header "Setting runtime versions in .tool-versions"
cat > "$PROJECT_ROOT/.tool-versions" <<EOF
if [[ "$VERSION_MANAGER" == "mise" ]] || [[ "$VERSION_MANAGER" == "asdf" ]]; then
print_header "Setting runtime versions in .tool-versions"
cat > "$PROJECT_ROOT/.tool-versions" <<EOF
ruby 3.2.8
nodejs 20.18.1
EOF
print_success "Created .tool-versions with Ruby 3.2.8 and Node 20.18.1"
print_success "Created .tool-versions with Ruby 3.2.8 and Node 20.18.1"
fi

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"
Expand Down Expand Up @@ -158,22 +267,53 @@ 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"

case "$VERSION_MANAGER" in
rvm+nvm|rvm|nvm)
print_warning "Note: Version changes only affect this script's subshell."
print_warning "You may need to open a new terminal or source your shell config."
;;
esac

print_warning "Run these commands to reload your shell and verify:"
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"
Expand Down Expand Up @@ -201,12 +341,17 @@ restore_to_latest() {
fi

# Set Ruby and Node versions
print_header "Setting runtime versions in .tool-versions"
cat > "$PROJECT_ROOT/.tool-versions" <<EOF
if [[ "$VERSION_MANAGER" == "mise" ]] || [[ "$VERSION_MANAGER" == "asdf" ]]; then
print_header "Setting runtime versions in .tool-versions"
cat > "$PROJECT_ROOT/.tool-versions" <<EOF
ruby 3.4.3
nodejs 22.12.0
EOF
print_success "Created .tool-versions with Ruby 3.4.3 and Node 22.12.0"
print_success "Created .tool-versions with Ruby 3.4.3 and Node 22.12.0"
fi

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"
Expand Down Expand Up @@ -238,22 +383,53 @@ 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"

case "$VERSION_MANAGER" in
rvm+nvm|rvm|nvm)
print_warning "Note: Version changes only affect this script's subshell."
print_warning "You may need to open a new terminal or source your shell config."
;;
esac

print_warning "Run these commands to reload your shell and verify:"
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"
Expand Down