From 0daa49445a977ab9ee990be84e51db2ebf288e15 Mon Sep 17 00:00:00 2001 From: Guido de Jong <35309288+guidojw@users.noreply.github.com> Date: Wed, 27 Nov 2024 15:40:12 +0100 Subject: [PATCH] feat(tests): add code coverage reporting (#891) * feat(tests): add code coverage reporting * fix: correct coverage path * refactor: use simplecov-lcov * fix: indentation in Gemfile.lock * fix: remove test filters * feat(README): add badge * refactor: try tokenless report uploading * chore: update codecov-action * chore: update codecov-action * fix(cd): pass CODECOV_TOKEN To ci --- .github/workflows/continuous-delivery.yml | 1 + .github/workflows/continuous-integration.yml | 21 +++++++++++++++++++- Gemfile | 1 + Gemfile.lock | 4 +++- README.md | 1 + spec/spec_helper.rb | 13 ++++-------- 6 files changed, 30 insertions(+), 11 deletions(-) diff --git a/.github/workflows/continuous-delivery.yml b/.github/workflows/continuous-delivery.yml index 738ed981c..ae51732d9 100644 --- a/.github/workflows/continuous-delivery.yml +++ b/.github/workflows/continuous-delivery.yml @@ -124,6 +124,7 @@ jobs: with: sha: ${{ needs.merge.outputs.sha }} secrets: + codecov_token: ${{ secrets.CODECOV_TOKEN }} rails_master_key: ${{ secrets.RAILS_MASTER_KEY }} publish_image: diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 4510d3309..1998113df 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -12,6 +12,9 @@ on: required: false type: string secrets: + codecov_token: + description: Codecov token + required: true rails_master_key: description: The Rails master key required: true @@ -119,5 +122,21 @@ jobs: env: RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }} run: | + mkdir coverage docker run -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_HOST=localhost -e \ - RAILS_MASTER_KEY --network=host app bin/ci.sh spec + RAILS_MASTER_KEY --network=host -v "$(pwd)"'/coverage:/app/coverage' app bin/ci.sh spec + + - name: Upload coverage report to Codecov + if: ${{ !cancelled() }} + uses: codecov/codecov-action@54bcd8715eee62d40e33596ef5e8f0f48dbbccab # v4.1.0 + with: + fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} + + - name: Upload coverage report artifact + if: ${{ !cancelled() }} + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 + with: + name: coverage + path: coverage/ + if-no-files-found: error diff --git a/Gemfile b/Gemfile index 6fe160eda..1caa202cc 100644 --- a/Gemfile +++ b/Gemfile @@ -79,6 +79,7 @@ group :test do gem 'rubocop-rails' gem 'rubocop-rspec' gem 'simplecov', require: false + gem 'simplecov-lcov', '~> 0.8.0', require: false gem 'terminal-notifier-guard' gem 'timecop' end diff --git a/Gemfile.lock b/Gemfile.lock index 295ceff29..efb153310 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -464,6 +464,7 @@ GEM simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) simplecov-html (0.12.3) + simplecov-lcov (0.8.0) simplecov_json_formatter (0.1.4) slack-notifier (2.4.0) spring (2.1.1) @@ -589,6 +590,7 @@ DEPENDENCIES sidekiq-scheduler (~> 5.0.2) simple_form (~> 5.1.0) simplecov + simplecov-lcov (~> 0.8.0) slack-notifier (~> 2.4.0) spring spring-commands-rspec @@ -605,4 +607,4 @@ DEPENDENCIES wkhtmltopdf-binary BUNDLED WITH - 2.2.15 + 2.4.14 diff --git a/README.md b/README.md index 2613efb97..6cd9dab59 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ Alpha SOFIA [![Continuous Integration](https://github.com/csvalpha/sofia/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/csvalpha/sofia/actions/workflows/continuous-integration.yml) [![Continuous Delivery](https://github.com/csvalpha/sofia/actions/workflows/continuous-delivery.yml/badge.svg)](https://github.com/csvalpha/sofia/actions/workflows/continuous-delivery.yml) +[![codecov](https://codecov.io/github/csvalpha/sofia/graph/badge.svg?token=RGR5PARLD5)](https://codecov.io/github/csvalpha/sofia) The source code belonging to Alpha SOFIA. It is a system built with Ruby on Rails with Turbolinks and a little VueJS, used to manage orders in our own bar "Flux". Users authenticate via OAuth API (currently "Alpha AMBER") to see how much credit they got left, or to be able to register new orders and/or payments. diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8fa233880..a5f96ef4f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,15 +1,10 @@ require 'simplecov' +require 'simplecov-lcov' +SimpleCov.formatter = SimpleCov::Formatter::LcovFormatter SimpleCov.start 'rails' do - add_filter 'app/controllers/' - add_filter 'app/jobs/' - add_filter 'app/mailers/' - add_filter 'app/policies/' - add_filter 'app/views/' - add_filter 'lib/' - - minimum_coverage 95 - minimum_coverage_by_file 95 + # minimum_coverage 95 + # minimum_coverage_by_file 95 end RSpec.configure do |config|