在CircleCI配置文件

时间:2017-06-29 14:35:03

标签: ruby-on-rails ruby circleci

我正在尝试构建一个CircleCI配置文件,该文件仅通过environment参数安装一组特定的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 

1 个答案:

答案 0 :(得分:1)

此解决方案仅适用于CIRCLE 1.0

根据我目前的研究,我必须验证continous_integration环境 在整个Rails内部设置正确的秘密,环境文件夹,宝石等。事实证明,我发现bundler不使用ENV集,所以我正在使用以下配置知道强制缓存宝石,加快构建过程,并使用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中产生正确的错误输出

enter image description here