rubyvideo icon indicating copy to clipboard operation
rubyvideo copied to clipboard

Add Rails 8.1 Local CI Runner

Open fagnerpereira opened this issue 2 months ago • 7 comments

Summary

Configure Rails 8.1's new local CI feature to run the full CI pipeline locally before pushing code.

Background

Rails 8.1 introduced a local CI runner that allows developers to execute the entire CI pipeline on their machines. This was announced in the Rails 8.1 release and provides a way to catch issues before committing.

Current Status

I've already implemented this in PR #1105, but I'm separating it into its own PR to maintain clear separation of concerns. My apologies for mixing multiple features in my first contribution (related to #1079) - lesson learned! 😅

Implementation example (already existent in the current codebase)

Add CI.run block to run locally with bin/ci:

CI.run do
  step "Setup", "bin/setup --skip-server"
  step "Style: Ruby", "bin/rubocop"
  step "Security: Gem audit", "bin/bundler-audit"
  step "Security: Importmap vulnerability audit", "bin/importmap audit"
  step "Security: Brakeman code analysis", "bin/brakeman --quiet --no-pager --exit-on-warn --exit-on-error"
  step "Tests: Rails", "bin/rails test"
  step "Tests: Seeds", "env RAILS_ENV=test bin/rails db:seed:replant"
  
  # Optional: Requires `gh` CLI with `gh extension install basecamp/gh-signoff`
  if success?
    step "Signoff: All systems go. Ready for merge and deploy.", "gh signoff"
  else
    failure "Signoff: CI failed. Do not merge or deploy.", "Fix the issues and try again."
  end
end

Benefits

  • Faster Feedback Loop: Catch issues locally in seconds/minutes instead of waiting for cloud CI
  • Safer Experimentation: Test CI pipeline changes locally before modifying the actual workflow
  • Reduced Commit Noise: Avoid multiple fix commits trying to get CI green
  • Standardized Workflow: Ensures all contributors run the same checks locally

Future potential

  • Getting rid of a cloud-setup for all of CI not just feasible but desirable for many small-to-mid-sized applications
  • The optional integration with gh ensures that PRs must be signed off by a passing CI run in order to be eligible to be merged.

Rails 8.1 Announcement

Next Steps

@marcoroth - If you're agreed, I'll create a clean PR with setup + docs for easy contributor adoption.

References: Rails 8.1 Release Announcement GoRails Tutorial: Rails 8.1 Local CI Initial Implementation in PR #1105 Related Issue #1079

fagnerpereira avatar Oct 30 '25 03:10 fagnerpereira

Currently our CI has 3 parallel steps on GA + the deploy step on main. I think we want to keep this as it improve the speed. If we have a CI script it would only benefits when we run it locally.

Currently it is what we achieve with a mix of bin/lint and rails test:all. It could be nice yes to have a single command for that but I don't think we should replace what we have in GitHub action

adrienpoly avatar Oct 30 '25 07:10 adrienpoly

@adrienpoly hey, nice to meet you Adrien Senpai. Maybe I expressed wrongly, bu I totally agree about use this issue as a replacemant of github action, but as a complement. For example in the PR i implemented the steps I literally copied from our ci workflow. And it was very helpfull because the result was the possibility of run our ci locally, then I fixed what was broken, then submited to the pull request to make it green. So I think the value I saw on this experience was the possibility of fix the ci locally while coding and not commit with a fix, then I wait some minutes to see that other thing failed, then I commit again, and keep repeting this until make all green.

I think replacemant is always an extreme decision, because this is a new feature and probably its going to grow maybe adding more possibilities. So its something very simple to setup, because its literally copy/paste from our ci workflow, and its done to give you this power to resolve as much things as possible before following an approach of N tries and between those tries, you wast minutes to receive a feedback, when you can have now this feature to see the fail in you environment and fix before submiting and wait.

fagnerpereira avatar Oct 30 '25 07:10 fagnerpereira

some days ago by the way I think there was a contributer trying to fix a issue failing in CI, and then this came in my mind, because he would spend less time trying to findout in its on machine, investigating, debuging, etc.

fagnerpereira avatar Oct 30 '25 07:10 fagnerpereira

Actually, running GitHub action workflows locally is easy There is https://github.com/nektos/act that has existed for a few years

saiqulhaq avatar Oct 30 '25 14:10 saiqulhaq

@saiqulhaq I didnt know this one, I thouth it was some gap that rails core team found to try solving, because they are literally using in a "production" level to decrease the time they had with their huge CI.

What do you think @adrienpoly @marcoroth ? Its pratically implemented, maybe we could give a try to this simple native solution, and if contributors feel that is usefull we can improve, test new approachs, or even test this one suggested by our friend @saiqulhaq , which I admit I didnt know, but I will probably experiment to understand better

fagnerpereira avatar Oct 30 '25 21:10 fagnerpereira

yes please go ahead and generate a bin/ci script to run locally, I think that can be useful

adrienpoly avatar Oct 30 '25 21:10 adrienpoly

@adrienpoly sure thing, could you assign for me please and I send the pr asap. If at the end you guys feels not so usefull, delete things is always easier at least 😅

fagnerpereira avatar Oct 30 '25 21:10 fagnerpereira