@@ -2961,16 +2961,113 @@ No warnings found
29612961
29622962Learn more about [ Securing Rails Applications] ( security.html )
29632963
2964- Continuous Integration with GitHub Actions
2964+ Continuous Integration with ` bin/ci `
29652965------------------------------------------
29662966
2967- Rails apps generate a ` .github ` folder that includes a prewritten GitHub Actions
2968- configuration that runs rubocop, brakeman, and our test suite.
2967+ Rails applications include a ` bin/ci ` script that runs all essential checks for
2968+ your app: setup, code style (RuboCop), security audits, and tests. The steps
2969+ are defined in ` config/ci.rb ` and can be customized for your project.
29692970
2970- When we push our code to a GitHub repository with GitHub Actions enabled, it
2971- will automatically run these steps and report back success or failure for each.
2972- This allows us to monitor our code changes for defects and issues and ensure
2973- consistent quality for our work.
2971+ This script prints each step as it runs, showing ✅ for success and ❌ for
2972+ failures. If any step fails, ` bin/ci ` exits with a nonzero status.
2973+
2974+ To use a CI Provider, point your pipeline to ` bin/ci ` . This ensures consistent
2975+ checks locally and in CI.
2976+
2977+ To run it locally, call the script from your command line:
2978+ ``` bash
2979+ $ bin/ci
2980+ Continuous Integration
2981+ Running tests, style checks, and security audits
2982+
2983+
2984+ Setup
2985+ bin/setup --skip-server
2986+
2987+ == Installing dependencies ==
2988+ The Gemfile' s dependencies are satisfied
2989+
2990+ == Preparing database ==
2991+
2992+ == Removing old logs and tempfiles ==
2993+
2994+ ✅ Setup passed in 2.11s
2995+
2996+
2997+ Style: Ruby
2998+ bin/rubocop
2999+
3000+ Inspecting 25 files
3001+ .........................
3002+
3003+ 25 files inspected, no offenses detected
3004+
3005+ ✅ Style: Ruby passed in 1.17s
3006+ # ...
3007+ ✅ Continuous Integration passed in 8.91s
3008+ ```
3009+
3010+ ### CI Steps DSL
3011+
3012+ The file is written in a DSL that makes it straightforward to manage steps, here
3013+ we add another step to check to make sure we don' t leave any TODOs behind in
3014+ the code in ` config/ci.rb` :
3015+
3016+ ` ` ` ruby#6-7
3017+ # config/ci.rb
3018+ CI.run do
3019+ step " Setup" , " bin/setup --skip-server"
3020+
3021+ step " Style: Ruby" , " bin/rubocop"
3022+ step " Check: No TODOs" ,
3023+ " if grep -r TODO app/; then exit 1; fi"
3024+ # ...
3025+ end
3026+ ` ` `
3027+
3028+ To test this out, I added a todo comment at the start of a random file, here
3029+ the ` ApplicationController` :
3030+ ` ` ` ruby
3031+ # app/controllers/application_controller.rb
3032+ # TODO: Remove this todo
3033+ class ApplicationController < ActionController::Base
3034+ # ...
3035+ ` ` `
3036+
3037+ Now when I run it on the CI:
3038+ ` ` ` bash
3039+ $ bin/ci
3040+ # ...
3041+ Check: No TODOs
3042+ if grep -r TODO app/; then exit 1; fi
3043+
3044+ app/controllers/application_controller.rb:# TODO: Remove this todo
3045+
3046+ ❌ Check: No TODOs failed in 0.01s
3047+ # ...
3048+ ❌ Continuous Integration failed in 9.09s
3049+ ` ` `
3050+
3051+ To verify, remove the comment:
3052+ ` ` ` ruby
3053+ # app/controllers/application_controller.rb
3054+ class ApplicationController < ActionController::Base
3055+ # ...
3056+ ` ` `
3057+
3058+ and ` bin/ci` should now pass:
3059+
3060+ ` ` ` bash
3061+ $ bin/ci
3062+ # ...
3063+ Check: No TODOs
3064+ if grep -r TODO app/; then exit 1; fi
3065+
3066+
3067+ ✅ Check: No TODOs passed in 0.01s
3068+ # ...
3069+ ✅ Continuous Integration passed in 8.91s
3070+ ` ` `
29743071
29753072Deploying to Production
29763073-----------------------
0 commit comments