/sbt-coveralls

Sbt plugin for uploading Scala code coverage to coveralls

Primary LanguageScalaOtherNOASSERTION

sbt-coveralls

SBT plugin that uploads scala code coverage to https://coveralls.io and integrates with Travis CI. This plugin uses either scoverage or SCCT to generate the code coverage metrics. This repo is a fork of the original xsbt-coverall-plugin to add support for scoverage. Use this project if you need scoverage support and until/if scoverage is supported upstream in xsbt-coveralls-plugin.

For an example project that uses this plugin click here. For example output click here

Installation

  1. Add the following to your project/build.sbt file
resolvers += Classpaths.sbtPluginReleases

addSbtPlugin("com.sksamuel.scoverage" % "sbt-scoverage" % "0.95.1")

addSbtPlugin("com.sksamuel.scoverage" %% "sbt-coveralls" % "0.0.5")
  1. Import the settings in your build file
for build.sbt:

Add the following to the top of your build.sbt:

ScoverageSbtPlugin.instrumentSettings

CoverallsPlugin.coverallsSettings
for build.scala projects:

Import the plugin settings, and add them to your project settings (example):

import scoverage.ScoverageSbtPlugin.instrumentSettings
import com.github.theon.coveralls.CoverallsPlugin.coverallsSettings

...

lazy val project = Project(
  ...
  settings = defaultSettings ++ intsrumentSettings ++ coverallsSettings
)

Coveralls configuration options (such as Specifying Your Repo Token) must come after this line.

  1. Register on https://coveralls.io/

  2. Follow the instructions for either Travis CI or Manual Usage

Travis CI Integration

sbt-coveralls can be run by Travis CI by following these instructions:

  1. Add the following to you travis.yml

    script: "sbt coveralls"

  2. Job done! Commit these changes to travis.yml to kick off your Travis build and you should see coverage reports appear on http://coveralls.io

Manual Usage

  1. Get the repo token for your repo from http://coveralls.io

  2. Let sbt-coveralls know what your coveralls repo token is. See Specifying Your Repo Token

  3. In the SBT console run the command coveralls. This should run your test suite, generate code coverage reports and upload the reports to coveralls.io. After running the command, you should see output similar to the following:

    Uploading to coveralls.io succeeded: Job #17.1 https://coveralls.io/jobs/12207

For example output click here

Specifying Your Repo Token

There are several ways to tell sbt-coveralls your repo token to support different use cases:

Write your repo token into a file

Add the following to your build.sbt. The path can be absolute and point to somewhere outside the project or relative and point somewhere inside the project (such as src/main/resources/token.txt).

Just remember: Do not store repo tokens inside your project if it is in a public git repository!

import CoverallsPlugin.CoverallsKeys._

coverallsTokenFile := "/path/to/my/repo/token.txt"

Put your repo token directly in your build.sbt

Do not store repo tokens inside your project if it is in a public git repository!

import CoverallsPlugin.CoverallsKeys._

coverallsToken := "my-token"

Add an environment variable

Add an environment variable COVERALLS_REPO_TOKEN, for example:

export COVERALLS_REPO_TOKEN=my-token

Custom Source File Encoding

By default sbt-coveralls assumes your source files are UTF-8 encoded. To use a different encoding, add the following to your build.sbt

import CoverallsPlugin.CoverallsKeys._

encoding := "ISO-8859-1"

Once the plugin has slurped your source code into memory using the specified encoding, it will be converted into UTF-8 to be sent to the coveralls API. This is because the coveralls API uses a JSON request body and RFC 4627 mandates that JSON must be UTF encoded.

License

sbt-coveralls is open source software released under the Apache 2 License.