From 6214a200f31ac9500e18ba14f6fc284a2e58d2cf Mon Sep 17 00:00:00 2001 From: Daniel Fowler Date: Thu, 15 Jun 2023 15:11:03 +0700 Subject: [PATCH] Add test coverage reporting to Sonarcloud (#54) * Add test coverage reporting --- .github/workflows/code-coverage.yml | 27 +++++++++++++++++++++++++++ omise.gemspec | 1 + sonar-project.properties | 3 +++ test/support.rb | 7 +++++++ 4 files changed, 38 insertions(+) create mode 100644 .github/workflows/code-coverage.yml create mode 100644 sonar-project.properties diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml new file mode 100644 index 0000000..b6c43ba --- /dev/null +++ b/.github/workflows/code-coverage.yml @@ -0,0 +1,27 @@ +name: Push Test Coverage to SonarCloud + +on: + push: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: "3.2" + bundler-cache: true + - name: Build and test with Rake + run: | + gem install bundler + bundle install --jobs 4 --retry 3 + bundle exec rake test + - run: | + rm -rf vendor + - name: Fix Code Coverage Paths + run: sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' coverage/coverage.json + - name: SonarCloud Scan + uses: SonarSource/sonarcloud-github-action@master + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/omise.gemspec b/omise.gemspec index b255342..9b4ee24 100644 --- a/omise.gemspec +++ b/omise.gemspec @@ -24,4 +24,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "rake" spec.add_development_dependency "pry" spec.add_development_dependency "minitest", ">= 5.4" + spec.add_development_dependency "simplecov" end diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 0000000..a08b5d1 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,3 @@ +sonar.projectKey=omise_omise-ruby +sonar.organization=omise +sonar.exclusions=**/test/** diff --git a/test/support.rb b/test/support.rb index bfa0fe6..beaffc92 100644 --- a/test/support.rb +++ b/test/support.rb @@ -1,3 +1,10 @@ +require "simplecov" +require "simplecov_json_formatter" +SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter +SimpleCov.start do + add_filter "test/" +end + require "rubygems" require "bundler/setup"