Skip to content

Commit 06b7927

Browse files
justin808claude
andcommitted
Add .ruby-version/.nvmrc support and enhance UX warnings
Based on final code review feedback: **Version File Management:** - Create .ruby-version for rvm users (enables auto-switching on cd) - Create .nvmrc for nvm users (enables auto-switching on cd) - Maintains .tool-versions for mise/asdf users - Allows users to leverage each manager's native auto-switching features **Improved Version Matching:** - Fix rvm version check to avoid partial matches (3.2.8 won't match 3.2.80) - Use word boundaries in grep pattern for exact version matching **Enhanced User Warnings:** - Make subshell limitation warnings more explicit and prominent - Explain WHY versions don't persist (subshell vs. parent shell) - Provide clear, actionable steps with two distinct options: 1. Open new terminal (recommended) 2. Source shell config files (with exact commands) - Show appropriate sourcing commands based on version manager **Documentation:** - Add warning about not mixing version managers (mise + rvm, etc.) - Explain version manager priority (mise > asdf > rvm+nvm) - Clarify potential confusion from using multiple managers These changes make the script more user-friendly by enabling native auto-switching features and setting much clearer expectations about how version changes work with rvm/nvm. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent e133a13 commit 06b7927

File tree

2 files changed

+66
-18
lines changed

2 files changed

+66
-18
lines changed

SWITCHING_CI_CONFIGS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
9595
# Add to shell config (the installer usually does this automatically)
9696
```
9797

98-
**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.
98+
**Important Notes:**
99+
100+
- 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.
101+
- **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.
99102

100103
## Detailed Usage
101104

bin/ci-switch-config

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ set_ruby_version() {
6565
rvm|rvm+nvm)
6666
print_header "Setting Ruby $version with rvm"
6767
# Check if version exists using rvm list rubies for consistent output
68-
if ! rvm list rubies | grep -qE "(ruby-)?${version}"; then
68+
# Use word boundaries to avoid matching partial versions (e.g., 3.2.8 shouldn't match 3.2.80)
69+
if ! rvm list rubies | grep -qE "(ruby-)?${version}([[:space:]]|$)"; then
6970
print_warning "Ruby $version not installed. Installing..."
7071
if ! rvm install "$version"; then
7172
print_error "Failed to install Ruby $version with rvm"
@@ -225,14 +226,29 @@ switch_to_minimum() {
225226
fi
226227

227228
# Set Ruby and Node versions
228-
if [[ "$VERSION_MANAGER" == "mise" ]] || [[ "$VERSION_MANAGER" == "asdf" ]]; then
229-
print_header "Setting runtime versions in .tool-versions"
230-
cat > "$PROJECT_ROOT/.tool-versions" <<EOF
229+
case "$VERSION_MANAGER" in
230+
mise|asdf)
231+
print_header "Setting runtime versions in .tool-versions"
232+
cat > "$PROJECT_ROOT/.tool-versions" <<EOF
231233
ruby 3.2.8
232234
nodejs 20.18.1
233235
EOF
234-
print_success "Created .tool-versions with Ruby 3.2.8 and Node 20.18.1"
235-
fi
236+
print_success "Created .tool-versions with Ruby 3.2.8 and Node 20.18.1"
237+
;;
238+
rvm|rvm+nvm)
239+
print_header "Creating .ruby-version for rvm"
240+
echo "3.2.8" > "$PROJECT_ROOT/.ruby-version"
241+
print_success "Created .ruby-version with Ruby 3.2.8"
242+
;;
243+
esac
244+
245+
case "$VERSION_MANAGER" in
246+
nvm|rvm+nvm)
247+
print_header "Creating .nvmrc for nvm"
248+
echo "20.18.1" > "$PROJECT_ROOT/.nvmrc"
249+
print_success "Created .nvmrc with Node 20.18.1"
250+
;;
251+
esac
236252

237253
set_ruby_version "3.2.8" "$VERSION_MANAGER"
238254
set_node_version "20.18.1" "$VERSION_MANAGER"
@@ -290,12 +306,19 @@ EOF
290306

291307
case "$VERSION_MANAGER" in
292308
rvm+nvm|rvm|nvm)
293-
print_warning "Note: Version changes only affect this script's subshell."
294-
print_warning "You may need to open a new terminal or source your shell config."
309+
print_warning "IMPORTANT: Version changes in this script don't persist to your current shell."
310+
print_warning "The rvm/nvm commands run in a subshell and cannot affect your terminal."
311+
echo ""
312+
print_warning "Choose one of these options to activate the new versions:"
313+
echo " Option 1 (Recommended): Open a new terminal and cd into the project"
314+
echo " Option 2: Source your shell config:"
315+
[ "$VERSION_MANAGER" = "rvm" ] || [ "$VERSION_MANAGER" = "rvm+nvm" ] && echo " source ~/.rvm/scripts/rvm"
316+
[ "$VERSION_MANAGER" = "nvm" ] || [ "$VERSION_MANAGER" = "rvm+nvm" ] && echo " source \$NVM_DIR/nvm.sh"
317+
echo ""
295318
;;
296319
esac
297320

298-
print_warning "Run these commands to reload your shell and verify:"
321+
print_warning "After activating versions, verify with:"
299322
echo " cd $PROJECT_ROOT"
300323
case "$VERSION_MANAGER" in
301324
mise)
@@ -341,14 +364,29 @@ restore_to_latest() {
341364
fi
342365

343366
# Set Ruby and Node versions
344-
if [[ "$VERSION_MANAGER" == "mise" ]] || [[ "$VERSION_MANAGER" == "asdf" ]]; then
345-
print_header "Setting runtime versions in .tool-versions"
346-
cat > "$PROJECT_ROOT/.tool-versions" <<EOF
367+
case "$VERSION_MANAGER" in
368+
mise|asdf)
369+
print_header "Setting runtime versions in .tool-versions"
370+
cat > "$PROJECT_ROOT/.tool-versions" <<EOF
347371
ruby 3.4.3
348372
nodejs 22.12.0
349373
EOF
350-
print_success "Created .tool-versions with Ruby 3.4.3 and Node 22.12.0"
351-
fi
374+
print_success "Created .tool-versions with Ruby 3.4.3 and Node 22.12.0"
375+
;;
376+
rvm|rvm+nvm)
377+
print_header "Creating .ruby-version for rvm"
378+
echo "3.4.3" > "$PROJECT_ROOT/.ruby-version"
379+
print_success "Created .ruby-version with Ruby 3.4.3"
380+
;;
381+
esac
382+
383+
case "$VERSION_MANAGER" in
384+
nvm|rvm+nvm)
385+
print_header "Creating .nvmrc for nvm"
386+
echo "22.12.0" > "$PROJECT_ROOT/.nvmrc"
387+
print_success "Created .nvmrc with Node 22.12.0"
388+
;;
389+
esac
352390

353391
set_ruby_version "3.4.3" "$VERSION_MANAGER"
354392
set_node_version "22.12.0" "$VERSION_MANAGER"
@@ -406,12 +444,19 @@ EOF
406444

407445
case "$VERSION_MANAGER" in
408446
rvm+nvm|rvm|nvm)
409-
print_warning "Note: Version changes only affect this script's subshell."
410-
print_warning "You may need to open a new terminal or source your shell config."
447+
print_warning "IMPORTANT: Version changes in this script don't persist to your current shell."
448+
print_warning "The rvm/nvm commands run in a subshell and cannot affect your terminal."
449+
echo ""
450+
print_warning "Choose one of these options to activate the new versions:"
451+
echo " Option 1 (Recommended): Open a new terminal and cd into the project"
452+
echo " Option 2: Source your shell config:"
453+
[ "$VERSION_MANAGER" = "rvm" ] || [ "$VERSION_MANAGER" = "rvm+nvm" ] && echo " source ~/.rvm/scripts/rvm"
454+
[ "$VERSION_MANAGER" = "nvm" ] || [ "$VERSION_MANAGER" = "rvm+nvm" ] && echo " source \$NVM_DIR/nvm.sh"
455+
echo ""
411456
;;
412457
esac
413458

414-
print_warning "Run these commands to reload your shell and verify:"
459+
print_warning "After activating versions, verify with:"
415460
echo " cd $PROJECT_ROOT"
416461
case "$VERSION_MANAGER" in
417462
mise)

0 commit comments

Comments
 (0)