Skip to content

build: move coverage reports to jacoco-report-aggregation #5264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions buildSrc/src/main/kotlin/toolkit-jacoco-report.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.gradle.api.plugins.jvm.internal.JvmPluginServices
import org.gradle.kotlin.dsl.support.serviceOf

// Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

Expand All @@ -21,26 +24,27 @@ val aggregateCoverage by configurations.creating {
isCanBeConsumed = false
}

// Resolvable configuration to resolve the classes of all dependencies
val classPath by configurations.creating {
val aggregateCoverageReportResults by configurations.creating {
isVisible = false
isCanBeResolved = true
isCanBeConsumed = false
extendsFrom(aggregateCoverage)
}
// magic to resolve all project dependencies transitively
serviceOf<JvmPluginServices>().configureAsRuntimeClasspath(aggregateCoverageReportResults)


// view to resolve the classes of all dependencies
val classPath = aggregateCoverageReportResults.incoming.artifactView {
componentFilter { it is ProjectComponentIdentifier }
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.LIBRARY))
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements.CLASSES))
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
}
}

// A resolvable configuration to collect source code
val sourcesPath by configurations.creating {
isVisible = false
isCanBeResolved = true
isCanBeConsumed = false
extendsFrom(aggregateCoverage)

// view to collect source code
val sourcesPath = aggregateCoverageReportResults.incoming.artifactView {
withVariantReselection()
componentFilter { it is ProjectComponentIdentifier }
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.VERIFICATION))
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
Expand All @@ -49,29 +53,27 @@ val sourcesPath by configurations.creating {
}

// A resolvable configuration to collect JaCoCo coverage data
val coverageDataPath by configurations.creating {
isVisible = false
isCanBeResolved = true
isCanBeConsumed = false
extendsFrom(aggregateCoverage)
val coverageDataPath = aggregateCoverageReportResults.incoming.artifactView {
withVariantReselection()
componentFilter { it is ProjectComponentIdentifier }
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION))
attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("jacoco-coverage-data"))
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.VERIFICATION))
attribute(VerificationType.VERIFICATION_TYPE_ATTRIBUTE, objects.named(VerificationType.JACOCO_RESULTS))
attribute(ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE, ArtifactTypeDefinition.BINARY_DATA_TYPE)
}
}

// Register a code coverage report task to generate the aggregated report
tasks.register<JacocoReport>("coverageReport") {
additionalClassDirs(
classPath.filter { it.isDirectory }.asFileTree.matching {
classPath.files.filter { it.isDirectory }.asFileTree.matching {
include("**/software/aws/toolkits/**")
exclude("**/software/aws/toolkits/telemetry/**")
}
)

additionalSourceDirs(sourcesPath.incoming.artifactView { lenient(true) }.files)
executionData(coverageDataPath.incoming.artifactView { lenient(true) }.files.filter { it.exists() && it.extension == "exec" })
additionalSourceDirs(sourcesPath.files)
executionData(coverageDataPath.files)

reports {
html.required.set(true)
Expand Down
32 changes: 16 additions & 16 deletions buildSrc/src/main/kotlin/toolkit-testing.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,19 @@ tasks.jacocoTestReport.configure {
enabled = false
}

// Share the coverage data to be aggregated for the whole product
// this can be removed once we're using jvm-test-suites properly
configurations.register("coverageDataElements") {
isVisible = false
isCanBeResolved = false
isCanBeConsumed = true
extendsFrom(configurations.implementation.get())
attributes {
attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION))
attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("jacoco-coverage-data"))
}
tasks.withType<Test>().configureEach {
outgoing.artifact(extensions.getByType<JacocoTaskExtension>().destinationFile!!)
}
}
//// Share the coverage data to be aggregated for the whole product
//// this can be removed once we're using jvm-test-suites properly
//configurations.register("coverageDataElements") {
// isVisible = false
// isCanBeResolved = false
// isCanBeConsumed = true
// extendsFrom(configurations.implementation.get())
// attributes {
// attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
// attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION))
// attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("jacoco-coverage-data"))
// }
// tasks.withType<Test>().configureEach {
// outgoing.artifact(extensions.getByType<JacocoTaskExtension>().destinationFile!!)
// }
//}
3 changes: 2 additions & 1 deletion buildspec/linuxTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ phases:
- CI_BUILD_ID="${CODEBUILD_BUILD_ID}"
- test -n "$CODE_COV_TOKEN" && curl -Os https://uploader.codecov.io/latest/linux/codecov && chmod +x codecov || true # this sometimes times out but we don't want to fail the build
- test -n "$CODE_COV_TOKEN" && test -n "$CODEBUILD_BUILD_SUCCEEDING" && ./codecov -t $CODE_COV_TOKEN -F unittest || true
- test -n "$CODE_COV_TOKEN" && test -n "$CODEBUILD_BUILD_SUCCEEDING" && ./codecov -t $CODE_COV_TOKEN -F codewhisperer || true
# - test -n "$CODE_COV_TOKEN" && test -n "$CODEBUILD_BUILD_SUCCEEDING" && ./codecov -t $CODE_COV_TOKEN -F codewhisperer || true

post_build:
commands:
Expand All @@ -52,6 +52,7 @@ phases:
- mkdir -p $BUILD_ARTIFACTS
- rsync -rmq --include='*/' --include '**/build/idea-sandbox/**/log*/**' --exclude='*' . $TEST_ARTIFACTS/ || true
- rsync -rmq --include='*/' --include '**/build/reports/**' --exclude='*' . $TEST_ARTIFACTS/ || true
- rsync -rmq --include='*/' --include '**/build/**/*.exec' --exclude='*' . $TEST_ARTIFACTS/ || true
- rsync -rmq --include='*/' --include '**/test-results/**/*.xml' --exclude='*' . $TEST_ARTIFACTS/test-reports || true
- find plugins -path '*/build/distributions/*.zip' -exec cp {} $BUILD_ARTIFACTS/ \; || touch $BUILD_ARTIFACTS/build_failed

Expand Down
38 changes: 38 additions & 0 deletions coverage-report/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import kotlin.io.extension

// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

plugins {
base
id("jacoco-report-aggregation")
}

dependencies {
jacocoAggregation(project(":plugin-toolkit:intellij-standalone"))
jacocoAggregation(project(":plugin-core"))
jacocoAggregation(project(":plugin-amazonq"))

project.findProject(":plugin-toolkit:jetbrains-gateway")?.let {
jacocoAggregation(it)
}

jacocoAggregation(project(":ui-tests"))
}

reporting {
reports {
val testCodeCoverageReport by creating(JacocoCoverageReport::class) {
testType = TestSuiteType.UNIT_TEST
// https://github.com/gradle/gradle/issues/20026
reportTask.configure {
classDirectories.setFrom(classDirectories.map {
fileTree(it).matching {
include("**/software/aws/toolkits/**")
exclude("**/software/aws/toolkits/telemetry/**")
}
})
}
}
}
}
Loading