Skip to content

Commit

Permalink
Test merge verify
Browse files Browse the repository at this point in the history
  • Loading branch information
turchenkoalex committed Jul 10, 2024
1 parent f5ed4e6 commit a31c7ee
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/verify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,20 @@ jobs:
min-coverage-overall: 50
min-coverage-changed-files: 60
- name: Coverage verify
id: koververify
run: ./gradlew koverVerify
- name: Read merge.err
if: failure()
id: readmergeerr
run: |
cat build/reports/kover/merge.err
- name: Fail PR if coverage verify fails
if: failure()
uses: actions/github-script@v7
with:
script: |
core.setFailed('Rule violated: lines covered')
// read stdout from readmerge
const readmergeerr = steps.readmergeerr.outputs.stdout
core.setOutput('summary', 'Rule violated: lines covered ' + readmergeerr)
detekt:
name: Detekt
runs-on: ubuntu-latest
Expand Down
49 changes: 48 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.report.ReportMergeTask
import kotlinx.kover.gradle.plugin.dsl.tasks.KoverVerifyReport

group = "com.ecwid"
version = "1.0-SNAPSHOT"
Expand Down Expand Up @@ -53,6 +54,41 @@ subprojects {
}

// Kover
@CacheableTask
abstract class KoverVerifyMergeTask : DefaultTask() {

@get:InputFiles
@get:PathSensitive(PathSensitivity.RELATIVE)
abstract val input: ConfigurableFileCollection

@get:OutputFile
abstract val output: RegularFileProperty

@TaskAction
fun merge() {
logger.info("Input")
logger.info(input.files.joinToString(separator = "\n") { it.absolutePath })
logger.info("Output = ${output.get().asFile.absolutePath}")

val existingFiles = input.files.filter { it.exists() }
val text = existingFiles.map { it.readText().trim() }
.filterNot { it.isEmpty() }
.joinToString(separator = "\n", prefix = "\t")

if (text.isNotEmpty()) {
output.get().asFile.writeText("Verify errors:\n$text")
logger.lifecycle("Merged output to ${output.get().asFile.absolutePath}")
} else {
if (output.get().asFile.exists()) {
output.get().asFile.delete()
}
}
}
}

val koverVerifyMergeTask by tasks.registering(KoverVerifyMergeTask::class) {
output = rootProject.layout.buildDirectory.file("reports/kover/merge.err")
}

val coverageExclusions = setOf(
"benchmarks",
Expand All @@ -69,10 +105,21 @@ subprojects {
kover(project)
}

tasks["koverVerify"].finalizedBy(koverVerifyMergeTask)

koverVerifyMergeTask {
tasks.withType(KoverVerifyReport::class).forEach { task ->
input.from(
"${task.project.projectDir}/build/reports/kover/verify.err",
)
}

}

kover {
reports {
verify {
rule {
rule("Minimal line coverage rate in percents") {
minBound(50)
}
}
Expand Down

0 comments on commit a31c7ee

Please sign in to comment.