When migrating from Travis CI to GitHub Actions, we looked at how GitHub Actions could send Simple Cov results to Coveralls. It was like using simplecov-lcov to output code coverage in lcov format and send it to Coveralls.
I added the following two lines to my Gemfile and did a bundle install
.
gem 'simplecov', '~> 0.21'
gem 'simplecov-lcov', '~> 0.8'
Add the following to the beginning of spec/spec_helper.rb
. The important part when sending coverage to Coveralls is the part related to SimpleCov :: Formatter :: LcovFormatter
.
require 'simplecov'
require 'simplecov-lcov'
SimpleCov::Formatter::LcovFormatter.config do |config|
#Coveralls is coverage by default/lcov.Send info results
config.report_with_single_file = true
config.single_report_path = 'coverage/lcov.info'
end
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
SimpleCov::Formatter::HTMLFormatter,
#Simple Cov in formatter::Formatter::Add Lcov Formatter
SimpleCov::Formatter::LcovFormatter
])
SimpleCov.start
Coveralls GitHub Actions You can find Coveralls' GitHub Actions at https://github.com/marketplace/actions/coveralls-github-action.
Copy the two modal lines that appear when you press the Use latent version
button and add them to the Workflow yml.
I have prepared a workflow file called .github/workflows/coverage.yml
to send code coverage to Coveralls. The important part is from the last -name: Coveralls GitHub Action
that you copied in the previous section. github-token
is a required option, but you can set it as$ {{secrets.GITHUB_TOKEN}}
.
name: coverage
on: [push, pull_request]
jobs:
coverage:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Set up Ruby 2.7
uses: actions/setup-ruby@v1
with:
ruby-version: '2.7'
- name: Build and test with Rake
run: |
gem install bundler
bundle install
bundle exec rake
- name: Coveralls GitHub Action
uses: coverallsapp/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
It's a little mysterious whether it's necessary, but I've prepared just one line, .coveralls.yml
.
service_name: github-ci
After that, if you commit and push these, the workflow will start and the result will be sent to Coveralls. Please turn on repository linkage on the Coveralls side in advance.
Since the example of GitHub Action of Coveralls was that of Node.js, I was wondering if Ruby does not support it, but it was easy when I investigated it properly. When I was Travis CI, I used coveralls gem. In coveralls gem, there is a limit to the version of SimpleCov, so the method using simplecov-lcov like this one is more free and better.
Recommended Posts