Rails 8.1 introduces bin/ci to standardize CI workflows with a new DSL

Rails 8.1 introduces bin/ci to standardize CI workflows based on a new domain specific language (DSL) in config/ci.rb making it easier to define, run and maintain the CI pipelines.

Understanding the DSL in config/ci.rb

The new DSL allows us to define CI steps in a structured and readable way.

  • step: Defines a single step in the workflow. The first argument is the step’s name and the remaining arguments form the command to execute.
  • success?: Returns true if all previous steps passed, allowing conditional logic.
  • failure: Displays a failure message with a description when the workflow fails. Takes two arguments: the message and a description.
CI.run do
  step "Setup", "bin/setup --skip-server"

  step "Style: Ruby", "bin/rubocop"

  step "Security: Brakeman code analysis", "bin/brakeman", "--quiet", "--no-pager",
          "--exit-on-warn", "--exit-on-error"
  step "Security: Importmap vulnerability audit", "bin/importmap", "audit"

  step "Tests: Rails", "bin/rails", "test", "test:system"
  step "Tests: Seeds", "env RAILS_ENV=test bin/rails db:seed:replant"

  if success?
    step "Signoff: All systems go. Ready for merge and deploy.", "gh signoff"
  else
    failure "Signoff: Failed. Do not merge or deploy.", "Fix the issues and try again."
  end
end

Example output:

./bin/ci
Continuous Integration
Running tests, style checks, and security audits


Setup
bin/setup --skip-server

== Installing ruby ==
mise all runtimes are installed

== Installing dependencies ==
The Gemfile's dependencies are satisfied

== Preparing database ==

== Removing old logs and tempfiles ==

== Now start developing with bin/dev

Setup passed in 3.33s


Style: Ruby
bin/rubocop

Inspecting 563 files
..........................................

563 files inspected, no offenses detected

Style: Ruby passed in 1.07s


Security: Brakeman code analysis
bin/brakeman --quiet --no-pager --exit-on-warn --exit-on-error


== Brakeman Report ==

Application Path: /home/user/Work/miru-web/know_it_all
Rails Version: 8.1.0.alpha
Brakeman Version: 6.2.2
Scan Date: 2025-03-06 12:16:47 +0100
Duration: 1.273865987 seconds
Checks Run: BasicAuth, BasicAuthTimingAttack, CSRFTokenForgeryCVE,
ContentTag, CookieSerialization, CreateWith, CrossSiteScripting,
DefaultRoutes, Deserialize, DetailedExceptions, DigestDoS,
DynamicFinders, EOLRails, EOLRuby, EscapeFunction, Evaluation,
Execute, FileAccess, FileDisclosure, FilterSkipping, ForgerySetting,
HeaderDoS, I18nXSS, JRubyXML, JSONEncoding, JSONEntityEscape,
JSONParsing, LinkTo, LinkToHref, MailTo, MassAssignment, MimeTypeDoS,
ModelAttrAccessible, ModelAttributes, ModelSerialize, NestedAttributes,
NestedAttributesBypass, NumberToCurrency, PageCachingCVE, Pathname,
PermitAttributes, QuoteTableName, Ransack, Redirect, RegexDoS, Render,
RenderDoS, RenderInline, ResponseSplitting, RouteDoS, SQL, SQLCVEs,
SSLVerify, SafeBufferManipulation, SanitizeConfigCve, SanitizeMethods,
SelectTag, SelectVulnerability, Send, SendFile, SessionManipulation,
SessionSettings, SimpleFormat, SingleQuotes, SkipBeforeFilter,
SprocketsPathTraversal, StripTags, SymbolDoSCVE, TemplateInjection,
TranslateBug, UnsafeReflection, UnsafeReflectionMethods, ValidationRegex,
VerbConfusion, WeakRSAKey, WithoutProtection, XMLDoS, YAMLParsing

== Overview ==

Controllers: 58
Models: 63
Templates: 181
Errors: 0
Security Warnings: 0
Ignored Warnings: 3

== Warning Types ==


No warnings found


Security: Brakeman code analysis passed in 1.61s


Security: Importmap vulnerability audit
bin/importmap audit

No vulnerable packages found

Security: Importmap vulnerability audit passed in 1.40s


Tests: Rails
bin/rails test test:system

Running 618 tests in parallel using 32 processes
Run options: --seed 52099

# Running:

.............................................................
Finished in 4.164330s, 148.4032 runs/s, 591.2115 assertions/s.
618 runs, 2462 assertions, 0 failures, 0 errors, 0 skips

Tests: Rails passed in 6.64s

Continuous Integration passed in 14.42s

Breakdown of the CI workflow defined in the code

1. Setup:

  • bin/setup --skip-server installs Ruby, dependencies, setup the database and cleans up old files.

2. Style Check:

  • bin/rubocop command check for style violations

3. Security: Brakeman code analysis:

  • bin/brakeman command scans for security vulnerabilities.

4. Security: Importmap Vulnerability Audit:

  • bin/importmap audit command checks for vulnerable packages.

5. Tests: Rails:

  • bin/rails test test:system command runs the Rails test suite.

6. Tests: Seeds:

  • bin/rails db:seed:replant verifies that seed data can be loaded correctly in the test environment.

7. Signoff:

  • If all steps pass (success?), a signoff step runs to indicate the build is ready for merge and deploy.
  • If any step fails, the failure method displays an error message with guidance to fix the issues.

References

Need help on your Ruby on Rails or React project?

Join Our Newsletter