Installation
Add this line to your application's Gemfile:
gem "ci-helper", require: false
And then execute:
$ bundle install
Or install it yourself as:
$ gem install ci_helper
Usage
Command Line
You can use this gem as command line utility. For example, to lint project by rubocop, execute the following command in the project root:
$ ci-helper RubocopLint # Here's RubocopLint is a command
A command can accept list of options (parameters). Option values are passed through flags.
For example, the BundlerAudit command accepts the ignored_advisories option
You can set a value of this option by setting the flag --ignored-advisories ignored-advisory
.
It should be noted that all hyphens in flag names are automatically replaced with underscores.
If command accepts array as option's value, you can separate values with either commas or spaces.
$ ci-helper BundlerAudit --ignored-advisories first,second # Valid
$ ci-helper BundlerAudit --ignored-advisories first second # Valid too!
List of available commands:
-
BundlerAudit — executes
bundler-audit
. Accepted flags:--ignored-advisories
.-
--ignored-advisories [values]
— accepts advisory codes, delimited by comma.
-
-
CheckDBDevelopment — executes rails db commands (
db:drop
,db:create
,db:migrate
) and seeds database. Does not accept flags. -
CheckDBRollback — executes rails db commands with additional command
db:rollback_new_migrations
, which rollbacks migrations, added in tested branch. Does not accept flags. Gem provides this rake task, but only forSequel
. If you want to useActiveRecord::Migrator
, you'll have to write rake task by your own. - RubocopLint — executes rubocop linter. Does not accept flags.
-
RunSpecs — executes
rspec
in project root. Accepted flags:--node-index
,node-total
,with-database
,split-resultset
.-
--node-index
— if you run specs in parallel in CI, then you might use this flag. -
--node-total
— if you run specs in parallel in CI, then you might use this flag. -
--with-database
— if you want to prepare database before executing specs, you should set this flag totrue
. -
--split-resultset
— if you run specs in parallel in CI, then you might use this flag totrue
. If this flag set to true, final.resultset.json
will be renamed to.resultset.#{node_index}.json
-
-
CheckSpecSuffixes — checks specs in the spec subdirectories for
_spec
suffix, by default ignores directoriessupport
,factories
and files withcontext
suffix. Accepted flags:--extra_paths
,--ignored_paths
.-
--extra-paths [values]
- accepts additional path patterns that should be scanned, delimited by coma. -
--ignored-paths [values]
- accepts path patterns that should be ignored, delimited by coma.
-
-
CheckCoverage — checks coverage by executing
SimpleCov::collate
. Accepted flags:--split-resultset
,--setup-file-path
.-
--split-resultset
— if you execute commandRunSpecs
with--split-resultset true
, you also should set this flag totrue
. If this flag set totrue
, final coverage will be calculated by merging results in all files, matching the maskcoverage/resultset.*.json
. By default final coverage is calculated using result fromcoverage/.resultset.json
. -
--setup-file-path
— relative path to your.rb
file, which setupsSimpleCov
. Usually it isspec_helper.rb
.
-
-
CheckSidekiqSchedulerConfig — checks
sidekiq_scheduler
config by trying to resolve jobs constants viarails runner
. Accepted flags:--config-path
-
--config-path
— relative path to your config yaml file with schedule. Usually it isconfig/sidekiq_scheduler.yml
. -
--with-database
— if you want to prepare database before executing specs, you should set this flag totrue
.
-
Rake Tasks
As you can see, some commands use generic rake tasks. To make tasks available in your application,
you need to require the file ci_helper/railtie
. Also, you can require it directly in Gemfile
:
gem "ci-helper", require: "ci_helper/railtie, group: :test
.
Or if you haven't set require
option to false
, rake tasks loads automatically.
Script
Also, you can write your own script, which can executes this commands by calling classes:
CIHelper::Commands::#{command_name}
. For example,
if you want to execute RunSpecs
command in your script, you can write following lines:
begin
CIHelper::Commands::RunSpecs.call!(with_database: "true") # returned value is exit code.
rescue CIHelper::Commands::Error => e # Command raise error with this class if something went wrong.
abort e.message
end
Adding your own commands
You can write plugins (gems) that add new commands. You just need create gem with following structure:
- lib
- ci_helper
- commands
- cool_command.rb
Where your CoolCoomand
class may look something like this:
module CIHelper
module Commands
class CoolCommand < BaseCommand
def call
execute("ls #{options[:cool_options]}")
end
end
end
end
Then you add your gem to a Gemfile:
gem "ci-helper", require: false
gem "ci-helper-plugin-gem", require: false
And now, you can use your custom command with command line tool:
$ ci-helper CoolCommand --cool-options option_value
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/umbrellio/ci_helper.
License
The gem is available as open source under the terms of the MIT License.
Authors
Created by Ivan Chernov.