-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #166 from kaleido-io/coverage
Add task type for checking coverage
- Loading branch information
Showing
3 changed files
with
51 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.GradleException | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.InputFile | ||
import org.gradle.api.tasks.TaskAction | ||
|
||
class GoCheckCoverage extends DefaultTask { | ||
|
||
@InputFile | ||
File coverageFile | ||
|
||
@Input | ||
BigDecimal target | ||
|
||
@Input | ||
BigDecimal maxGap | ||
|
||
void coverageFile(Object f) { | ||
coverageFile = project.file(f) | ||
} | ||
|
||
@TaskAction | ||
void exec() { | ||
String coverageOutput = ("go tool cover -func=${coverageFile}").execute().text | ||
String totalCoverage = coverageOutput.readLines().find { line -> | ||
line.contains('total:') | ||
}?.split()?.last()?.replace('%', '') | ||
println "Coverage is ${totalCoverage}%" | ||
if (totalCoverage && totalCoverage.toFloat() < target) { | ||
throw new GradleException( | ||
"ERROR: Coverage is below ${target}% (current coverage: ${totalCoverage}%)" | ||
) | ||
} else if (totalCoverage.toFloat() - target > maxGap) { | ||
throw new GradleException( | ||
"ERROR: The target coverage ${target}% is below the current coverage: ${totalCoverage}% by " + | ||
"more than ${maxGap}%, please update the target value in ./core/go/build.gradle file" | ||
) | ||
} else { | ||
println "Coverage is above ${target}%, current coverage: ${totalCoverage}%" | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters