From faeca4263add304008ff6d464a4fe053fccacd37 Mon Sep 17 00:00:00 2001 From: Abhimanyu Singh Date: Tue, 18 Jan 2022 23:38:23 +0530 Subject: [PATCH] Add CodeClimate (#2) Configure CodeClimate analysis and code coverage report. --- .github/workflows/ci.yml | 60 ++++++++++++++++++++++++++++++++++++++++ README.md | 3 ++ spec/spec_helper.rb | 6 ++++ 3 files changed, 69 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 23b1e05..31cea2b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,6 +46,13 @@ jobs: with: ruby-version: ${{ matrix.ruby }} + - name: Setup Code Climate test-reporter + if: ${{ matrix.os == 'ubuntu-latest' }} + run: | + curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter + chmod +x ./cc-test-reporter + ./cc-test-reporter before-build + - name: Install Dependencies run: | gem update --system 3.2.3 @@ -54,3 +61,56 @@ jobs: - name: Run Tests run: bundle exec rake + + - name: Format Coverage Report + if: ${{ matrix.os == 'ubuntu-latest' }} + env: + GIT_BRANCH: ${{ github.event_name == 'pull_request' && github.head_ref || 'main' }} + GIT_COMMIT_SHA: ${{ github.sha }} + run: | + mkdir -p coverage-artifacts + ./cc-test-reporter format-coverage coverage/coverage.json --input-type simplecov --output coverage-artifacts/ruby-${{ matrix.ruby }}-coverage.json + + - name: Save Coverage Report + if: ${{ matrix.os == 'ubuntu-latest' }} + uses: actions/upload-artifact@v2 + with: + name: ruby-${{ matrix.ruby }}-coverage.json + path: coverage-artifacts/ruby-${{ matrix.ruby }}-coverage.json + retention-days: 1 + + coverage: + needs: [ 'main' ] + name: coverage + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup Code Climate test-reporter + run: | + curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter + chmod +x ./cc-test-reporter + ./cc-test-reporter before-build + + - name: Download Coverage Reports + uses: actions/download-artifact@v2 + with: + path: coverage-artifacts-temp + + - name: Finalize Artifacts + run: | + mkdir -p coverage-artifacts + find coverage-artifacts-temp -mindepth 2 -type f -exec mv -i '{}' coverage-artifacts ';' + + - name: Upload Coverage + env: + GIT_BRANCH: ${{ github.event_name == 'pull_request' && github.head_ref || 'main' }} + GIT_COMMIT_SHA: ${{ github.sha }} + CC_TEST_REPORTER_ID: "23d80ff322cb6f334d19fd049df07430140bc2c9eb9567711a17387a5378f9c1" + run: | + ./cc-test-reporter sum-coverage coverage-artifacts/ruby-*-coverage.json --parts 11 --output coverage-artifacts/coverage.json + ./cc-test-reporter upload-coverage --input coverage-artifacts/coverage.json diff --git a/README.md b/README.md index 5c76158..6accf9b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +[![Maintainability](https://api.codeclimate.com/v1/badges/906b5c8d15a66897d350/maintainability)](https://codeclimate.com/github/avmnu-sng/clepsydra/maintainability) +[![Test Coverage](https://api.codeclimate.com/v1/badges/906b5c8d15a66897d350/test_coverage)](https://codeclimate.com/github/avmnu-sng/clepsydra/test_coverage) + # Clepsydra **Clepsydra** is an instrumentation tool allowing instrumenting events. You can diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cc23d60..d1ca405 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,10 +2,16 @@ require 'pry' require 'simplecov' +require 'simplecov_json_formatter' require 'timecop' require 'clepsydra' +SimpleCov.formatters = [ + SimpleCov::Formatter::HTMLFormatter, + SimpleCov::Formatter::JSONFormatter +].freeze + RSpec.configure do |config| config.example_status_persistence_file_path = 'spec/examples.txt' config.disable_monkey_patching!