Skip to content

Commit 27d9d22

Browse files
authored
chore(ci): report coverage (#64)
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
1 parent e9ea4e3 commit 27d9d22

5 files changed

Lines changed: 53 additions & 2 deletions

File tree

.github/workflows/ruby.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ on:
1414
# see https://docs.github.com/en/actions/how-tos/writing-workflows/choosing-what-your-workflow-does/controlling-permissions-for-github_token
1515
permissions: {}
1616

17+
concurrency:
18+
group: '${{ github.workflow }}-${{ github.ref }}'
19+
cancel-in-progress: true
20+
21+
env:
22+
COVERAGE_DIR: coverage
23+
TESTS_COVERAGE_ARTIFACT: coverage
24+
1725
jobs:
1826
test:
1927
name: Ruby ${{ matrix.ruby }}
@@ -39,3 +47,34 @@ jobs:
3947
bundler-cache: true
4048
- name: Run the default task
4149
run: bundle exec rake
50+
- name: Artifact coverage
51+
if: ${{ ! cancelled() }}
52+
# see https://github.com/actions/upload-artifact
53+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
54+
with:
55+
name: '${{ env.TESTS_COVERAGE_ARTIFACT }}_ruby${{ matrix.ruby }}'
56+
path: ${{ env.COVERAGE_DIR }}
57+
if-no-files-found: error
58+
retention-days: 7
59+
report-coverage:
60+
name: Publish test coverage
61+
needs: [ "test" ]
62+
runs-on: ubuntu-latest
63+
timeout-minutes: 5
64+
steps:
65+
- name: fetch test artifacts
66+
# see https://github.com/actions/download-artifact
67+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
68+
with:
69+
pattern: '${{ env.TESTS_COVERAGE_ARTIFACT }}_*'
70+
merge-multiple: false
71+
- name: Run codacy-coverage-reporter
72+
env:
73+
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
74+
## see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-secrets
75+
if: ${{ env.CODACY_PROJECT_TOKEN != '' }}
76+
# see https://github.com/codacy/codacy-coverage-reporter-action
77+
uses: codacy/codacy-coverage-reporter-action@89d6c85cfafaec52c72b6c5e8b2878d33104c699 # v1
78+
with:
79+
project-token: ${{ env.CODACY_PROJECT_TOKEN }}
80+
coverage-reports: '${{ env.TESTS_COVERAGE_ARTIFACT }}_*/coverage.xml'

.simplecov

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# frozen_string_literal: true
22

3+
require 'simplecov-cobertura'
4+
5+
SimpleCov.formatters = [
6+
SimpleCov::Formatter::HTMLFormatter,
7+
SimpleCov::Formatter::CoberturaFormatter
8+
]
9+
310
# Copied from https://github.com/cucumber/aruba/blob/3b1a6cea6e3ba55370c3396eef0a955aeb40f287/.simplecov
411
# Licensed under MIT - https://github.com/cucumber/aruba/blob/3b1a6cea6e3ba55370c3396eef0a955aeb40f287/LICENSE
512

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![Gem Version](https://img.shields.io/gem/v/cyclonedx-ruby?logo=rubygems&logoColor=white)](https://rubygems.org/gems/cyclonedx-ruby)
44
[![CT status](https://img.shields.io/github/actions/workflow/status/CycloneDX/cyclonedx-ruby-gem/ruby.yml?branch=master&logo=GitHub&logoColor=white)](https://github.com/CycloneDX/cyclonedx-ruby-gem/actions/workflows/ruby.yml?query=branch%3Amaster)
5+
[![shield_coverage]][link_codacy]
56
[![License](https://img.shields.io/github/license/CycloneDX/cyclonedx-ruby-gem?logo=open%20source%20initiative&logoColor=white)][license_file]
67
[![Website](https://img.shields.io/badge/https://-cyclonedx.org-blue.svg)](https://cyclonedx.org/)
78
[![Slack Invite](https://img.shields.io/badge/Slack-Join-blue?logo=slack&labelColor=393939)](https://cyclonedx.org/slack/invite)
@@ -64,3 +65,6 @@ CycloneDX Ruby Gem is Copyright (c) OWASP Foundation. All Rights Reserved.
6465
Permission to modify and redistribute is granted under the terms of the Apache 2.0 license. See the [LICENSE][license_file] file for the full license.
6566

6667
[license_file]: https://github.com/CycloneDX/cyclonedx-ruby-gem/blob/master/LICENSE.txt
68+
69+
[shield_coverage]: https://img.shields.io/codacy/coverage/de2bfb229a81439b8974b5e3d0af4e1a?logo=Codacy&logoColor=white "test coverage"
70+
[link_codacy]: https://app.codacy.com/gh/CycloneDX/cyclonedx-ruby-gem

cyclonedx-ruby.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Gem::Specification.new do |spec|
6464
spec.add_development_dependency 'cucumber', '>= 9.2.0', '< 11'
6565
spec.add_development_dependency 'aruba', '~> 2.2'
6666
spec.add_development_dependency 'simplecov', '~> 0.22.0'
67+
spec.add_development_dependency 'simplecov-cobertura'
6768
spec.add_development_dependency 'rubocop', '~> 1.54'
6869
spec.add_development_dependency 'stone_checksums', '~> 1.0', '>= 1.0.3'
6970
end

spec/spec_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
require 'simplecov'
1919
SimpleCov.command_name 'RSpec'
2020

21-
# Run simplecov by default
22-
SimpleCov.start unless ENV.key? 'ARUBA_NO_COVERAGE'
21+
aruba_no_coverage = ENV.fetch('ARUBA_NO_COVERAGE', 'false')
22+
SimpleCov.start unless aruba_no_coverage.casecmp?('true')
2323
end
2424
# End copied from Aruba
2525

0 commit comments

Comments
 (0)