How can I connect Coveralls and Travis in GitHub?
Asked Answered
R

2

13

I currently have TravisCI building on PRs in a public GitHub repo. The instructions for Coveralls say to put this in a .coveralls.yml file:

service_name: travis-pro
repo_token: <my_token>

That doesn't work for me because the .coveralls.yml file would be public--checked into GitHub. My TravisCI is integrated into my GitHub repo wired to a branch and fires on PR.

So I tried this:

In TravisCI's site I set an environment var:

COVERALLS_REPO_TOKEN to my token's value.

Then modded my .travis.yml to look like this:

language: scala
scala:
   - 2.11.7
notifications:
  email:
    recipients:
      - me@my_email.com
jdk:
  - oraclejdk8
script: "sbt clean coverage test"
after_success: "sbt coverageReport coveralls"
script:
  - sbt clean coverage test coverageReport &&
    sbt coverageAggregate
after_success:
  - sbt coveralls

Now when I create a PR on the branch this runs ok--no errors and I see output in Travis' console that the coverage test ran and generated files. But when I go to Coveralls I see nothing--"There have been no builds for this repo."

How can I set this up?

EDIT: I also tried creating a .coveralls.yml with just service_name: travis-ci No dice, sadly.

Reformation answered 15/9, 2016 at 0:11 Comment(0)
S
22

How can I set this up?

Step 1 - Enable Coveralls

The first thing to do is to enable Coveralls for your repository.

You can do that on their website http://coveralls.io:

  • go to http://coveralls.io
  • sign in with your GitHub credentials
  • click on "Repositories", then "Add Repo"
    • if the repo isn't listed, yet, then "Sync GitHub Repos"
  • finally, flip the "enable coveralls" switch to "On"

enter image description here

Step 2 - Setup Travis-CI to push the coverage infos to Coveralls

You .travis.yml file contains multiple entries of the script and after_success sections. So, let's clean that up a bit:

language: scala
scala:    2.11.7
jdk:      oraclejdk8

script: "sbt clean coverage test"

after_success: "sbt coveralls"

notifications:
  email:
    recipients:
      - me@my_email.com

Now, when you push, the commands in the script sections are executed. This is were your coverage data is generated.

When the commands finish successfully the after_success section is executed. This is were the coverage data is pushed to coveralls.

The .coveralls config file

The .coveralls file is only needed to:

  • public Travis-CI repos do not need this config file since Coveralls can get the information via their API (via access token exchange)
  • the repo_token (found on the repo page on Coveralls) is only needed for private repos and should be kept secret. If you publish it, then anyone could submit some coverage data for your repo.

Boils down to: you need the file only in two cases:

  • to specify a custom location to the files containing the coverage data
  • or when you are using Travis-Pro and private repositories. Then you have to configure "travis-pro" and add the token:

    service_name: travis-pro
    repo_token: ...
    
Sangria answered 15/10, 2016 at 13:21 Comment(0)
C
0

I thought it might be helpful to explain how to set this up for PHP, given that the question applies essentially to any language that Coveralls supports (and not just Lua).

The process is particularly elusive for PHP because the PHP link on Travis-CI's website points to a password-protected page on Coveralls' site that provides no means by which to login using GitHub, unlike the main Coveralls site.

Equally confusing is that the primary PHP page on Coveralls' site seems to contain overly-complicated instructions that require yet another library called atoum/atoum (which looks to be defunct) and are anything but complete.

What ended-up working perfectly for me is https://github.com/php-coveralls/php-coveralls/ . The documentation is very thorough, but it boils-down to this:

  1. Enable Coveralls for your repository (see Step 1 in the Accepted Answer).

  2. Ensure that xdebug is installed and enabled in PHP within your Travis-CI build environment (it should be by default), which is required for code-coverage support in PHPUnit.

  3. Add phpunit and the php-coveralls libraries to the project with Composer:

composer require phpunit/phpunit php-coveralls/php-coveralls
  1. Update travis.yml at the root of the project to include the following directives:
script:
  - mkdir -p build/logs
  - vendor/bin/phpunit tests --coverage-clover build/logs/clover.xml

after_success:
  - travis_retry php vendor/bin/php-coveralls
  1. Create .coveralls.yml at the root of the project and populate it with:
service_name: travis-ci

I'm not positive that this step is necessary for public repositories (the Accepted Answer implies that it's not), but the php-coveralls documentation says of this directive (emphasis mine):

service_name: Allows you to specify where Coveralls should look to find additional information about your builds. This can be any string, but using travis-ci or travis-pro will allow Coveralls to fetch branch data, comment on pull requests, and more.

  1. Push the above changes to the remote repository on GitHub and trigger a Travis-CI build (if you don't already have hooks to make it happen automatically).

  2. Slap a Coveralls code-coverage badge in your README (or wherever else you'd like). The required markup may be found on the Coveralls page for the repository in question, in the Badge column.

Cuspidation answered 8/2, 2019 at 21:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.