在 CircleCI 配置文件中安装一组特定的 gem

Install a specific set of gems in a CircleCI configuration file

我正在尝试构建一个 CircleCI 配置文件,该文件仅通过环境参数安装一组特定的 gem。在这种情况下,我们称该环境为 continuous_integration 并且该环境与 test 环境相匹配。到目前为止,我已经尝试了很多东西,这是我在这个尖峰中的当前配置。

谁能指出我正确的方向?这可能吗?

machine:
  timezone:
    America/Los_Angeles
  ruby:
    version:
      2.4.1
  services:
    - redis
  environment:
    RAILS_ENV: continous_integration

database:
  override:
    - bundle exec RAILS_ENV=continous_integration rake db:drop
    - bundle exec RAILS_ENV=continous_integration rake db:setup

dependencies:
  pre:
    - gem install bundler
  override:
    - bundle install:
        timeout: 180
        environment:
          RAILS_ENV: continous_integration

test:
  override:
    - bundle exec RAILS_ENV=continous_integration rspec 

此解决方案仅适用于 CIRCLE 1.0

根据我目前的研究,我必须验证 continous_integration 环境 在整个 Rails 秘密、环境文件夹、gems 等内部都已正确设置。事实证明,我发现 bundler 不使用 ENV 集,因此我正在使用以下配置知道强制缓存 gem,加快构建过程,并使用 continous_integration 环境。

参考资料

.rspec

--color
--require spec_helper
--format documentation

.circle.yml

machine:
  timezone:
    America/Los_Angeles
  ruby:
    version:
      2.4.1
  services:
    - redis

dependencies:
  pre:
    - gem install bundler
    - gem update bundler
  override:
    - bundle config without development:test
    - bundle check --path=vendor/bundle || bundle install --without development test --path=vendor/bundle --jobs=4 --retry=3:
        timeout: 180

database:
  override:
    - RAILS_ENV=continous_integration bundle exec rake db:drop
    - RAILS_ENV=continous_integration bundle exec rake db:setup

test:
  override:
    - RAILS_ENV=continous_integration bundle exec rspec --format RspecJunitFormatter -o $CIRCLE_TEST_REPORTS/rspec.xml
  post:
    - gem install brakeman
    - gem install rubocop
    - gem install rubocop-rspec
    - RAILS_ENV=continous_integration bundle exec rubocop --format fuubar --require rubocop-rspec --config .rubocop.yml
    - RAILS_ENV=continous_integration brakeman -z

Gemfile

group :development do
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
  gem 'spring-commands-rspec'
  gem 'spring-commands-rubocop'
end

group :development, :test do
  gem 'pry-rails'
  gem 'pry-nav'
  gem 'pry-clipboard'
  gem 'pry-rescue'
  gem 'table_print'
  gem 'awesome_print'
  gem 'guard-rake'
  gem 'guard-rspec'
end

group :development, :test, :continous_integration do
  gem 'brakeman', require: false
  gem 'rubocop', require: false
  gem 'rubocop-rspec', require: false
  gem 'timecop'
  gem 'mail_safe'
  gem 'dotenv-rails'
  gem 'factory_girl_rails'
  gem 'faker', '~> 1.6.6'
end

group :test, :continous_integration do
  gem 'simplecov'
  gem 'database_cleaner'
  gem 'rspec-rails'
  gem 'json_spec'
  gem 'json-schema'
  gem 'json_matchers'
  gem 'shoulda-matchers'
  gem 'nyan-cat-formatter'
  gem 'rspec_junit_formatter', '~> 0.3.0.pre6'
  gem 'webmock'
  gem 'vcr'
end

此设置也会在 Circle CI 中产生正确的错误输出