From 921cbf36436f70f9e8383381bad78427102b2c9c Mon Sep 17 00:00:00 2001 From: Jacob Harris Date: Mon, 24 Jul 2017 15:58:50 -0400 Subject: [PATCH 1/5] Switch micropurchase to use CircleCI --- .circleci/config.yml | 74 +++++++++++++++++++++++ .ruby-version | 2 +- .simplecov | 8 +-- Gemfile | 6 +- Gemfile.lock | 14 ++--- features/support/_circleci_formatter.rb | 79 +++++++++++++++++++++++++ 6 files changed, 164 insertions(+), 19 deletions(-) create mode 100644 .circleci/config.yml create mode 100644 features/support/_circleci_formatter.rb diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 00000000..789cb49b --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,74 @@ +# +version: 2 +jobs: + build: + docker: + # specify the version you desire here + - image: circleci/ruby:2.3.4-node-browsers + environment: + CC_TEST_REPORTER_ID: 2ad0d3196c872832cf5d6b34c83bf21dbf0a30e2191ba036be003b01e417a6a1 + PG_HOST: localhost + PG_USER: postgres + RAILS_ENV: test + RACK_ENV: test + DATABASE_URL: "postgres://postgres:postgres@localhost:5432/micropurchase_test" + + # Specify service dependencies here if necessary + # CircleCI maintains a library of pre-built images + # documented at https://circleci.com/docs/2.0/circleci-images/ + - image: postgres:9.6.2 + environment: + POSTGRES_USER: postgres + POSTGRES_DB: micropurchase_test + POSTGRES_PASSWORD: postgres + + working_directory: ~/micropurchase + + steps: + - checkout + + # Download and cache dependencies + - restore_cache: + keys: + - v1-dependencies-{{ checksum "Gemfile.lock" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + + - run: + name: install dependencies + command: | + bundle install --jobs=4 --retry=3 --path vendor/bundle + curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter + chmod +x ./cc-test-reporter + + - save_cache: + paths: + - ./venv + key: v1-dependencies-{{ checksum "Gemfile.lock" }} + # Database setup + - run: bundle exec rake db:create + - run: bundle exec rake db:schema:load + + # run tests! + # TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)" + - run: + name: run tests + command: | + mkdir /tmp/test-results + ./cc-test-reporter before-build + bundle exec rspec --format progress \ + --format RspecJunitFormatter \ + --out /tmp/test-results/rspec.xml \ + --format progress + ./cc-test-reporter format-coverage --output coverage/codeclimate.rspec.json + bundle exec cucumber + ./cc-test-reporter format-coverage --output coverage/codeclimate.cucumber.json + ./cc-test-reporter sum-coverage coverage/codeclimate.*.json | ./cc-test-reporter upload-coverage + + # --format CircleCICucumberFormatter::CircleCIJson + # collect reports + - store_test_results: + path: /tmp/test-results + - store_artifacts: + path: /tmp/test-results + destination: test-results diff --git a/.ruby-version b/.ruby-version index 0bee604d..3f684d2d 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.3.3 +2.3.4 diff --git a/.simplecov b/.simplecov index 59027b20..15530f37 100644 --- a/.simplecov +++ b/.simplecov @@ -3,10 +3,4 @@ SimpleCov.add_filter '/spec' SimpleCov.add_filter '/features' SimpleCov.add_filter '/vendor' -if ENV['CI'] - ENV['DEFAULT_BRANCH'] = 'develop' - require 'codeclimate_batch' - CodeclimateBatch.start -else - SimpleCov.start -end +SimpleCov.start diff --git a/Gemfile b/Gemfile index f7f74bb1..efb081ab 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -ruby '2.3.3' +ruby '2.3.4' gem 'rails', '4.2.7.1' gem 'pg' @@ -41,8 +41,7 @@ gem 'uswds-rails', github: '18F/uswds-rails-gem' gem 'rest-client' group :test do - gem "codeclimate-test-reporter", require: nil - gem 'codeclimate_batch', require: nil + gem "simplecov", require: nil gem 'dotenv' gem 'db-query-matchers' gem 'json-schema' @@ -52,6 +51,7 @@ group :test do end group :development, :test do + gem 'rspec_junit_formatter' gem 'rspec-rails' gem 'cucumber-rails', require: false gem 'capybara' diff --git a/Gemfile.lock b/Gemfile.lock index a3e2b6fc..504b1b2d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -103,10 +103,6 @@ GEM clockwork (2.0.2) activesupport tzinfo - codeclimate-test-reporter (1.0.8) - simplecov (<= 0.13) - codeclimate_batch (0.5.0) - json coderay (1.1.1) commander (4.4.3) highline (~> 1.7.2) @@ -354,6 +350,8 @@ GEM rspec-mocks (~> 3.6.0) rspec-support (~> 3.6.0) rspec-support (3.6.0) + rspec_junit_formatter (0.3.0) + rspec-core (>= 2, < 4, != 2.12.0) rubocop (0.48.1) parser (>= 2.3.3.1, < 3.0) powerpack (~> 0.1) @@ -449,8 +447,6 @@ DEPENDENCIES cf-app-utils chronic clockwork - codeclimate-test-reporter - codeclimate_batch cucumber-rails daemons database_cleaner @@ -491,6 +487,7 @@ DEPENDENCIES redcarpet rest-client rspec-rails + rspec_junit_formatter rubocop ruby-saml (= 1.4.2) saml_idp! @@ -499,6 +496,7 @@ DEPENDENCIES selectize-rails shoulda-matchers simple_form + simplecov sinatra timecop uglifier @@ -508,7 +506,7 @@ DEPENDENCIES webmock RUBY VERSION - ruby 2.3.3p222 + ruby 2.3.4p301 BUNDLED WITH - 1.14.6 + 1.15.3 diff --git a/features/support/_circleci_formatter.rb b/features/support/_circleci_formatter.rb new file mode 100644 index 00000000..32197e4a --- /dev/null +++ b/features/support/_circleci_formatter.rb @@ -0,0 +1,79 @@ +require 'time' + +if Cucumber::VERSION =~ /^2.*/ + require 'cucumber/core/test/timer' + require 'cucumber/formatter/json' + module Cucumber + module Core + module Test + class Timer + def unpatched_time_now + if Time.respond_to?(:now_without_mock_time) + Time.now_without_mock_time + else + Time.now + end + end + + def time_in_nanoseconds + t = unpatched_time_now + t.to_i * 10 ** 9 + t.nsec + end + end + end + end + end + + module CircleCICucumberFormatter + class CircleCIJson < Cucumber::Formatter::Json #:nodoc: + end + end +end # if + +if Cucumber::VERSION =~ /^1.*/ + require 'cucumber/formatter/gherkin_formatter_adapter' + require 'cucumber/formatter/io' + require 'gherkin/formatter/argument' + require 'gherkin/formatter/json_formatter' + + module CircleCICucumberFormatter + class CircleCIJson < Cucumber::Formatter::GherkinFormatterAdapter #:nodoc: + include Cucumber::Formatter::Io + + alias_method :original_before_step, :before_step + + def unpatched_time_now + if Time.respond_to?(:now_without_mock_time) + Time.now_without_mock_time + else + Time.now + end + end + + def initialize(_runtime, io, options) + @io = ensure_io(io, 'json') + f = Gherkin::Formatter::JSONFormatter.new(@io) + begin + super(f, false, options) + rescue ArgumentError # backwards compatibility with old arity + super(f, false) + end + end + + # override @step_time with un-patched Time.now + def before_step(step) + original_before_step(step) + @step_time = unpatched_time_now + end + + # used for capturing duration, copied from gherkin_formatter_adapter.rb + # override step_finish with un-patched Time.now + def after_step(_step) + return if @outline && @options && @options[:expand] && + !@in_instantiated_scenario + step_finish = (unpatched_time_now - @step_time) + @gf.append_duration(step_finish) + end + end + end # module +end # if From 010814c44715f32c650d5e996a9b5a843213e996 Mon Sep 17 00:00:00 2001 From: Jacob Harris Date: Mon, 24 Jul 2017 18:38:57 -0400 Subject: [PATCH 2/5] Some more tweaks to CodeClimate config --- .circleci/config.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 789cb49b..58cdf552 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -61,9 +61,10 @@ jobs: --out /tmp/test-results/rspec.xml \ --format progress ./cc-test-reporter format-coverage --output coverage/codeclimate.rspec.json - bundle exec cucumber + bundle exec rake cucumber ./cc-test-reporter format-coverage --output coverage/codeclimate.cucumber.json - ./cc-test-reporter sum-coverage coverage/codeclimate.*.json | ./cc-test-reporter upload-coverage + ./cc-test-reporter sum-coverage --output -- --parts 2 coverage/codeclimate.*.json > coverage/codeclimate.json + ./cc-test-reporter upload-coverage -d # --format CircleCICucumberFormatter::CircleCIJson # collect reports From 6529a4396e618be4c99e7ec1582056892a4a889f Mon Sep 17 00:00:00 2001 From: Jacob Harris Date: Mon, 24 Jul 2017 19:08:33 -0400 Subject: [PATCH 3/5] Argh CodeClimate --- .circleci/config.yml | 6 +++--- .simplecov | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 58cdf552..1cf68bf9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -61,10 +61,10 @@ jobs: --out /tmp/test-results/rspec.xml \ --format progress ./cc-test-reporter format-coverage --output coverage/codeclimate.rspec.json - bundle exec rake cucumber + bundle exec cucumber --format junit --out /tmp/test-results/cucumber.xml ./cc-test-reporter format-coverage --output coverage/codeclimate.cucumber.json - ./cc-test-reporter sum-coverage --output -- --parts 2 coverage/codeclimate.*.json > coverage/codeclimate.json - ./cc-test-reporter upload-coverage -d + ./cc-test-reporter sum-coverage --parts 2 --output coverage/codeclimate.json coverage/codeclimate.*.json + ./cc-test-reporter upload-coverage --debug # --format CircleCICucumberFormatter::CircleCIJson # collect reports diff --git a/.simplecov b/.simplecov index 15530f37..27b8a3fe 100644 --- a/.simplecov +++ b/.simplecov @@ -3,4 +3,8 @@ SimpleCov.add_filter '/spec' SimpleCov.add_filter '/features' SimpleCov.add_filter '/vendor' +if ENV['CIRCLE_ARTIFACTS'] + dir = File.join(ENV['CIRCLE_ARTIFACTS'], "coverage") + SimpleCov.coverage_dir(dir) +end SimpleCov.start From 9852865294e392009f2b6b755e694ef195137e50 Mon Sep 17 00:00:00 2001 From: Jacob Harris Date: Mon, 24 Jul 2017 21:30:08 -0400 Subject: [PATCH 4/5] Final config tweaks for CircleCI --- .circleci/config.yml | 2 +- .travis.yml | 48 -------------------------------------------- README.md | 2 +- 3 files changed, 2 insertions(+), 50 deletions(-) delete mode 100644 .travis.yml diff --git a/.circleci/config.yml b/.circleci/config.yml index 1cf68bf9..0578a365 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -64,7 +64,7 @@ jobs: bundle exec cucumber --format junit --out /tmp/test-results/cucumber.xml ./cc-test-reporter format-coverage --output coverage/codeclimate.cucumber.json ./cc-test-reporter sum-coverage --parts 2 --output coverage/codeclimate.json coverage/codeclimate.*.json - ./cc-test-reporter upload-coverage --debug + ./cc-test-reporter upload-coverage # --format CircleCICucumberFormatter::CircleCIJson # collect reports diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 09b9f86e..00000000 --- a/.travis.yml +++ /dev/null @@ -1,48 +0,0 @@ -language: generic - -services: - - docker - -before_install: - - cp .env.test .env - - rm .ruby-version - - sudo rm /usr/local/bin/docker-compose - - curl -L https://github.com/docker/compose/releases/download/1.4.2/docker-compose-`uname -s`-`uname -m` > docker-compose - - chmod +x docker-compose - - sudo mv docker-compose /usr/local/bin - -script: - - docker-compose build - - docker-compose up -d - - docker-compose run web bundle exec rake - -notifications: - email: false - -addons: - code_climate: - repo_token: 2ad0d3196c872832cf5d6b34c83bf21dbf0a30e2191ba036be003b01e417a6a1 - -after_script: -- "./bin/codeclimate-batch --groups 2" -- docker pull 18fgsa/pa11y-crawl-docker -- docker-compose up -d -- docker run -t --net="host" 18fgsa/pa11y-crawl-docker pa11y-crawl http://localhost:3000 - -before_deploy: -- export PATH=$HOME:$PATH -- travis_retry curl -L -o $HOME/cf.tgz "https://cli.run.pivotal.io/stable?release=linux64-binary&version=6.22.2" -- tar xzvf $HOME/cf.tgz -C $HOME -- cf install-plugin autopilot -f -r CF-Community -- docker-compose run web bundle exec rake git:dump_sha -deploy: -- provider: script - script: "./bin/deploy.sh staging" - skip_cleanup: true - on: - branch: develop -- provider: script - script: "./bin/deploy.sh production" - skip_cleanup: true - on: - branch: master diff --git a/README.md b/README.md index 0da71844..42d6837a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![Code Climate](https://codeclimate.com/github/18F/micropurchase/badges/gpa.svg)](https://codeclimate.com/github/18F/micropurchase) [![Test Coverage](https://codeclimate.com/github/18F/micropurchase/badges/coverage.svg)](https://codeclimate.com/github/18F/micropurchase/coverage) [![Dependency Status](https://gemnasium.com/18F/micropurchase.svg)](https://gemnasium.com/18F/micropurchase) [![security](https://hakiri.io/github/18F/micropurchase/master.svg)](https://hakiri.io/github/18F/micropurchase/master) -[![Accessibility](https://continua11y.18f.gov/18F/micropurchase.svg?branch=develop)](https://continua11y.18f.gov/18F/micropurchase) +[![Accessibility](https://continua11y.18f.gov/18F/micropurchase.svg?branch=develop)](https://continua11y.18f.gov/18F/micropurchase) [![Build Status](https://circleci.com/gh/18F/micropurchase.svg?style=shield&circle-token=:circle-token)](https://circleci.com/gh/18F/micropurchase.svg?style=shield&circle-token=:circle-token) # Micro-purchase From 5749578e4eb58e8d2f3248d2c7f0fa09da70c4d0 Mon Sep 17 00:00:00 2001 From: Jacob Harris Date: Wed, 26 Jul 2017 13:47:45 -0400 Subject: [PATCH 5/5] Fix a few Gemfile issues flagged by CodeClimate --- Gemfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index efb081ab..cfc4a291 100644 --- a/Gemfile +++ b/Gemfile @@ -41,8 +41,8 @@ gem 'uswds-rails', github: '18F/uswds-rails-gem' gem 'rest-client' group :test do - gem "simplecov", require: nil gem 'dotenv' + gem "simplecov", require: nil gem 'db-query-matchers' gem 'json-schema' gem 'shoulda-matchers' @@ -51,8 +51,8 @@ group :test do end group :development, :test do - gem 'rspec_junit_formatter' gem 'rspec-rails' + gem 'rspec_junit_formatter' gem 'cucumber-rails', require: false gem 'capybara' gem 'poltergeist'