Skip to content

Commit

Permalink
add support for parallel builds (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-dennehy-ovo authored Feb 4, 2023
1 parent d7a583e commit d334e1f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,25 @@ import org.scoverage.coveralls.TravisPro
coverallsService := Some(TravisPro)
```

## Uploading coverage from parallel CI builds

[Coveralls supports merging reports from multiple CI builds.](https://docs.coveralls.io/parallel-build-webhook)
Each report must be flagged as coming from a parallel job, then a webhook must be called after all jobs have completed to merge the reports together.

To mark uploaded reports as parallel, either:

### Put the flag directly in `build.sbt`
```scala
import org.scoverage.coveralls.Imports.CoverallsKeys._
coverallsParallel := true
```

### Set an environment variable
```shell
export COVERALLS_PARALLEL=true
```

# License

`sbt-coveralls` is open source software released under the [Apache 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class CoverallPayloadWriter(
coverallsFile: File,
repoToken: Option[String],
service: Option[CIService],
parallel: Boolean,
gitClient: GitClient
)(implicit log: Logger) {
import gitClient._
Expand All @@ -38,6 +39,10 @@ class CoverallPayloadWriter(
// to provide an unique additional label in jobs with multiple submissions
writeOpt("flag_name", sys.env.get("COVERALLS_FLAG_NAME"))

if (parallel) {
gen.writeBooleanField("parallel", true)
}

addGitInfo()

gen.writeFieldName("source_files")
Expand Down
5 changes: 4 additions & 1 deletion src/main/scala/org/scoverage/coveralls/CoverallsPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ object Imports {
val coverallsEndpoint = SettingKey[Option[String]]("coverallsEndpoint")
val coverallsGitRepoLocation =
SettingKey[Option[String]]("coveralls-git-repo")
val coverallsParallel = SettingKey[Boolean]("coverallsParallel")
}
}

Expand Down Expand Up @@ -56,7 +57,8 @@ object CoverallsPlugin extends AutoPlugin {
},
coverallsFile := crossTarget.value / "coveralls.json",
coberturaFile := crossTarget.value / "coverage-report" / "cobertura.xml",
coverallsGitRepoLocation := Some(".")
coverallsGitRepoLocation := Some("."),
coverallsParallel := sys.env.get("COVERALLS_PARALLEL").contains("true")
)

val aggregateFilter = ScopeFilter(
Expand Down Expand Up @@ -98,6 +100,7 @@ object CoverallsPlugin extends AutoPlugin {
coverallsFile.value,
repoToken,
coverallsService.value,
coverallsParallel.value,
new GitClient(repoRootDirectory)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ class CoverallPayloadWriterTest
def coverallsWriter(
writer: Writer,
tokenIn: Option[String],
service: Option[CIService]
service: Option[CIService],
parallel: Boolean,
): (CoverallPayloadWriter, Writer) = {
val payloadWriter = new CoverallPayloadWriter(
new File(".").getAbsoluteFile,
new File("."),
tokenIn,
service,
parallel,
testGitClient
) {
override def generator(file: File) = {
Expand Down Expand Up @@ -66,7 +68,8 @@ class CoverallPayloadWriterTest
val (payloadWriter, writer) = coverallsWriter(
new StringWriter(),
Some("testRepoToken"),
Some(testService)
Some(testService),
false
)

payloadWriter.start
Expand All @@ -81,7 +84,7 @@ class CoverallPayloadWriterTest

"generate a correct starting payload without a CI service" in {
val (payloadWriter, writer) =
coverallsWriter(new StringWriter(), Some("testRepoToken"), None)
coverallsWriter(new StringWriter(), Some("testRepoToken"), None, false)

payloadWriter.start
payloadWriter.flush()
Expand Down Expand Up @@ -109,7 +112,8 @@ class CoverallPayloadWriterTest
val (payloadWriter, writer) = coverallsWriter(
new StringWriter(),
Some("testRepoToken"),
Some(TravisCI)
Some(TravisCI),
false
)
payloadWriter.addSourceFile(
SourceFileReport(
Expand All @@ -128,14 +132,28 @@ class CoverallPayloadWriterTest
val (payloadWriter, writer) = coverallsWriter(
new StringWriter(),
Some("testRepoToken"),
Some(TravisCI)
Some(TravisCI),
false
)

payloadWriter.start
payloadWriter.end()

writer.toString should endWith("]}")
}

"include parallel correctly" in {
val (payloadWriter, writer) = coverallsWriter(new StringWriter(), Some("testRepoToken"), None, true)

payloadWriter.start
payloadWriter.flush()

writer.toString should equal(
"""{"repo_token":"testRepoToken","parallel":true,""" +
expectedGit +
""","source_files":["""
)
}
}
}
}

0 comments on commit d334e1f

Please sign in to comment.