Skip to content

Commit

Permalink
feat(tests): add code coverage reporting (#891)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
guidojw authored Nov 27, 2024
1 parent d546681 commit 0daa494
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/workflows/continuous-delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
21 changes: 20 additions & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -605,4 +607,4 @@ DEPENDENCIES
wkhtmltopdf-binary

BUNDLED WITH
2.2.15
2.4.14
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
13 changes: 4 additions & 9 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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|
Expand Down

0 comments on commit 0daa494

Please sign in to comment.