In a Rails 8.1 app, what do bin/ci and config/ci.rb run, and how does one failing step affect the rest of the run?
answer
- new in Rails 8.1
- CI.run with step "Title", "command"
- sets ENV["CI"] so tests eager load
- every step runs; abort at the end
- system tests and signoff commented out
basics
~20 sbin/ci loads ActiveSupport::ContinuousIntegration and runs the steps declared in config/ci.rb (setup, RuboCop, audits, Brakeman, bin/rails test, seeds); a failing step is reported but later steps still run, and the script exits non-zero at the end.
solid answer
~40 sRails 8.1 generates `bin/ci`, which requires `active_support/continuous_integration`, aliases it as `CI` and loads `config/ci.rb`. That file is a `CI.run do ... end` block of `step "Title", "command"` lines: `bin/setup --skip-server`, `bin/rubocop`, `bin/bundler-audit`, `bin/importmap audit`, `bin/brakeman ...`, `bin/rails test` and `env RAILS_ENV=test bin/rails db:seed:replant`. System tests and a `gh signoff` step are left commented out. Each step runs with `system`, is timed and prints pass or fail. A failure does not stop the block, so later steps still run, and at the end `CI.run` aborts with a non-zero status if any step failed. `CI.run` also sets `ENV["CI"] = "true"`, which turns on `config.eager_load` in the generated test environment.
code
ruby · 14 lines# config/ci.rb
CI.run do
step "Setup", "bin/setup --skip-server"
step "Style: Ruby", "bin/rubocop"
step "Security: Gem audit", "bin/bundler-audit"
step "Tests: Rails", "bin/rails test"
step "Tests: System", "bin/rails test:system"
if success?
step "Signoff: Ready for merge", "gh signoff"
else
failure "Signoff: CI failed.", "Fix the issues and try again."
end
endgo deeper
Know that Rails 8.1 apps can run all their checks with bin/ci, and that the steps live in config/ci.rb.
Explain the step DSL, that every step runs before the exit status is decided, and how ENV["CI"] switches on eager loading in tests.
Shape config/ci.rb so local and hosted runs check the same things, including system tests and eager loading, without making the local loop slow.
Decide whether local signoff can be trusted for merges, and what must still run on shared CI infrastructure.
## What Rails 8.1 generates A new Rails 8.1 app gets two files for running its checks locally or on a CI machine: - **`bin/ci`** requires `config/boot` and `active_support/continuous_integration`, sets `CI = ActiveSupport::ContinuousIntegration`, and loads `config/ci.rb`. - **`config/ci.rb`** declares the workflow with a small DSL. The generated workflow, depending on the options `rails new` was given: | Step title | Command | |---|---| | Setup | `bin/setup --skip-server` | | Style: Ruby | `bin/rubocop` | | Security: Gem audit | `bin/bundler-audit` | | Security: Importmap vulnerability audit | `bin/importmap audit` (import-map apps; Node apps get `yarn audit`) | | Security: Brakeman code analysis | `bin/brakeman --quiet --no-pager --exit-on-warn --exit-on-error` | | Tests: Rails | `bin/rails test` | | Tests: Seeds | `env RAILS_ENV=test bin/rails db:seed:replant` | Two blocks are present but **commented out**: a `step "Tests: System", "bin/rails test:system"` line, and a `gh signoff` step guarded by `success?` with a `failure(...)` heading in the else branch. ## The DSL - `CI.run(title, subtitle) { ... }` runs the block and prints a banner. - `step "Title", "command"` runs the command with `system`, times it, prints the title, and records `true` or `false`. - `step "Title", "bin/rails", "test", "test/models"` passes separate arguments, so paths need no shell escaping. - `success?` is true only while every recorded step has passed. - `failure "Title", "subtitle"` prints a red heading; it does not change the result. - `heading` and `echo` print extra output. ## What happens when a step fails 1. The failing command returns false, and `bin/ci` prints a red cross with the step's title and elapsed time. 2. The block **keeps going**: later steps still run, so one run reports style, audit and test failures together. 3. After the block, `CI.run` calls `abort` unless every step succeeded, so `bin/ci` exits non-zero and a CI service marks the build failed. A missing command also counts as a failure, because `system` returns `nil` when it cannot run the program. If you want a fast stop, order the cheap steps first and break the workflow into separate runs; the DSL itself does not short-circuit. ## Why ENV["CI"] matters `CI.run` sets `ENV["CI"] = "true"` before running steps, and child processes inherit it. The generated `config/environments/test.rb` contains `config.eager_load = ENV["CI"].present?`. So `bin/rails test` under `bin/ci` **eager loads the whole app**, which catches files that only fail to load when eager loading, such as a constant that does not match its file name. A plain local `bin/rails test` skips that check and starts faster. ## Where it sits next to hosted CI - Rails also generates `.github/workflows/ci.yml` with separate scan, lint and test jobs, so `bin/ci` does not replace a hosted pipeline. It gives developers the same checks on their own machines before pushing. - The optional `gh signoff` step (from the `basecamp/gh-signoff` extension) sets a green commit status after a local run, so a team can trust local runs for merge decisions. - Adding system tests is a matter of uncommenting the line or adding a step; they are left out by default because they need a browser. ## Common edits - Add a `step "Tests: System", "bin/rails test:system"` once the app has system tests. - Add project checks such as a JavaScript linter as more `step` lines. - Wrap optional steps in Ruby conditionals; `config/ci.rb` is plain Ruby, evaluated inside the `CI.run` block. ## Running it - `bin/ci` with no arguments runs the whole workflow from the top, printing a banner, each step's heading and command, and a pass or fail line with the elapsed time. - The final summary line says whether the whole run passed and how long it took, which makes it easy to spot a step that has grown slow. - Pressing Ctrl-C aborts with an "interrupted" message naming the current step. - Because each step is an ordinary shell command, any step can be run on its own while fixing it, for example `bin/rubocop` or `bin/rails test test/models`, and `bin/ci` is rerun once everything is green.
- Why can bin/rails test pass locally but fail under bin/ci in a Rails 8.1 app?`CI.run` sets `ENV["CI"] = "true"`, and the generated `config/environments/test.rb` sets `config.eager_load = ENV["CI"].present?`. Under `bin/ci` the whole app is eager loaded, so a file whose constant does not match its path, or code that breaks at load time, fails there even though a local lazy-loading run never touched it.
- bin/ci stops at the first failing step and skips the rest.
- The generated config/ci.rb runs system tests by default.
- bin/ci has existed in every Rails app since Rails 7.
- failure in config/ci.rb makes the run exit non-zero by itself.
- bin/ci replaces the generated GitHub Actions workflow.
Assumes Rails 8.1, which introduced bin/ci, config/ci.rb and ActiveSupport::ContinuousIntegration; earlier apps have none of them.