From 783cb1b63c51cf14cab700865357a98327194c0c Mon Sep 17 00:00:00 2001 From: Umekawa Date: Tue, 28 Jul 2020 11:11:28 +0900 Subject: [PATCH 1/6] Fix rspec --- spec/support/sandboxing.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/support/sandboxing.rb b/spec/support/sandboxing.rb index a9ef3ca..004d661 100644 --- a/spec/support/sandboxing.rb +++ b/spec/support/sandboxing.rb @@ -1,4 +1,5 @@ require 'circleci/coverage_reporter/sandbox' +require 'tmpdir' RSpec.configure do |c| c.around do |example| From c2e1c2e2fcc262aca48f326444c554d2c33798e3 Mon Sep 17 00:00:00 2001 From: Umekawa Date: Tue, 28 Jul 2020 11:12:31 +0900 Subject: [PATCH 2/6] Update faraday --- circleci-coverage_reporter.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circleci-coverage_reporter.gemspec b/circleci-coverage_reporter.gemspec index 39daba4..124f422 100644 --- a/circleci-coverage_reporter.gemspec +++ b/circleci-coverage_reporter.gemspec @@ -20,6 +20,6 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.add_dependency 'faraday', '~> 0.9' + spec.add_dependency 'faraday', '>= 0.9' , '< 2.0.0' spec.add_development_dependency 'bundler', '~> 1.12' end From c1330fea84762861bef7f0db739e5461d1c1e0b3 Mon Sep 17 00:00:00 2001 From: Kyle Troutner Date: Thu, 10 Sep 2020 15:46:16 +0900 Subject: [PATCH 3/6] Update CircleCI config to 2.0 --- .circleci/config.yml | 42 ++++++++++++++++++++++++++++++++++++++++++ circle.yml | 11 ----------- 2 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 .circleci/config.yml delete mode 100644 circle.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..2f337d1 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,42 @@ +version: 2.1 + +executors: + custom: + docker: + - image: circleci/ruby:2.4 + environment: + - CIRCLE_ARTIFACTS: /tmp/circleci-artifacts + - CIRCLE_TEST_REPORTS: /tmp/circleci-test-results + +commands: + setup: + steps: + - checkout + - run: bundle install + report_coverage: + steps: + - run: + name: Run coverage reporter + command: | + bundle exec rake rubycritic + bundle exec yard doc -o $CIRCLE_ARTIFACTS/doc + bundle exec rake circleci:report_coverage + +jobs: + tests: + executor: custom + steps: + - setup + - run: + name: Run rspec + command: bundle exec rspec --format progress --require rspec_junit_formatter --format RspecJunitFormatter -o $CIRCLE_TEST_REPORTS/rspec/junit.xml + - run: + name: Run rubocop + command: bundle exec rubocop + - report_coverage + +workflows: + version: 2 + tests: + jobs: + - tests diff --git a/circle.yml b/circle.yml deleted file mode 100644 index 14aa3d7..0000000 --- a/circle.yml +++ /dev/null @@ -1,11 +0,0 @@ -machine: - ruby: - version: 2.4.0 -test: - override: - - bundle exec rspec --format progress --require rspec_junit_formatter --format RspecJunitFormatter -o $CIRCLE_TEST_REPORTS/rspec/junit.xml - - bundle exec rubocop - post: - - bundle exec rake rubycritic - - bundle exec yard doc -o $CIRCLE_ARTIFACTS/doc - - bundle exec rake circleci:report_coverage From 0e352fb5d55ef8b739c6846f71a10af7103b41bf Mon Sep 17 00:00:00 2001 From: Kyle Troutner Date: Thu, 8 Oct 2020 16:01:07 +0900 Subject: [PATCH 4/6] Fix rubocop warning --- .rubocop.yml | 3 +++ Gemfile | 1 + 2 files changed, 4 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 844fa43..2d282df 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,6 @@ +require: + - rubocop-performance + AllCops: TargetRubyVersion: 2.4 diff --git a/Gemfile b/Gemfile index 82eec4d..ec9d451 100644 --- a/Gemfile +++ b/Gemfile @@ -8,6 +8,7 @@ group :development, :test do gem 'rspec', '~> 3.5' gem 'rspec_junit_formatter', '~> 0.2', require: false gem 'rubocop', '~> 0.42' + gem 'rubocop-performance' gem 'rubycritic', '~> 3.1', require: false gem 'simplecov', '~> 0.13' gem 'yard', '~> 0.9' From 974768201114f0bfec4a67820f5a8f86ff4a1776 Mon Sep 17 00:00:00 2001 From: Kyle Troutner Date: Thu, 8 Oct 2020 16:02:04 +0900 Subject: [PATCH 5/6] Fix rubocop errors --- circleci-coverage_reporter.gemspec | 6 ++---- lib/circleci/coverage_reporter.rb | 1 + lib/circleci/coverage_reporter/client.rb | 4 ++++ lib/circleci/coverage_reporter/configuration.rb | 8 ++++---- lib/circleci/coverage_reporter/report.rb | 4 ++++ lib/circleci/coverage_reporter/reporters/link.rb | 1 + lib/circleci/coverage_reporter/runner.rb | 5 +++-- 7 files changed, 19 insertions(+), 10 deletions(-) diff --git a/circleci-coverage_reporter.gemspec b/circleci-coverage_reporter.gemspec index 124f422..3c13122 100644 --- a/circleci-coverage_reporter.gemspec +++ b/circleci-coverage_reporter.gemspec @@ -1,6 +1,4 @@ -# coding: utf-8 - -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'circleci/coverage_reporter/version' @@ -20,6 +18,6 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.add_dependency 'faraday', '>= 0.9' , '< 2.0.0' + spec.add_dependency 'faraday', '>= 0.9', '< 2.0.0' spec.add_development_dependency 'bundler', '~> 1.12' end diff --git a/lib/circleci/coverage_reporter.rb b/lib/circleci/coverage_reporter.rb index c32c640..2bbb742 100644 --- a/lib/circleci/coverage_reporter.rb +++ b/lib/circleci/coverage_reporter.rb @@ -38,6 +38,7 @@ def self.run configuration.reporters.select!(&:active?) configuration.dump raise NoActiveReporter if configuration.reporters.empty? + Runner.new.tap(&:dump).run end end diff --git a/lib/circleci/coverage_reporter/client.rb b/lib/circleci/coverage_reporter/client.rb index a186a55..7c62f75 100644 --- a/lib/circleci/coverage_reporter/client.rb +++ b/lib/circleci/coverage_reporter/client.rb @@ -18,9 +18,11 @@ class Client # @see https://circleci.com/docs/api/v1-reference/#build def single_build(build_number) return unless build_number + resp = get(single_build_url(build_number)) body = JSON.parse(resp.body) raise RequestError.new(body['message'], resp) unless resp.success? + create_build(body) end @@ -34,6 +36,7 @@ def artifacts(build_number) resp = get(artifacts_url(build_number)) body = JSON.parse(resp.body) raise RequestError.new(body['message'], resp) unless resp.success? + body.map(&method(:create_artifact)) end @@ -84,6 +87,7 @@ def recent_builds(branch) resp = get(recent_builds_url(branch), limit: 100) body = JSON.parse(resp.body) raise RequestError.new(body['message'], resp) unless resp.success? + body.map(&method(:create_build)) end diff --git a/lib/circleci/coverage_reporter/configuration.rb b/lib/circleci/coverage_reporter/configuration.rb index 2110c59..2109bac 100644 --- a/lib/circleci/coverage_reporter/configuration.rb +++ b/lib/circleci/coverage_reporter/configuration.rb @@ -14,7 +14,7 @@ class Configuration attr_accessor :circleci_token, :vcs_token attr_writer :artifacts_dir, :base_revision, :current_build_number, :current_revision, :previous_build_number, - :reporters, :repository_name, :template, :template_safe_mode, :template_safe_mode, :user_name, :vcs_type + :reporters, :repository_name, :template, :template_safe_mode, :user_name, :vcs_type # @return [String] def project @@ -53,7 +53,7 @@ def current_revision # @return [Integer, nil] def previous_build_number - @previous_build_number ||= ENV['CIRCLE_PREVIOUS_BUILD_NUM'] && ENV['CIRCLE_PREVIOUS_BUILD_NUM'].to_i + @previous_build_number ||= ENV['CIRCLE_PREVIOUS_BUILD_NUM']&.to_i end # @return [String] @@ -68,7 +68,7 @@ def user_name # @return [void] def dump # rubocop:disable AbcSize - puts <<~EOF + puts <<~TEXT Configuration | Value ----------------------|---------------------------------------------------------------------------- artifacts_dir | #{artifacts_dir.inspect} @@ -82,7 +82,7 @@ def dump # rubocop:disable AbcSize user_name | #{user_name.inspect} vcs_token | #{vcs_token[-4..-1].rjust(40, '*').inspect} vcs_type | #{vcs_type.inspect} - EOF + TEXT end end end diff --git a/lib/circleci/coverage_reporter/report.rb b/lib/circleci/coverage_reporter/report.rb index 5e74695..2b8841c 100644 --- a/lib/circleci/coverage_reporter/report.rb +++ b/lib/circleci/coverage_reporter/report.rb @@ -63,24 +63,28 @@ def branch_progress # @return [String, nil] def pretty_base_diff return unless base_diff + pretty_diff(base_diff.round(2)) end # @return [String, nil] def pretty_branch_diff return unless branch_diff + pretty_diff(branch_diff.round(2)) end # @return [Float, nil] def base_diff return unless base_result + current_result.coverage - base_result.coverage end # @return [Float, nil] def branch_diff return unless previous_result + current_result.coverage - previous_result.coverage end diff --git a/lib/circleci/coverage_reporter/reporters/link.rb b/lib/circleci/coverage_reporter/reporters/link.rb index 0204ba5..672622e 100644 --- a/lib/circleci/coverage_reporter/reporters/link.rb +++ b/lib/circleci/coverage_reporter/reporters/link.rb @@ -65,6 +65,7 @@ def configuration # @return [String, nil] def extract_artifact_url(build) return unless build + artifact = build.find_artifact(path) artifact ? artifact.url : nil end diff --git a/lib/circleci/coverage_reporter/runner.rb b/lib/circleci/coverage_reporter/runner.rb index 0f9abf7..26dd104 100644 --- a/lib/circleci/coverage_reporter/runner.rb +++ b/lib/circleci/coverage_reporter/runner.rb @@ -11,13 +11,13 @@ def run # @return [void] def dump - puts <<~EOF + puts <<~TEXT Runner | Value ------------------|----------------------------------------------------------------------------------- base_build | #{base_build.inspect} base_build_number | #{base_build_number.inspect} previous_build | #{previous_build.inspect} - EOF + TEXT end private @@ -70,6 +70,7 @@ def reporters # @return [Integer, nil] def base_build_number return if configuration.base_revision == configuration.current_revision + @base_build_number ||= client.build_number_by_revision(base_revision, branch: 'master') end end From 3bbdba6452e764a372c06d508293fdc6fcc7cfb6 Mon Sep 17 00:00:00 2001 From: Kyle Troutner Date: Thu, 8 Oct 2020 16:40:30 +0900 Subject: [PATCH 6/6] Specify library versions --- .ruby-version | 1 + Gemfile | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 .ruby-version diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..59aa62c --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.4.5 diff --git a/Gemfile b/Gemfile index ec9d451..d84871a 100644 --- a/Gemfile +++ b/Gemfile @@ -3,13 +3,13 @@ source 'https://rubygems.org' gemspec group :development, :test do - gem 'ffaker', '~> 2.5' + gem 'ffaker', '~> 2.5.0' gem 'rake', '~> 11.0' gem 'rspec', '~> 3.5' gem 'rspec_junit_formatter', '~> 0.2', require: false gem 'rubocop', '~> 0.42' gem 'rubocop-performance' gem 'rubycritic', '~> 3.1', require: false - gem 'simplecov', '~> 0.13' + gem 'simplecov', '~> 0.13.0' gem 'yard', '~> 0.9' end