From ec35613a8dec7c557e85e163993faada231bd5d3 Mon Sep 17 00:00:00 2001 From: Alex Skrenchuk Date: Fri, 7 Nov 2025 17:44:47 -0800 Subject: [PATCH 1/2] Add code coverage --- .github/workflows/ruby.yml | 16 ++++++++++++---- .gitignore | 7 +++++-- Gemfile | 2 ++ Gemfile.lock | 19 ++++++++++++++++--- test/test_case.rb | 16 ++++++++++++++++ 5 files changed, 51 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 0650cf0..56eb6ed 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -9,19 +9,22 @@ name: Ruby on: push: + branches: + - '**' # run on all branches + tags-ignore: + - '**' # skip all tags pull_request_target: - types: [opened, reopened] + types: [opened, reopened, synchronize] jobs: test: - runs-on: ubuntu-latest strategy: fail-fast: false matrix: ruby-version: ['3.1'] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v5 - name: Set up Ruby # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, # change this to (see https://github.com/ruby/setup-ruby#versioning): @@ -30,8 +33,13 @@ jobs: ruby-version: ${{ matrix.ruby-version }} bundler-cache: true # runs 'bundle install' and caches installed gems automatically - name: set up config file - run: cp config/config.test.rb config/config.rb + run: cp config/config.test.rb config/config.rb - name: Run tests env: UT_APIKEY: ${{ secrets.UT_APIKEY }} run: bundle exec rake test TESTOPTS="-v" + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v5 + with: + flags: ${{ matrix.ruby-version }} + verbose: true diff --git a/.gitignore b/.gitignore index 9c6de78..446fd6d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,12 @@ *.gem .DS_Store -config/config.rb +/config/config.rb # Specific to IntelliJ .idea/ # Specific to rbenv -.ruby-version \ No newline at end of file +.ruby-version + +# Codecov local cache +/coverage/ diff --git a/Gemfile b/Gemfile index cd1e8ba..3d9f833 100644 --- a/Gemfile +++ b/Gemfile @@ -7,3 +7,5 @@ gemspec gem 'pry' gem 'rake' gem 'rubocop', '~> 1.43' +gem "simplecov", require: false +gem "simplecov-cobertura", require: false diff --git a/Gemfile.lock b/Gemfile.lock index be3816e..7b27f71 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -36,6 +36,7 @@ GEM coderay (1.1.3) concurrent-ruby (1.3.5) connection_pool (2.5.4) + docile (1.4.1) drb (2.2.3) excon (1.3.1) logger @@ -50,11 +51,11 @@ GEM faraday (>= 1, < 3) faraday-multipart (1.1.1) multipart-post (~> 2.0) - faraday-net_http (3.4.1) - net-http (>= 0.5.0) + faraday-net_http (3.4.2) + net-http (~> 0.5) i18n (1.14.7) concurrent-ruby (~> 1.0) - json (2.15.2) + json (2.16.0) language_server-protocol (3.17.0.5) lint_roller (1.1.0) logger (1.7.0) @@ -84,6 +85,7 @@ GEM rainbow (3.1.1) rake (13.3.1) regexp_parser (2.11.3) + rexml (3.4.4) rubocop (1.81.7) json (~> 2.3) language_server-protocol (~> 3.17.0.2) @@ -100,6 +102,15 @@ GEM prism (~> 1.4) ruby-progressbar (1.13.0) securerandom (0.4.1) + simplecov (0.22.0) + docile (~> 1.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-cobertura (3.1.0) + rexml + simplecov (~> 0.19) + simplecov-html (0.13.2) + simplecov_json_formatter (0.1.4) tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (3.2.0) @@ -119,6 +130,8 @@ DEPENDENCIES pry rake rubocop (~> 1.43) + simplecov + simplecov-cobertura BUNDLED WITH 2.6.9 diff --git a/test/test_case.rb b/test/test_case.rb index cc9e209..b4bc8a4 100644 --- a/test/test_case.rb +++ b/test/test_case.rb @@ -1,4 +1,20 @@ # frozen_string_literal: true +# Start simplecov if this is a coverage task or if it is run in the CI pipeline +if ENV['COVERAGE'] || ENV['CI'] + require 'simplecov' + require 'simplecov-cobertura' + + SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([ + SimpleCov::Formatter::HTMLFormatter, + SimpleCov::Formatter::CoberturaFormatter, # writes coverage/cobertura.xml + ]) + + SimpleCov.start do + enable_coverage :branch + add_filter %w[/test/ /config/] + end +end + require 'bundler/setup' require 'pry' require 'minitest/autorun' From 4e5c0d88a2f66abdd69989560f8cf8b1bd95baeb Mon Sep 17 00:00:00 2001 From: Alex Skrenchuk Date: Fri, 7 Nov 2025 17:48:50 -0800 Subject: [PATCH 2/2] add codecov token --- .github/workflows/ruby.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 56eb6ed..7564131 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -41,5 +41,6 @@ jobs: - name: Upload coverage to Codecov uses: codecov/codecov-action@v5 with: + token: ${{ secrets.CODECOV_TOKEN }} flags: ${{ matrix.ruby-version }} verbose: true