opendevstack / ods-pipeline-gradle

ODS Pipeline tasks for Gradle development
Apache License 2.0
0 stars 0 forks source link

Publish gradle (test)-reports as artifacts by default #1

Open oalyman opened 2 years ago

oalyman commented 2 years ago

Currently we publish the test results as xunit reports in xml format. This format is processable by different tools but not easily digestable by humans. Gradle creates test reports in html format at the same time that are easily browsable and interpretable by humans. Those html reports usually reside under the path $buildDir/reports/tests/test if you do not have crazy custumization of your gradle build. It would be a great benefit if those reports would be part of the published artifacts. With issue opendevstack/ods-pipeline#384 implemented they would be even browsable by a single click. One could think as well as publishing the whole reports directory as depending on used plugins additional reports will most likely end up there.

oalyman commented 2 years ago

As we meanwhile expose the ARTIFACTS_DIR environment variable to the gradle build the publishing of the gradle test reports can be achieved by creating a custom build task.

The following task definition in a gradle build would achieve that. Please note that this is kotlin syntax, so if you use groovy for your build definition it varies...

tasks.register<Zip>("ciCopyGradleTestReport") {
    val artifactsDir = System.getenv("ARTIFACTS_DIR")
    val reportsDir = "$artifactsDir/gradle-reports"
    doFirst {
        if (artifactsDir == null) {
            println("not copying gradle test reports as build runs locally")
            throw StopExecutionException()
        } else {
            println("copying gradle tests to $reportsDir")
        }
    }
    archiveFileName.set("gradle-reports.zip")
    from(layout.buildDirectory.dir("reports/tests/test"))
    destinationDirectory.set(layout.buildDirectory.dir(reportsDir))
}
tasks.test {
    finalizedBy("ciCopyGradleTestReport")
}
oalyman commented 2 years ago

I plan to make this part of opendevstack/ods-pipeline#417.

michaelsauter commented 10 months ago

Transferring as a consequence of https://github.com/opendevstack/ods-pipeline/pull/722.