Danger
Danger runs during our CI process, and lets us ensure our commits, pull requests, and more meet a minimum level of quality.
Setup
Enable Danger for a project within the ministryofjustice organization.
Add the following to your Gemfile;
group :development do gem 'moj-danger' endbundle installCreate Dangerfile
echo "danger.import_dangerfile(github: 'ministryofjustice/danger')" > Dangerfile
- Add Danger to your .travis.yml (use whatever ruby version is appropriate)
rvm: 2.3.3
script:
- bundle exec danger
Commit the changes to the Dangerfile and .travis.yml
Add the MoJ Dangerbot API token to Travis;
This assumes your project has already been added to Travis.
https://travis-ci.org/ministryofjustice/[your project]/settings
Add the environment variable DANGER_GITHUB_API_TOKEN, with the value from the password field of https://rattic.service.dsd.io/cred/detail/695/
Run danger locally
You need to create a PR before you can do this.
bundle exec danger pr https://github.com/ministryofjustice/[your project]/pull/[PR number]
Configure Danger to use this repo's Dangerfile
Commit a Dangerfile containing linking to this repo:
danger.import_dangerfile(github: 'ministryofjustice/danger')
If you're running Ruby
Add danger to your Gemfile.
gem 'danger'
Run Danger in Travis
Add Danger to .travis.yml:
before_script:
- bundle exec danger
… or add it to your build matrix:
matrix:
include:
- rvm: 2.3.1
script:
- bundle exec danger
And add the DANGER_GITHUB_API_TOKEN as an environment variable in
Travis's repo settings, which are at a URL like
https://travis-ci.org/ministryofjustice/[repo]/settings. The API token
itself is in Rattic (search for Danger).
Run Danger in CircleCI
Just add bundle exec danger to your circle.yml, either as an extra
step in your test overrides, or in a new pre section. You'll need
to add the DANGER_GITHUB_API_TOKEN to the environment variables like
with Travis, and Danger
recommend
setting “only build pull requests” in the advanced settings.
If you're not running Ruby
If Danger is your only Ruby dependency, you probably don't want to have a Gemfile cluttering up your repo. In that case, you can (probably) use this command in the Travis config above:
rbenv global 2.3.1 && gem install danger --version '~> 5.0' && danger