Skip to content

Commit

Permalink
chore: generate json coverage report
Browse files Browse the repository at this point in the history
  • Loading branch information
dasheck0 committed Aug 27, 2024
1 parent d21ee47 commit 715aa8d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 39 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test_and_scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ jobs:

- name: Test
run: |
bundle exec rake -- test
bundle exec rake -- spec
- name: Store coverage report
if: always()
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: coverage/.resultset.json
path: coverage/coverage.json

sonar:
runs-on: ubuntu-20.04
Expand All @@ -74,7 +74,7 @@ jobs:
- name: Check
run: |
ls -la coverage
cat coverage/.resultset.json
cat coverage/coverage.json
- name: Run SonarCloud Scan
uses: sonarsource/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sonar.organization=payone-gmbh
sonar.projectName=PCP-ServerSDK-ruby

sonar.sources=./lib
sonar.ruby.coverage.reportPaths=coverage/.resultset.json
sonar.ruby.coverage.reportPaths=coverage/coverage.json

sonar.coverage.exclusions=test/**/*.rb,example-app/**/*.rb,lib/PCP-server-Ruby-SDK/version.rb,lib/PCP-server-Ruby-SDK/models/**/*.rb,lib/PCP-server-Ruby-SDK/PCP-server-Ruby-SDK.rb
sonar.exclusions=lib/PCP-server-Ruby-SDK/models/**/*.rb
40 changes: 5 additions & 35 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,18 @@

require 'simplecov'
require "simplecov-html"
require 'fileutils'
require 'json'
require 'time'


class SimpleCov::Formatter::SonarCloudFormatter
def format(result)
# Extract the coverage data
coverage_data = result.original_result

# Remove the "Minitest" key, if it exists
coverage_data = coverage_data["Minitest"] if coverage_data.key?("Minitest")

meta_data = {
"simplecov_version" => SimpleCov::VERSION
}

# Write the result to a JSON file in the correct format
File.open(File.join(SimpleCov.coverage_path, '.resultset.json'), 'w') do |file|
file.puts JSON.pretty_generate({
"meta" => meta_data,
"coverage" => coverage_data
})
end

puts "Coverage report generated for SonarCloud: #{SimpleCov.coverage_path}/.resultset.json"
end
end

# FileUtils.rm_rf(SimpleCov.coverage_path) if File.directory?(SimpleCov.coverage_path)
require "simplecov_json_formatter"

SimpleCov.start do
add_filter '/test/' # Ignore test files from coverage
add_filter '/lib/PCP-server-Ruby-SDK/version.rb'
add_filter '/lib/PCP-server-Ruby-SDK/models'
add_filter '/example-app/'
add_filter '/spec/'

# SimpleCov.formatters = [
# SimpleCov::Formatter::SonarCloudFormatter,
# SimpleCov::Formatter::HTMLFormatter,
# ]
SimpleCov.formatters = [
SimpleCov::Formatter::JSONFormatter,
SimpleCov::Formatter::HTMLFormatter,
]

use_merging false
end
Expand Down

0 comments on commit 715aa8d

Please sign in to comment.