Use Coveralls with GitHub Actions in a Ruby repository

Introduction

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.

Installation of SimpleCov and simplecov-lcov

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. coveralls_github_actions-fs8.png

Copy the two modal lines that appear when you press the Use latent version button and add them to the Workflow yml.

coveralls_github_actions_code-fs8.png

Workflow example

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.

in conclusion

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

Use Coveralls with GitHub Actions in a Ruby repository
Run Ruby on Rails RSpec tests with GitHub Actions
Use ruby variables in javascript.
Multiplication in a Ruby array
Use Ruby with Google Colab
In Ruby you can define a method with any name
I searched for a web framework with Gem in Ruby
Sorting hashes in a Ruby array
Use constructor with arguments in cucumber-picocontainer
Let's use Amazon Textract with Ruby
Implement a gRPC client in Ruby
Make a typing game with ruby
Creating a project (and GitHub repository) using Java and Gradle in IntelliJ IDEA
[Ruby / Rails] Use alias. In a way that rubocop won't get angry!
Let's make a smart home with Ruby!
I made a risky die with Ruby
Use selenium (Firefox) in Ruby in WSL environment
Extract a part of a string with Ruby
Use FacesContext as a Mock with PowerMockito
Split a string with ". (Dot)" in Java
Use selenium (Chrome) in Ruby in WSL environment
Configure a multi-project with subdirectories in Gradle
Use a named format with Ruby's format method
That? Why is this repository bad for Github Actions CI running on Ruby 3.0?
Escape processing when creating a URL in Ruby
Read a string in a PDF file with Java
AtCoder Beginner Contest 169 A, B, C with ruby
Create a CSR with extended information in Java
Creating a browser automation tool with Ruby + Selenium
I want to use arrow notation in Ruby
With Tomcat you can use placeholders ($ {...}) in web.xml
I made a Ruby extension library in C
Add a project in any folder with Gradle
(Ruby on Rails6) Creating data in a table
[JAVA] [Spring] [MyBatis] Use IN () with SQL Builder
Creating a common repository with Spring Data JPA
Create a native extension of Ruby in Rust
I made a portfolio with Ruby On Rails
Write a test by implementing the story of Mr. Nabeats in the world with ruby
Docker command to create Rails project with a single blow in environment without Ruby
How to use a structure with variable length array or bit field in Ruby-FFI