Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Coveralls with Github Action?

I'm experiencing problems with my github repo configuration. Here it is - umbress. I have Github Actions CI enabled and configured and I want to have the coverage badge in my repo so everyone who wants to use my code in their projects knows that my code is well-tested. But it seems that I missing something because my coverage badge has an "unknown" status for a long time already.

CI steps are:

  1. Run build
  2. Run tests and generate coverage (jest --coverage --config config/jest.js). This will generate ./coverage/lcov.info in root directory
  3. Finally Coveralls GitHub Action should upload coverage to their website and display the results

There are a few issues:

  1. When I run builds on pull requests, it says "First build" (but it's not, I've ran a lot of builds on this branch already) github actions
  2. Coverage info is differs in what jest shows me after tests and what is displaying in Coveralls stats (i.e. in Coveralls it says FIRST BUILD ON DEVELOPER AT 90.072%, but there's no such percentage at all! Lines covered is 93.43% and everything in average is 89.4%)
  3. Coverage badge is "unknown" no matter I try to change

What am I doing wrong and what should I do to fix this?

like image 700
JamesJGoodwin Avatar asked Feb 23 '20 12:02

JamesJGoodwin


People also ask

What is coveralls GitHub?

Coveralls is a web service that tracks code coverage over time for GitHub projects. Coveralls requires Travis CI to be set up beforehand as Travis sends the coverage report from the latest build to Coveralls.

What is coveralls io?

Coveralls is a web service to help you track your code coverage over time, and ensure that all your new code is fully covered. The Coveralls service is language-agnostic and CI-agnostic, but we haven't yet built easy solutions for all the possibilities as far as repo hosting.


1 Answers

I've tried many things as well and in the end, the usage of the coverallsapp/[email protected] helped! Now I can successfully publish the coverage results to coveralls.io

Unfortunately, the straightforward approach was either leading to "Bad Response 422 - Couldn't find a repository matching this job" or "Error from lcovParse: 'Failed to parse string'".

Straightforward approach (not working):

- name: Publish to coveralls.io
  run: cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js

Using Actions app from GH marketplace (working):

- name: Publish to coveralls.io
  uses: coverallsapp/[email protected]
  with:
    github-token: ${{ github.token }}

This is the working .yml configuration, hope it will help someone else as well.

Keep in mind that the scenario that I needed to cover was a little bit tricky, we have multiple coverage results that needed to be combined and later on used as a single output result to coveralls.io.

If someone is curious, here are the things that I've tried, but failed:

  • Use of NODE_ENV for publishing -

    run: NODE_ENV=test cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js

  • Specifying exact node version 11.8.0 and above

  • Specifying a github.token, repo and env for the steps:

  • Creating a separate Github Actions Job.

    uses: actions/setup-node@v1
    with:
      repo-token: ${{ github.token }}
      repository: ${{ github.repository }}
      GITHUB_TOKEN: ${{ github.token }}
    
like image 153
Zdravko Kolev Avatar answered Oct 19 '22 10:10

Zdravko Kolev