coverallsapp / github-action

Coveralls Github Action
https://github.com/marketplace/actions/coveralls-github-action
MIT License
468 stars 75 forks source link

No clear examples for rails project #29

Open mcampo84 opened 4 years ago

mcampo84 commented 4 years ago

I'm new to Ruby on Rails, Github Actions and Coveralls, and I can't seem to get this github action working. It doesn't seem to be able to find the coverage report file after I run rspec tests.

My .coveralls.yml file looks like this:


on: [push, "pull_request"]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
    - name: Set up Ruby 2.6
      uses: actions/setup-ruby@v1
      with:
        ruby-version: 2.6.x

    - name: Run rspec
      run: |
        gem install bundler
        bundle install
        bundle exec rspec spec

    - name: Coveralls
      uses: coverallsapp/github-action@master
      with:
        github-token: ${{ secrets.GITHUB_TOKEN }}

What am I missing?

clh161 commented 4 years ago

same problem to yours I tried to add path-to-lcov but no luck

    - name: Coveralls
      uses: coverallsapp/github-action@master
      with:
        github-token: ${{ secrets.GITHUB_TOKEN }}
        path-to-lcov: coverage/.resultset.json

I wonder if Rails is not supported

stephaneliu commented 4 years ago

Overalls expects a consolidated lcov.info file.

# Gemfile
gem "simplecov-lcov"

# spec_helper.rb
if ENV["COVERAGE"]
  require "simplecov"
  require "simplecov-lcov"

  SimpleCov.start "rails" do
    if ENV["CI"]
      SimpleCov::Formatter::LcovFormatter.config do |config
        config.report_with_simgle_file = true
        config.lcov_file_name = "lcov.info"
    else
      SimpleCov::Formatter::HTMLFormatter
    end
end

# test.yml
...
- name: Run test
   ...
   run: |
     ...
     COVERAGE=true CI=true DISABLE_SPRING=true bundle exec rspec spec
- name: Coveralls 
  uses: coverallsapp/github-action@master
  with:
    github-tocken: ${{ secrets.GITHUB_TOKEN }}
    path-to-lcov: "./coverage/lcvo/lcov.info"
jfo84 commented 4 years ago

Here is some cleaned up code of @stephaneliu, etc.

spec_helper.rb

if ENV['COVERAGE'] == 'true'
  require 'coveralls'
  require 'simplecov'
  require 'simplecov-lcov'

  if ENV['CI'] == 'true'
    SimpleCov::Formatter::LcovFormatter.config do |config|
      config.report_with_single_file = true
      config.lcov_file_name = 'lcov.info'
    end

    SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
      SimpleCov::Formatter::LcovFormatter,
      Coveralls::SimpleCov::Formatter
    ])
  else
    SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
  end

  SimpleCov.start('rails')
end

ci.yml

- name: Coveralls 
  uses: coverallsapp/github-action@master
  with:
    github-tocken: ${{ secrets.GITHUB_TOKEN }}
    path-to-lcov: "./coverage/lcov/lcov.info"

Gemfile

  gem 'simplecov', require: false
  gem 'simplecov-lcov', require: false
  gem 'coveralls_reborn', '~> 0.18.0', require: false

You will need this library as well since the original is unmaintained.

Cheers

silva96 commented 4 years ago

You don't need a the coveralls nor coverals_reborn gem if using github actions, it picks up the lcov file written by the simplecov gem.

You need to add to your gemfile 2 gems, under the test group

  gem 'simplecov',      require: false
  gem 'simplecov-lcov', require: false

Also create a file called .simplecov in your root dir

and add this

require 'simplecov-lcov'

SimpleCov::Formatter::LcovFormatter.config do |c|
  c.report_with_single_file = true
  c.single_report_path = 'coverage/lcov.info'
end
SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new(
  [
    SimpleCov::Formatter::HTMLFormatter,
    SimpleCov::Formatter::LcovFormatter,
  ]
)
SimpleCov.start('rails')