-
Notifications
You must be signed in to change notification settings - Fork 0
Add Conductor configuration for Rails workspace setup #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Added conductor.json with setup, run, and archive scripts - Created conductor-setup.sh script that: - Loads mise for Ruby version management - Verifies Ruby 3.2.0+ is available - Installs Ruby gem dependencies - Copies .env files from root if present - Clears logs and temp files - Configured nonconcurrent run mode for Rails server 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
WalkthroughIntroduces a new setup script and a coordinator config. The script validates Ruby/Bundler, optionally activates a mise environment, provisions .env files, installs gems, clears logs/tmp via Rails tasks, and exits on errors. The config maps setup/run/archive commands and specifies nonconcurrent run mode. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Dev as Developer
participant Sh as Shell
participant CS as conductor-setup.sh
participant Env as mise (optional)
participant RB as ruby/bundler
participant RL as bin/rails
Dev->>Sh: run ./conductor-setup.sh
Sh->>CS: execute
Note over CS: set -e
CS->>Env: activate if available
alt mise found
Env-->>CS: environment activated
else
CS-->>CS: continue without mise
end
CS->>RB: check ruby version (>=3.2.0)
RB-->>CS: version OK or fail (exit)
CS->>RB: check bundler presence
RB-->>CS: OK or fail (exit)
CS->>CS: copy .env/.env.local if present
CS->>RB: bundle install
RB-->>CS: dependencies installed
CS->>RL: rails log:clear tmp:clear
RL-->>CS: cleanup done
CS-->>Sh: success message
Sh-->>Dev: done
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Nitpick comments (7)
conductor-setup.sh (6)
2-2
: Harden shell options for safer failuresUse stricter flags to catch unset vars and pipeline failures.
-set -e # Exit on any error +set -Eeuo pipefail # safer: errtrace, nounset, pipefail +IFS=$'\n\t' +trap 'echo "Setup failed on line $LINENO"; exit 1' ERR
17-25
: Avoid hard‑coding framework version in error textMessage mentions “Rails 8.0.3” but requirement is generic (>= 3.2.0). Derive required Ruby from
.ruby-version
orGemfile
when present to keep it single‑sourced.-REQUIRED_VERSION="3.2.0" +# Prefer repo-defined version if available +if [ -f .ruby-version ]; then + REQUIRED_VERSION="$(tr -d ' \r\n' < .ruby-version)" +else + REQUIRED_VERSION="${REQUIRED_VERSION:-3.2.0}" +fi
27-30
: Self‑heal Bundler if missingInstead of just failing, install bundler (optionally to the version in Gemfile.lock).
-if ! command -v bundle &> /dev/null; then - echo "❌ Bundler is not installed. Please install Bundler first." - exit 1 -fi +if ! command -v bundle &> /dev/null; then + echo "📦 Installing Bundler..." + # Use version from Gemfile.lock if present + BUNDLER_VERSION="$(awk '/^BUNDLED WITH/{getline; gsub(/^[ \t]+/,""); print; exit}' Gemfile.lock 2>/dev/null || true)" + if [ -n "${BUNDLER_VERSION:-}" ]; then + gem install bundler -v "$BUNDLER_VERSION" + else + gem install bundler + fi +fi
44-46
: Avoid redundant installs; speed up with bundle check and parallelismUse
bundle check
beforeinstall
and enable jobs for faster installs.-echo "📦 Installing Ruby gems..." -bundle install +echo "📦 Installing Ruby gems..." +bundle check || bundle install --jobs="$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 4)"
48-49
: Guard Rails tasks callSkip cleanup gracefully if bin/rails isn’t present/executable yet.
-echo "🧹 Cleaning logs and temp files..." -bin/rails log:clear tmp:clear +echo "🧹 Cleaning logs and temp files..." +if [ -x bin/rails ]; then + bin/rails log:clear tmp:clear +else + echo "ℹ️ bin/rails not found; skipping log/tmp cleanup." +fi
6-9
: Optional: confirm active toolchain after mise activationPrint the resolved Ruby and Bundler versions to aid debugging.
if command -v mise &> /dev/null; then eval "$(mise activate bash)" fi +echo "Using: $(ruby -v)" +echo "Bundler: $(bundle -v 2>/dev/null || echo 'not installed')"conductor.json (1)
5-6
: Avoid empty archive commandEither omit
archive
or implement a noop (e.g.,true
) to reduce ambiguity in tooling that executes all script keys."scripts": { "setup": "./conductor-setup.sh", "run": "bin/dev", - "archive": "" + // "archive": "true" },
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
conductor-setup.sh
(1 hunks)conductor.json
(1 hunks)
🔇 Additional comments (1)
conductor.json (1)
7-7
: Nonconcurrent run mode: good choicePrevents duplicate Rails servers; keep as-is.
echo "🚀 Setting up Rails workspace..." | ||
|
||
# Load mise if available | ||
if command -v mise &> /dev/null; then | ||
eval "$(mise activate bash)" | ||
fi | ||
|
||
# Check for required tools | ||
if ! command -v ruby &> /dev/null; then | ||
echo "❌ Ruby is not installed. Please install Ruby first." | ||
exit 1 | ||
fi | ||
|
||
# Check Ruby version | ||
RUBY_VERSION=$(ruby -v | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1) | ||
REQUIRED_VERSION="3.2.0" | ||
|
||
if [ "$(printf '%s\n' "$REQUIRED_VERSION" "$RUBY_VERSION" | sort -V | head -n1)" != "$REQUIRED_VERSION" ]; then | ||
echo "❌ Ruby version $RUBY_VERSION is too old. Rails 8.0.3 requires Ruby >= $REQUIRED_VERSION" | ||
echo " Please update Ruby using a version manager like rbenv, rvm, or asdf." | ||
exit 1 | ||
fi | ||
|
||
if ! command -v bundle &> /dev/null; then | ||
echo "❌ Bundler is not installed. Please install Bundler first." | ||
exit 1 | ||
fi | ||
|
||
# Copy environment files from root if they exist | ||
if [ -f "$CONDUCTOR_ROOT_PATH/.env" ]; then | ||
echo "📋 Copying .env file from root..." | ||
cp "$CONDUCTOR_ROOT_PATH/.env" .env | ||
fi | ||
|
||
if [ -f "$CONDUCTOR_ROOT_PATH/.env.local" ]; then | ||
echo "📋 Copying .env.local file from root..." | ||
cp "$CONDUCTOR_ROOT_PATH/.env.local" .env.local | ||
fi | ||
|
||
# Install Ruby dependencies | ||
echo "📦 Installing Ruby gems..." | ||
bundle install | ||
|
||
# Clear logs and temp files | ||
echo "🧹 Cleaning logs and temp files..." | ||
bin/rails log:clear tmp:clear | ||
|
||
echo "✅ Setup complete! Click the Run button to start the Rails server." No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
🧩 Analysis chain
Overall: solid flow; minor polish will improve portability and safety
Nice linear setup with clear messages. Address the above to make it cross‑platform and idempotent.
Run this script to validate assumptions and files:
🏁 Script executed:
#!/bin/bash
set -Eeuo pipefail
echo "Repo root: $(git rev-parse --show-toplevel 2>/dev/null || pwd)"
echo "Ruby: $(command -v ruby || echo 'missing')"
ruby -v || true
echo "Bundler: $(command -v bundle || echo 'missing')"
bundle -v || true
echo "bin/rails present? $( [ -x bin/rails ] && echo yes || echo no )"
echo "bin/dev present? $( [ -x bin/dev ] && echo yes || echo no )"
echo "Procfile.dev present? $( [ -f Procfile.dev ] && echo yes || echo no )"
echo ".ruby-version: $( [ -f .ruby-version ] && cat .ruby-version || echo 'absent')"
echo "Gemfile ruby directive:"
sed -nE 's/^\s*ruby\s+["'\'']([^"'\'']+)["'\''].*/\1/p' Gemfile || true
Length of output: 292
Enable strict mode and compute CONDUCTOR_ROOT_PATH
At the very top of conductor-setup.sh
, add:
set -Eeuo pipefail
readonly CONDUCTOR_ROOT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)"
Improve idempotency (optional)
- Use
cp -n
instead ofcp
for.env
files to avoid overwriting existing copies. - Replace
bundle install
withbundle check || bundle install
so rerunning skips if gems are already satisfied.
🤖 Prompt for AI Agents
In conductor-setup.sh around lines 4 to 51, add strict Bash failure modes and
compute a reliable CONDUCTOR_ROOT_PATH at the top of the script (use set -Eeuo
pipefail and define readonly CONDUCTOR_ROOT_PATH by resolving the script
directory to the repo root) so errors are caught and path references work; also
make copies idempotent by using cp -n for .env and .env.local to avoid
overwrites if target exists, and replace the unconditional bundle install with a
guarded invocation (bundle check || bundle install) so rerunning the script
skips installing gems when already satisfied.
if [ "$(printf '%s\n' "$REQUIRED_VERSION" "$RUBY_VERSION" | sort -V | head -n1)" != "$REQUIRED_VERSION" ]; then | ||
echo "❌ Ruby version $RUBY_VERSION is too old. Rails 8.0.3 requires Ruby >= $REQUIRED_VERSION" | ||
echo " Please update Ruby using a version manager like rbenv, rvm, or asdf." | ||
exit 1 | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non‑portable Ruby version check (‘sort -V’ breaks on macOS/BSD)
sort -V
isn’t available on BSD/macOS; the check can falsely fail. Compare via Ruby’s Gem::Version instead.
-RUBY_VERSION=$(ruby -v | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1)
-REQUIRED_VERSION="3.2.0"
-
-if [ "$(printf '%s\n' "$REQUIRED_VERSION" "$RUBY_VERSION" | sort -V | head -n1)" != "$REQUIRED_VERSION" ]; then
- echo "❌ Ruby version $RUBY_VERSION is too old. Rails 8.0.3 requires Ruby >= $REQUIRED_VERSION"
- echo " Please update Ruby using a version manager like rbenv, rvm, or asdf."
- exit 1
-fi
+REQUIRED_VERSION="${REQUIRED_VERSION:-3.2.0}"
+if ! ruby -e "exit(Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('$REQUIRED_VERSION') ? 0 : 1)"; then
+ echo "❌ Ruby $(ruby -v) is too old. Requires Ruby >= $REQUIRED_VERSION."
+ echo " Please update Ruby via mise, rbenv, rvm, or asdf."
+ exit 1
+fi
🤖 Prompt for AI Agents
In conductor-setup.sh around lines 21 to 25, the current Ruby version check uses
sort -V which is not portable on macOS/BSD; replace it with a Ruby-based
comparison using Gem::Version: invoke a small ruby -e snippet that reads
REQUIRED_VERSION and RUBY_VERSION (export or pass as ENV), compares
Gem::Version.new(RUBY_VERSION) >= Gem::Version.new(REQUIRED_VERSION) and exit
non‑zero when the check fails; then use that exit status to print the existing
error messages and exit 1. Ensure the script remains POSIX-compatible by calling
ruby instead of relying on GNU sort.
if [ -f "$CONDUCTOR_ROOT_PATH/.env" ]; then | ||
echo "📋 Copying .env file from root..." | ||
cp "$CONDUCTOR_ROOT_PATH/.env" .env | ||
fi | ||
|
||
if [ -f "$CONDUCTOR_ROOT_PATH/.env.local" ]; then | ||
echo "📋 Copying .env.local file from root..." | ||
cp "$CONDUCTOR_ROOT_PATH/.env.local" .env.local | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potentially wrong source path and destructive overwrites for .env files
- If CONDUCTOR_ROOT_PATH is unset, you may read from “/.env”.
cp
overwrites existing local env files.
-# Copy environment files from root if they exist
-if [ -f "$CONDUCTOR_ROOT_PATH/.env" ]; then
- echo "📋 Copying .env file from root..."
- cp "$CONDUCTOR_ROOT_PATH/.env" .env
-fi
-...
-if [ -f "$CONDUCTOR_ROOT_PATH/.env.local" ]; then
- echo "📋 Copying .env.local file from root..."
- cp "$CONDUCTOR_ROOT_PATH/.env.local" .env.local
-fi
+# Copy environment files from repo root (non-destructive)
+ROOT_PATH="${CONDUCTOR_ROOT_PATH:-$(git rev-parse --show-toplevel 2>/dev/null || pwd)}"
+for f in .env .env.local; do
+ if [ -f "$ROOT_PATH/$f" ]; then
+ if [ -e "$f" ]; then
+ echo "⚠️ $f already exists locally; leaving it unchanged."
+ else
+ echo "📋 Copying $f from root..."
+ cp -n "$ROOT_PATH/$f" "$f"
+ fi
+ fi
+done
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if [ -f "$CONDUCTOR_ROOT_PATH/.env" ]; then | |
echo "📋 Copying .env file from root..." | |
cp "$CONDUCTOR_ROOT_PATH/.env" .env | |
fi | |
if [ -f "$CONDUCTOR_ROOT_PATH/.env.local" ]; then | |
echo "📋 Copying .env.local file from root..." | |
cp "$CONDUCTOR_ROOT_PATH/.env.local" .env.local | |
fi | |
# Copy environment files from repo root (non-destructive) | |
ROOT_PATH="${CONDUCTOR_ROOT_PATH:-$(git rev-parse --show-toplevel 2>/dev/null || pwd)}" | |
for f in .env .env.local; do | |
if [ -f "$ROOT_PATH/$f" ]; then | |
if [ -e "$f" ]; then | |
echo "⚠️ $f already exists locally; leaving it unchanged." | |
else | |
echo "📋 Copying $f from root..." | |
cp -n "$ROOT_PATH/$f" "$f" | |
fi | |
fi | |
done |
🤖 Prompt for AI Agents
In conductor-setup.sh around lines 33 to 41, the script risks reading from
"/.env" when CONDUCTOR_ROOT_PATH is unset and will unconditionally overwrite
local .env files; fix by first ensuring CONDUCTOR_ROOT_PATH is non-empty and
points to an existing directory (e.g. check [ -n "$CONDUCTOR_ROOT_PATH" ] && [
-d "$CONDUCTOR_ROOT_PATH" ]), construct safe source paths like
src="$CONDUCTOR_ROOT_PATH/.env" and only proceed if [ -f "$src" ], and replace
destructive cp with a non-overwriting strategy (use cp -n to skip if target
exists, or create a timestamped backup of the existing local file before
copying) while keeping all path variables quoted to handle spaces.
"setup": "./conductor-setup.sh", | ||
"run": "bin/dev", | ||
"archive": "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Validate run target prerequisites
Ensure bin/dev
exists and that a compatible Procfile (e.g., Procfile.dev) is present; otherwise “Run” will no‑op/fail.
🏁 Script executed:
#!/bin/bash
set -Eeuo pipefail
[ -x bin/dev ] && echo "bin/dev: OK" || echo "bin/dev: MISSING"
[ -f Procfile.dev ] && echo "Procfile.dev: OK" || echo "Procfile.dev: MISSING"
rg -n '^web:|rails' Procfile* || true
Length of output: 83
Add missing Procfile.dev
Procfile.dev is currently absent, so although bin/dev
exists, running without a defined process (e.g. a web:
entry) will no-op/fail. Add a Procfile.dev or adjust the run
value in conductor.json accordingly.
🤖 Prompt for AI Agents
In conductor.json around lines 3 to 5, the repo references bin/dev but lacks a
Procfile.dev so process managers no-op; add a Procfile.dev at the repo root
containing a "web: bin/dev" entry (or alternatively update conductor.json.run to
invoke the required command directly) so that running the development process
starts the web server via bin/dev.
Summary
Changes
conductor.json: Configuration file defining setup, run, and archive scripts
conductor-setup.sh
for workspace initializationbin/dev
to start Rails serverconductor-setup.sh: Automated setup script that:
Test Plan
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Chores