From a31c7ee1900d9a8e03be2bb7171341f25843eeeb Mon Sep 17 00:00:00 2001 From: Aleksandr Turchenko Date: Wed, 10 Jul 2024 19:57:27 +0400 Subject: [PATCH] Test merge verify --- .github/workflows/verify.yaml | 10 +++++-- build.gradle.kts | 49 ++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/.github/workflows/verify.yaml b/.github/workflows/verify.yaml index 160a0d2..cd40a09 100644 --- a/.github/workflows/verify.yaml +++ b/.github/workflows/verify.yaml @@ -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 diff --git a/build.gradle.kts b/build.gradle.kts index d7b6553..d0adfbb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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" @@ -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", @@ -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) } }