From b478722acee3a1bf141499b0359efa41679a5c09 Mon Sep 17 00:00:00 2001 From: Joakim Antman Date: Sun, 30 Oct 2022 20:44:23 +0200 Subject: [PATCH] Collect coverage from all previous tests --- .github/workflows/coverage.yml | 27 --------------------------- .github/workflows/test.yml | 26 ++++++++++++++++++++++++++ .simplecov | 15 +++++++++++++++ Rakefile | 14 +++++--------- spec/spec_helper.rb | 9 +-------- 5 files changed, 47 insertions(+), 44 deletions(-) delete mode 100644 .github/workflows/coverage.yml create mode 100644 .simplecov diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml deleted file mode 100644 index 46f8dd7d..00000000 --- a/.github/workflows/coverage.yml +++ /dev/null @@ -1,27 +0,0 @@ ---- -name: coverage -on: - push: - branches: - - "main" -jobs: - coverage: - name: coverage - runs-on: ubuntu-20.04 - env: - BUNDLE_GEMFILE: 'gemfiles/rbnacl.gemfile' - CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} - steps: - - uses: actions/checkout@v2 - - name: Install libsodium - run: | - sudo apt-get update -q - sudo apt-get install libsodium-dev -y - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: "2.7" - bundler-cache: true - - uses: paambaati/codeclimate-action@v3.0.0 - with: - coverageCommand: bundle exec rspec diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4c358fa2..c7ab9b47 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -73,3 +73,29 @@ jobs: - name: Run tests run: bundle exec rspec + + - name: Upload test coverage folder for later reporting + uses: actions/upload-artifact@v3 + with: + name: coverage-reports + path: ${{github.workspace}}/coverage-*/coverage.json + retention-days: 1 + + coverage: + name: Report coverage to Code Climate + runs-on: ubuntu-20.04 + needs: test + if: success() && github.ref == 'refs/heads/main' + env: + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} + steps: + - uses: actions/checkout@v3 + + - name: Download coverage reports from the test job + uses: actions/download-artifact@v3 + with: + name: coverage-reports + + - uses: paambaati/codeclimate-action@v3.2.0 + with: + coverageLocations: "coverage-*/coverage.json:simplecov" diff --git a/.simplecov b/.simplecov new file mode 100644 index 00000000..e3e3dee1 --- /dev/null +++ b/.simplecov @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require 'openssl' +require 'simplecov_json_formatter' + +SimpleCov.start do + command_name "Job #{File.basename(ENV['BUNDLE_GEMFILE'])}" if ENV['BUNDLE_GEMFILE'] + project_name 'Ruby JWT - Ruby JSON Web Token implementation' + coverage_dir "coverage-#{::OpenSSL::Digest::SHA256.hexdigest(ENV['GITHUB_STEP_SUMMARY'])}" if ENV['GITHUB_STEP_SUMMARY'] + add_filter 'spec' +end + +if ENV['CI'] + SimpleCov.formatters = SimpleCov::Formatter::JSONFormatter +end diff --git a/Rakefile b/Rakefile index 49dc3f72..3fdf1d38 100644 --- a/Rakefile +++ b/Rakefile @@ -3,14 +3,10 @@ require 'bundler/setup' require 'bundler/gem_tasks' -begin - require 'rspec/core/rake_task' - require 'rubocop/rake_task' +require 'rspec/core/rake_task' +require 'rubocop/rake_task' - RSpec::Core::RakeTask.new(:test) - RuboCop::RakeTask.new(:rubocop) +RSpec::Core::RakeTask.new(:test) +RuboCop::RakeTask.new(:rubocop) - task default: %i[rubocop test] -rescue LoadError - puts 'RSpec rake tasks not available. Please run "bundle install" to install missing dependencies.' -end +task default: %i[rubocop test] diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5b91b684..f29c496b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,20 +2,13 @@ require 'rspec' require 'simplecov' - -SimpleCov.start do - root File.join(File.dirname(__FILE__), '..') - project_name 'Ruby JWT - Ruby JSON Web Token implementation' - add_filter 'spec' -end - require 'jwt' puts "OpenSSL::VERSION: #{OpenSSL::VERSION}" puts "OpenSSL::OPENSSL_VERSION: #{OpenSSL::OPENSSL_VERSION}" puts "OpenSSL::OPENSSL_LIBRARY_VERSION: #{OpenSSL::OPENSSL_LIBRARY_VERSION}\n\n" -CERT_PATH = File.join(File.dirname(__FILE__), 'fixtures', 'certs') +CERT_PATH = File.join(__dir__, 'fixtures', 'certs') RSpec.configure do |config| config.expect_with :rspec do |c|