Skip to content

Commit

Permalink
Add simplecov for code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
javierjulio committed Apr 16, 2024
1 parent 06b47d5 commit 7fa7450
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 17 deletions.
62 changes: 45 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,57 @@ name: Tests

on:
push:
branches: [ master ]
branches:
- master
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
ruby: [ '3.0', '3.1', '3.2' ]
ruby:
- '3.0'
- '3.1'
- '3.2'
- '3.3'
name: Ruby ${{ matrix.ruby }}
steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Run Tests
env:
RUBYOPT: "-W:deprecated"
EMAIL: email
PASSWORD: password
INSTANCE_ZUID: ${{ secrets.INSTANCE_ZUID }}
MODEL_ZUID: ${{ secrets.MODEL_ZUID }}
run: |
bundle exec rake
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Run Tests
env:
COVERAGE: true
RUBYOPT: "-W:deprecated"
EMAIL: email
PASSWORD: password
INSTANCE_ZUID: ${{ secrets.INSTANCE_ZUID }}
MODEL_ZUID: ${{ secrets.MODEL_ZUID }}
run: bundle exec rake
- name: Rename coverage file by matrix run
run: mv coverage/coverage.xml coverage/coverage-ruby-${{ matrix.ruby }}.xml
- uses: actions/upload-artifact@v4
with:
name: coverage-ruby-${{ matrix.ruby }}
path: coverage
if-no-files-found: error

upload_coverage:
name: Upload Coverage
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
path: coverage
pattern: coverage-ruby-*
merge-multiple: true
- uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: coverage
fail_ci_if_error: true
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ source "https://rubygems.org"

# Specify your gem's dependencies in zesty.gemspec
gemspec

group :test do
gem "simplecov", require: false
gem "simplecov-cobertura"
end
12 changes: 12 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ GEM
bigdecimal
rexml
diff-lcs (1.5.1)
docile (1.4.0)
domain_name (0.6.20240107)
dotenv (3.1.0)
ffi (1.16.3)
Expand Down Expand Up @@ -51,6 +52,15 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-cobertura (2.1.0)
rexml
simplecov (~> 0.19)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
vcr (6.2.0)
webmock (3.23.0)
addressable (>= 2.8.0)
Expand All @@ -66,6 +76,8 @@ DEPENDENCIES
rake (~> 13.0)
rspec (~> 3.0)
rspec-json_expectations
simplecov
simplecov-cobertura
vcr
webmock
zesty!
Expand Down
5 changes: 5 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
coverage:
status:
project:
default:
threshold: 0.05%
9 changes: 9 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
if ENV.fetch("COVERAGE", false)
require "simplecov"
require "simplecov-cobertura"
SimpleCov.start do
add_filter %r{^/spec/}
formatter SimpleCov::Formatter::CoberturaFormatter
end
end

require "bundler/setup"
require "dotenv/load"
require "zesty"
Expand Down

0 comments on commit 7fa7450

Please sign in to comment.