CircleCI is a very simple tool that is well-configured as a supervisor of our projects. But is the configuration itself simple? This, of course, depends on the complexity of the project. In our case (mono repo) it turned out to be more difficult than expected.
The configuration for Ruby on Rails projects is not complicated, and the documentation accurately describes each element of the config.yml. However, I would like to focus on the circleci tools that are used to help us keep the code clean and ensure good practice.
It is likely that RuboCope needs no introduction, however, for those who are not familiar with it, it is a static Ruby code analyzer and formater. If you already use rubocop in your project, simply add CircleCI to the configuration file:
ESLint is a tool for identifying and reporting patterns found in the ECMAScript or JavaScript code, in order to make the code more consistent and to avoid errors.
In RSpec, tests are not only scripts that verify the application code, they are also detailed explanations of how the application should behave, expressed in simple English:
In the case of RSpec, we save the test result in a previously created catalog /tmp/test-results in the rspec.xml file, and then using the storetestresults key we store a given catalog. Now the Insights tab will give us access to information such as the median compilation time, the time of the last compilation or the success rate. You can read more about the Insights tab here. If we want to store the rspec.xml file as an “artifact” we need to add the store_artifacts key in our configuration file.
Brakeman is a static analysis tool that checks Ruby on Rails applications for security vulnerabilities. By default, Brakeman will return a non-zero exit code if security warnings are detected or scan errors are encountered. Therefore, we focused only on critical errors, and the warnings were turned off.
If we also want to store the scanning result in the same way as RSpec, our configuration will look like this, and we will have access to our file in the Artifacts tab.
RubyCritic is a gem that uses gems for static analysis, such as Reek, Flay and Flog, to provide a report about the quality of your code. The report contains an A / B / C / D / F rating, every file in our project that we want to have scanned and accurate places that need improvement, and documentation with each alert (eg: TooManyMethods). This tool acts as a consultant in the project. On the basis of the report received, the final decision on whether our code actually needs to be corrected depends on the developer. In our circleci configuration, a separate job is assigned that is responsible for preparing the report and sending a special comment with the result on github.
The basic configuration of rubycritic is no different from the previous ones.
As standard, we run through the bundle with information on which directory we want to scan ./app, in which place we want to save the result -p /tmp/rubycritic (rubycritic automatically creates a directory in which we will store our report), in what format -f json and option –no- browser. We also use the gem circleci-coverage_reporter, which after the scan, puts a comment on github in our pull request with a link to the report and a percentage rating of the scanned files.
In order for the above gem to work properly together with circleci, we must add it to our project and generate two keys (one of them is circleci, the second is github).
Standard installation:
Gemfile gem 'circleci-coverage_reporter'
Rakefile require 'circleci/coverage_reporter/rake_task' if ENV['CIRCLECI']
Section ‘settings’ of our project. After choosing ‘Create Token’ change scope for ‘all’ and fill in Token label. Token to API will be generated after clicking
COVERAGE_REPORTER_VCS_TOKEN
Scope for key to repo
After generating the keys, we must add them to our environment variables in Settings: