Skip to content

Commit

Permalink
Add codecov
Browse files Browse the repository at this point in the history
  • Loading branch information
mhamilton723 committed Jul 10, 2019
1 parent 7e8225f commit 7940967
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 4 deletions.
44 changes: 43 additions & 1 deletion build.sbt
@@ -1,5 +1,6 @@
import java.io.{File, PrintWriter}
import java.net.URL
import java.util.{Random, UUID}

import org.apache.commons.io.FileUtils
import sbt.internal.util.ManagedLogger
Expand Down Expand Up @@ -107,6 +108,18 @@ def uploadToBlob(source: String, dest: String,
Process(osPrefix ++ command) ! log
}

def downloadFromBlob(source: String, dest: String,
container: String, log: ManagedLogger,
accountName: String="mmlspark"): Int = {
val command = Seq("az", "storage", "blob", "download-batch",
"--destination", dest,
"--pattern", source,
"--source", container,
"--account-name", accountName,
"--account-key", Secrets.storageKey)
Process(osPrefix ++ command) ! log
}

val publishDocs = TaskKey[Unit]("publishDocs", "publish docs for scala and python")
publishDocs := {
val s = streams.value
Expand All @@ -126,6 +139,34 @@ publishDocs := {
uploadToBlob(unifiedDocDir.toString, version.value, "docs", s.log)
}

val uploadRawCodeCov = TaskKey[Unit]("uploadRawCodeCov",
"upload raw code coverage to blob for aggregation later")
uploadRawCodeCov := {
val s = streams.value
val scoverageDir = join("target", "scala-2.11", "scoverage-data")
uploadToBlob(scoverageDir.toString, version.value + "/" + UUID.randomUUID().toString, "coverage", s.log)
}

val downloadCloudCodeCov = TaskKey[Unit]("downloadCloudCodeCov",
"download code coverage files from blob")
downloadCloudCodeCov := {
val s = streams.value
val scoverageDir = join("target", "scala-2.11", "scoverage-data")
val v = version.value
downloadFromBlob(v + "/**/scoverage.measurements.*", scoverageDir.toString, "coverage", s.log)
join(scoverageDir.toString, v).listFiles().foreach { d =>
d.listFiles().foreach { f =>
val fileParts = f.getName.split(".".head)
println(fileParts.toList, s.log)
val newInt = fileParts.last.toInt + Math.abs(d.toString.hashCode)
val newName = (fileParts.dropRight(1) ++ Seq(newInt.toString)).mkString(".")
FileUtils.moveFile(f, join(scoverageDir.toString, newName))
}
FileUtils.forceDelete(d)
}
FileUtils.forceDelete(join(scoverageDir.toString, v))
}

def pythonizeVersion(v: String): String = {
if (v.contains("+")){
v.split("+".head).head + ".dev1"
Expand Down Expand Up @@ -265,6 +306,7 @@ developers := List(
"mmlspark-support@microsoft.com", url("https://github.com/drdarshan"))
)

/*
credentials += Credentials("Sonatype Nexus Repository Manager",
"oss.sonatype.org",
Secrets.nexusUsername,
Expand All @@ -284,7 +326,7 @@ pgpPublicRing := {
write(Secrets.pgpPublic); close()
}
temp
}
}*/

licenses += ("MIT", url("https://github.com/Azure/mmlspark/blob/master/LICENSE"))
publishMavenStyle := true
Expand Down
34 changes: 31 additions & 3 deletions pipeline.yaml
Expand Up @@ -35,6 +35,27 @@ jobs:
scriptLocation: inlineScript
inlineScript: 'sbt scalastyle test:scalastyle it:scalastyle'

- job: CodeCoverage
condition: eq(variables.runTests, 'True')
pool:
vmImage: ubuntu-16.04
dependsOn: UnitTests
steps:
- task: AzureCLI@1
displayName: 'Codecov Aggregate'
inputs:
azureSubscription: 'Findable Incubation(ca9d21ff-2a46-4e8b-bf06-8d65242342e5)'
scriptLocation: inlineScript
inlineScript: |
sbt coverage compile
sbt downloadCloudCodeCov
sbt coverageReport
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: 'cobertura'
summaryFileLocation: '**/coverage-report/*.xml'
failIfCoverageEmpty: true

- job: PublishAndE2E
pool:
vmImage: ubuntu-16.04
Expand Down Expand Up @@ -139,17 +160,24 @@ jobs:
inputs:
azureSubscription: 'Findable Incubation(ca9d21ff-2a46-4e8b-bf06-8d65242342e5)'
scriptLocation: inlineScript
inlineScript: 'sbt "testOnly com.microsoft.ml.spark.$(PACKAGE).**" '
inlineScript: 'sbt coverage "testOnly com.microsoft.ml.spark.$(PACKAGE).**"'
- task: AzureCLI@1
condition: and(failed(), eq(variables.flaky, 'True'))
displayName: 'Flaky Unit Test Retry'
inputs:
azureSubscription: 'Findable Incubation(ca9d21ff-2a46-4e8b-bf06-8d65242342e5)'
scriptLocation: inlineScript
inlineScript: 'sbt "testOnly com.microsoft.ml.spark.$(PACKAGE).**" '
inlineScript: 'sbt coverage "testOnly com.microsoft.ml.spark.$(PACKAGE).**"'
- task: AzureCLI@1
displayName: 'Generate Codecov report'
inputs:
azureSubscription: 'Findable Incubation(ca9d21ff-2a46-4e8b-bf06-8d65242342e5)'
scriptLocation: inlineScript
inlineScript: 'sbt uploadRawCodeCov'
condition: succeededOrFailed()
- task: PublishTestResults@2
displayName: 'Publish Test Results **/test-reports/*.xml'
inputs:
testResultsFiles: '**/test-reports/*.xml'
failTaskOnFailedTests: true
condition: succeededOrFailed()
condition: succeededOrFailed()
1 change: 1 addition & 0 deletions project/plugins.sbt
Expand Up @@ -4,3 +4,4 @@ addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.1")
addSbtPlugin("com.dwijnand" % "sbt-dynver" % "3.1.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.0")

0 comments on commit 7940967

Please sign in to comment.