Skip to content

Commit a2cad83

Browse files
Merge pull request rails#56031 from harsh183/hd/getting_started/rewrite_section_to_bin_ci
[Getting Started] Rewrite Continiouus Integration section to use `bin/ci` [ci-skip]
2 parents a57f1a7 + a5a8454 commit a2cad83

File tree

1 file changed

+110
-7
lines changed

1 file changed

+110
-7
lines changed

guides/source/getting_started.md

Lines changed: 110 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2943,16 +2943,119 @@ No warnings found
29432943

29442944
Learn more about [Securing Rails Applications](security.html)
29452945

2946-
Continuous Integration with GitHub Actions
2946+
Continuous Integration with `bin/ci`
29472947
------------------------------------------
29482948

2949-
Rails apps generate a `.github` folder that includes a prewritten GitHub Actions
2950-
configuration that runs rubocop, brakeman, and our test suite.
2949+
Rails applications include a `bin/ci` script that runs all essential checks for
2950+
your app: setup, code style (RuboCop), security audits, and tests. The steps
2951+
are defined in `config/ci.rb` and can be customized for your project.
29512952

2952-
When we push our code to a GitHub repository with GitHub Actions enabled, it
2953-
will automatically run these steps and report back success or failure for each.
2954-
This allows us to monitor our code changes for defects and issues and ensure
2955-
consistent quality for our work.
2953+
This script prints each step as it runs, showing ✅ for success and ❌ for
2954+
failures. If any step fails, `bin/ci` exits with a nonzero status.
2955+
2956+
To use a CI Provider, point your pipeline to `bin/ci`. This ensures consistent
2957+
checks locally and in CI.
2958+
2959+
To run it locally, call the script from your command line:
2960+
2961+
```bash
2962+
$ bin/ci
2963+
Continuous Integration
2964+
Running tests, style checks, and security audits
2965+
2966+
2967+
Setup
2968+
bin/setup --skip-server
2969+
2970+
== Installing dependencies ==
2971+
The Gemfile's dependencies are satisfied
2972+
2973+
== Preparing database ==
2974+
2975+
== Removing old logs and tempfiles ==
2976+
2977+
✅ Setup passed in 2.11s
2978+
2979+
2980+
Style: Ruby
2981+
bin/rubocop
2982+
2983+
Inspecting 25 files
2984+
.........................
2985+
2986+
25 files inspected, no offenses detected
2987+
2988+
✅ Style: Ruby passed in 1.17s
2989+
# ...
2990+
✅ Continuous Integration passed in 8.91s
2991+
```
2992+
2993+
### CI Steps DSL
2994+
2995+
The file is written in a DSL that makes it straightforward to manage steps, here
2996+
we add another step to check to make sure we don't leave any TODOs behind in
2997+
the code in `config/ci.rb`:
2998+
2999+
```ruby#6-7
3000+
# config/ci.rb
3001+
CI.run do
3002+
step "Setup", "bin/setup --skip-server"
3003+
3004+
step "Style: Ruby", "bin/rubocop"
3005+
step "Check: No TODOs",
3006+
"if grep -r TODO app/; then exit 1; fi"
3007+
# ...
3008+
end
3009+
```
3010+
3011+
To test this out, I added a todo comment at the start of a random file, here
3012+
the `ApplicationController`:
3013+
3014+
```ruby
3015+
# app/controllers/application_controller.rb
3016+
# TODO: Remove this todo
3017+
class ApplicationController < ActionController::Base
3018+
# ...
3019+
```
3020+
3021+
Now when I run it on the CI:
3022+
3023+
```bash
3024+
$ bin/ci
3025+
# ...
3026+
Check: No TODOs
3027+
if grep -r TODO app/; then exit 1; fi
3028+
3029+
app/controllers/application_controller.rb:# TODO: Remove this todo
3030+
3031+
❌ Check: No TODOs failed in 0.01s
3032+
# ...
3033+
❌ Continuous Integration failed in 9.09s
3034+
```
3035+
3036+
To verify, remove the comment:
3037+
3038+
```ruby
3039+
# app/controllers/application_controller.rb
3040+
class ApplicationController < ActionController::Base
3041+
# ...
3042+
```
3043+
3044+
and `bin/ci` should now pass:
3045+
3046+
```bash
3047+
$ bin/ci
3048+
# ...
3049+
Check: No TODOs
3050+
if grep -r TODO app/; then exit 1; fi
3051+
3052+
3053+
✅ Check: No TODOs passed in 0.01s
3054+
# ...
3055+
✅ Continuous Integration passed in 8.91s
3056+
```
3057+
3058+
To learn more about the DSL, read the documentation for [ActiveSupport::ContinuousIntegration](https://www.rubydoc.info/github/rails/rails/main/ActiveSupport/ContinuousIntegration).
29563059

29573060
Deploying to Production
29583061
-----------------------

0 commit comments

Comments
 (0)