|
| 1 | +# Switching Between CI Configurations Locally |
| 2 | + |
| 3 | +This guide explains how to switch between different CI test configurations locally to replicate CI failures. |
| 4 | + |
| 5 | +## Quick Start |
| 6 | + |
| 7 | +```bash |
| 8 | +# Check your current configuration |
| 9 | +bin/ci-switch-config status |
| 10 | + |
| 11 | +# Switch to minimum dependencies (Ruby 3.2, Node 20) |
| 12 | +bin/ci-switch-config minimum |
| 13 | + |
| 14 | +# Switch back to latest dependencies (Ruby 3.4, Node 22) |
| 15 | +bin/ci-switch-config latest |
| 16 | +``` |
| 17 | + |
| 18 | +## CI Configurations |
| 19 | + |
| 20 | +The project runs tests against two configurations: |
| 21 | + |
| 22 | +### Latest (Default Development) |
| 23 | + |
| 24 | +- **Ruby**: 3.4 |
| 25 | +- **Node**: 22 |
| 26 | +- **Shakapacker**: 9.3.0 |
| 27 | +- **React**: 19.0.0 |
| 28 | +- **Dependencies**: Latest versions with `--frozen-lockfile` |
| 29 | +- **When it runs**: Always on PRs and master |
| 30 | + |
| 31 | +### Minimum (Compatibility Testing) |
| 32 | + |
| 33 | +- **Ruby**: 3.2 |
| 34 | +- **Node**: 20 |
| 35 | +- **Shakapacker**: 8.2.0 |
| 36 | +- **React**: 18.0.0 |
| 37 | +- **Dependencies**: Minimum supported versions |
| 38 | +- **When it runs**: Only on master branch |
| 39 | + |
| 40 | +## When to Switch Configurations |
| 41 | + |
| 42 | +**Switch to minimum when:** |
| 43 | + |
| 44 | +- CI fails on `dummy-app-integration-tests (3.2, 20, minimum)` but passes on latest |
| 45 | +- You're debugging compatibility with older dependencies |
| 46 | +- You want to verify minimum version support before releasing |
| 47 | + |
| 48 | +**Switch to latest when:** |
| 49 | + |
| 50 | +- You're done testing minimum configuration |
| 51 | +- You want to return to normal development |
| 52 | +- CI failures are on latest configuration |
| 53 | + |
| 54 | +## Prerequisites |
| 55 | + |
| 56 | +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. |
| 57 | + |
| 58 | +```bash |
| 59 | +# Install mise (recommended, modern alternative to asdf) |
| 60 | +brew install mise |
| 61 | +echo 'eval "$(mise activate zsh)"' >> ~/.zshrc |
| 62 | +source ~/.zshrc |
| 63 | + |
| 64 | +# OR install asdf (legacy option) |
| 65 | +brew install asdf |
| 66 | +echo -e "\n. $(brew --prefix asdf)/libexec/asdf.sh" >> ~/.zshrc |
| 67 | +source ~/.zshrc |
| 68 | + |
| 69 | +# Install plugins (only needed for asdf, mise reads from mise.toml) |
| 70 | +asdf plugin add ruby |
| 71 | +asdf plugin add nodejs |
| 72 | +``` |
| 73 | + |
| 74 | +## Detailed Usage |
| 75 | + |
| 76 | +### 1. Check Current Configuration |
| 77 | + |
| 78 | +```bash |
| 79 | +bin/ci-switch-config status |
| 80 | +``` |
| 81 | + |
| 82 | +This shows: |
| 83 | + |
| 84 | +- Current Ruby and Node versions |
| 85 | +- Dependency versions (Shakapacker, React) |
| 86 | +- Which configuration you're currently on |
| 87 | + |
| 88 | +### 2. Switch to Minimum Configuration |
| 89 | + |
| 90 | +```bash |
| 91 | +bin/ci-switch-config minimum |
| 92 | +``` |
| 93 | + |
| 94 | +This will: |
| 95 | + |
| 96 | +1. Create `.tool-versions` with Ruby 3.2.8 and Node 20.18.1 |
| 97 | +2. Run `script/convert` to downgrade dependencies: |
| 98 | + - Shakapacker 9.3.0 → 8.2.0 |
| 99 | + - React 19.0.0 → 18.0.0 |
| 100 | + - Remove ESLint and other packages incompatible with Node 20 |
| 101 | +3. Clean `node_modules` and `yarn.lock` |
| 102 | +4. Reinstall dependencies without `--frozen-lockfile` |
| 103 | +5. Clean and reinstall spec/dummy dependencies |
| 104 | + |
| 105 | +**After switching, run:** |
| 106 | + |
| 107 | +```bash |
| 108 | +# Reload your shell to pick up new Ruby/Node versions |
| 109 | +cd <project-root> |
| 110 | +mise current # or: asdf current |
| 111 | + |
| 112 | +# Build and test |
| 113 | +rake node_package |
| 114 | +cd spec/dummy |
| 115 | +bin/shakapacker-precompile-hook |
| 116 | +RAILS_ENV=test bin/shakapacker |
| 117 | +cd ../.. |
| 118 | +bundle exec rake run_rspec:all_dummy |
| 119 | +``` |
| 120 | + |
| 121 | +### 3. Switch Back to Latest Configuration |
| 122 | + |
| 123 | +```bash |
| 124 | +bin/ci-switch-config latest |
| 125 | +``` |
| 126 | + |
| 127 | +This will: |
| 128 | + |
| 129 | +1. Create `.tool-versions` with Ruby 3.4.3 and Node 22.12.0 |
| 130 | +2. Restore files from git (reverting changes made by `script/convert`) |
| 131 | +3. Clean `node_modules` and `yarn.lock` |
| 132 | +4. Reinstall dependencies with `--frozen-lockfile` |
| 133 | +5. Clean and reinstall spec/dummy dependencies |
| 134 | + |
| 135 | +**After switching, run:** |
| 136 | + |
| 137 | +```bash |
| 138 | +# Reload your shell to pick up new Ruby/Node versions |
| 139 | +cd <project-root> |
| 140 | +mise current # or: asdf current |
| 141 | + |
| 142 | +# Build and test |
| 143 | +rake node_package |
| 144 | +cd spec/dummy |
| 145 | +bin/shakapacker-precompile-hook |
| 146 | +RAILS_ENV=test bin/shakapacker |
| 147 | +cd ../.. |
| 148 | +bundle exec rake run_rspec:all_dummy |
| 149 | +``` |
| 150 | + |
| 151 | +## What Gets Modified |
| 152 | + |
| 153 | +When switching to **minimum**, these files are modified: |
| 154 | + |
| 155 | +- `.tool-versions` - Ruby/Node versions |
| 156 | +- `Gemfile.development_dependencies` - Shakapacker gem version |
| 157 | +- `package.json` - React versions, dev dependencies removed |
| 158 | +- `spec/dummy/package.json` - React and Shakapacker versions |
| 159 | +- `packages/react-on-rails-pro/package.json` - Test scripts modified |
| 160 | +- `node_modules/`, `yarn.lock` - Cleaned and regenerated |
| 161 | +- `spec/dummy/node_modules/`, `spec/dummy/yarn.lock` - Cleaned and regenerated |
| 162 | + |
| 163 | +When switching to **latest**, these files are restored from git. |
| 164 | + |
| 165 | +## Common Workflows |
| 166 | + |
| 167 | +### Debugging a Minimum Config CI Failure |
| 168 | + |
| 169 | +```bash |
| 170 | +# 1. Check current config |
| 171 | +bin/ci-switch-config status |
| 172 | + |
| 173 | +# 2. Switch to minimum |
| 174 | +bin/ci-switch-config minimum |
| 175 | + |
| 176 | +# 3. Reload shell |
| 177 | +cd <project-root> |
| 178 | + |
| 179 | +# 4. Verify versions changed |
| 180 | +ruby --version # Should show 3.2.x |
| 181 | +node --version # Should show v20.x |
| 182 | + |
| 183 | +# 5. Build and test |
| 184 | +rake node_package |
| 185 | +cd spec/dummy |
| 186 | +bin/shakapacker-precompile-hook |
| 187 | +RAILS_ENV=test bin/shakapacker |
| 188 | +cd ../.. |
| 189 | + |
| 190 | +# 6. Run the failing tests |
| 191 | +bundle exec rake run_rspec:all_dummy |
| 192 | + |
| 193 | +# 7. Fix the issue |
| 194 | + |
| 195 | +# 8. Switch back when done |
| 196 | +bin/ci-switch-config latest |
| 197 | +``` |
| 198 | + |
| 199 | +### Quick Test in Both Configurations |
| 200 | + |
| 201 | +```bash |
| 202 | +# Test in latest (current default) |
| 203 | +bin/ci-switch-config status |
| 204 | +bundle exec rake run_rspec:all_dummy |
| 205 | + |
| 206 | +# Switch and test in minimum |
| 207 | +bin/ci-switch-config minimum |
| 208 | +rake node_package |
| 209 | +cd spec/dummy && bin/shakapacker-precompile-hook && RAILS_ENV=test bin/shakapacker && cd ../.. |
| 210 | +bundle exec rake run_rspec:all_dummy |
| 211 | + |
| 212 | +# Switch back |
| 213 | +bin/ci-switch-config latest |
| 214 | +``` |
| 215 | + |
| 216 | +## Troubleshooting |
| 217 | + |
| 218 | +### "No version is set for ruby" or version didn't change |
| 219 | + |
| 220 | +After switching, you need to reload your shell: |
| 221 | + |
| 222 | +```bash |
| 223 | +cd <project-root> |
| 224 | +# The cd command will trigger mise/asdf to load the new versions |
| 225 | +ruby --version # Verify it changed |
| 226 | +``` |
| 227 | + |
| 228 | +### Ruby/Node version didn't change |
| 229 | + |
| 230 | +If your version manager doesn't automatically switch: |
| 231 | + |
| 232 | +**For mise:** |
| 233 | + |
| 234 | +```bash |
| 235 | +mise install # Install missing versions from mise.toml or .tool-versions |
| 236 | +``` |
| 237 | + |
| 238 | +**For asdf:** |
| 239 | + |
| 240 | +```bash |
| 241 | +asdf install # Install missing versions from .tool-versions |
| 242 | +asdf reshim ruby |
| 243 | +asdf reshim nodejs |
| 244 | +``` |
| 245 | + |
| 246 | +### Yarn install fails |
| 247 | + |
| 248 | +If you get package resolution errors: |
| 249 | + |
| 250 | +```bash |
| 251 | +# Clean everything and try again |
| 252 | +rm -rf node_modules yarn.lock spec/dummy/node_modules spec/dummy/yarn.lock |
| 253 | +yarn install |
| 254 | +cd spec/dummy && yarn install |
| 255 | +``` |
| 256 | + |
| 257 | +### Git complains about modified files |
| 258 | + |
| 259 | +The script will warn you if you have uncommitted changes. You can: |
| 260 | + |
| 261 | +- Commit or stash your changes first, OR |
| 262 | +- Proceed (script will ask for confirmation) |
| 263 | + |
| 264 | +### Switching back doesn't restore everything |
| 265 | + |
| 266 | +If `git restore` doesn't work: |
| 267 | + |
| 268 | +```bash |
| 269 | +# Manually restore from git |
| 270 | +git restore Gemfile.development_dependencies package.json spec/dummy/package.json packages/react-on-rails-pro/package.json |
| 271 | + |
| 272 | +# Then run latest again |
| 273 | +bin/ci-switch-config latest |
| 274 | +``` |
| 275 | + |
| 276 | +## Integration with CI Debugging Tools |
| 277 | + |
| 278 | +This script works well with the other CI debugging tools: |
| 279 | + |
| 280 | +```bash |
| 281 | +# 1. Check what failed in CI |
| 282 | +bin/ci-rerun-failures |
| 283 | + |
| 284 | +# 2. If it's a minimum config failure, switch |
| 285 | +bin/ci-switch-config minimum |
| 286 | + |
| 287 | +# 3. Run the specific failing tests |
| 288 | +pbpaste | bin/ci-run-failed-specs |
| 289 | + |
| 290 | +# 4. Switch back when done |
| 291 | +bin/ci-switch-config latest |
| 292 | +``` |
| 293 | + |
| 294 | +## See Also |
| 295 | + |
| 296 | +- `CLAUDE.md` - Main development guide with CI debugging info |
| 297 | +- `bin/ci-rerun-failures` - Re-run only failed CI jobs locally |
| 298 | +- `bin/ci-run-failed-specs` - Run specific failing RSpec examples |
| 299 | +- `bin/ci-local` - Smart test detection based on changes |
0 commit comments