diff --git a/build-logic/src/main/java/dev/caskeleton/buildlogic/publishing/LibraryPublishingPlugin.java b/build-logic/src/main/java/dev/caskeleton/buildlogic/publishing/LibraryPublishingPlugin.java index 5789685..9b32f94 100644 --- a/build-logic/src/main/java/dev/caskeleton/buildlogic/publishing/LibraryPublishingPlugin.java +++ b/build-logic/src/main/java/dev/caskeleton/buildlogic/publishing/LibraryPublishingPlugin.java @@ -1,9 +1,11 @@ package dev.caskeleton.buildlogic.publishing; import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension; +import java.util.List; import org.gradle.api.GradleException; import org.gradle.api.Plugin; import org.gradle.api.Project; +import org.gradle.api.component.AdhocComponentWithVariants; import org.gradle.api.credentials.HttpHeaderCredentials; import org.gradle.api.plugins.JavaPluginExtension; import org.gradle.api.provider.Provider; @@ -58,6 +60,22 @@ public final class LibraryPublishingPlugin implements Plugin { .getByType(DependencyManagementExtension.class) .generatedPomCustomization(customization -> customization.setEnabled(false)); + // Test fixtures are this repository's own test support (grpc-core-api's, shared by the other + // modules' tests); the published testkit is grpc-testkit. They stay out of the publication, which + // also keeps a capability Maven cannot express out of the POM. + project + .getPlugins() + .withId( + "java-test-fixtures", + ignored -> { + AdhocComponentWithVariants component = + (AdhocComponentWithVariants) project.getComponents().getByName("java"); + for (String variant : List.of("testFixturesApiElements", "testFixturesRuntimeElements")) { + component.withVariantsFromConfiguration( + project.getConfigurations().getByName(variant), details -> details.skip()); + } + }); + Provider packagesUrl = project.getProviders().gradleProperty("packagesUrl"); Provider repositoryUrl = project.getProviders().gradleProperty("repositoryUrl"); Provider token = project.getProviders().environmentVariable("PACKAGES_TOKEN"); diff --git a/build.gradle b/build.gradle index ffcc373..c4951d1 100644 --- a/build.gradle +++ b/build.gradle @@ -20,6 +20,8 @@ group = providers.gradleProperty('libraryGroup').get() def revision = JavaConventionsPlugin.sourceRevision(providers) version = JavaConventionsPlugin.releaseVersion(providers) + (revision == JavaConventionsPlugin.UNKNOWN_REVISION ? '-SNAPSHOT' : '') +// Captured here: inside a task's configuration `group` and `version` are the task's own properties. +def libraryCoordinates = [project.group.toString(), project.version.toString()] tasks.register('resolveAndLockAll') { group = 'build setup' @@ -111,7 +113,7 @@ def sbomFile = layout.buildDirectory.file("release/grpc-library-${version}-cyclo tasks.register('verifyReleaseVersion') { group = 'verification' description = 'Fails unless this build names a release version and the commit it was built from.' - def releaseVersion = version.toString() + def releaseVersion = libraryCoordinates[1] doLast { if (releaseVersion.endsWith('-SNAPSHOT')) { throw new GradleException("No commit id (-PgitRevision, GIT_SHA or GITHUB_SHA): ${releaseVersion} is not a release.") @@ -218,10 +220,11 @@ tasks.register('releaseRehearsal') { group = 'release' description = 'releaseCheck, then publishes every module and the SBOM to build/staging-repository and checks the files.' dependsOn tasks.named('releaseCheck') - dependsOn(([path] + leafPaths).collect { "${it == ':' ? '' : it}:publishAllPublicationsToStagingRepository" }) + dependsOn tasks.named('publishAllPublicationsToStagingRepository') + dependsOn leafPaths.collect { "${it}:publishAllPublicationsToStagingRepository" } def staging = layout.buildDirectory.dir('staging-repository') def artifacts = leaves.collect { it.name } - def coordinates = [group.toString(), version.toString()] + def coordinates = libraryCoordinates def signed = !signingKey.isBlank() def checker = file('scripts/release/check-staging.py') doLast { @@ -241,10 +244,11 @@ tasks.register('release') { group = 'release' description = 'releaseCheck, publish to Gitea Packages, then verify the version is readable anonymously.' dependsOn tasks.named('releaseCheck') - dependsOn(([path] + leafPaths).collect { "${it == ':' ? '' : it}:publishAllPublicationsToGiteaRepository" }) + dependsOn tasks.named('publishAllPublicationsToGiteaRepository') + dependsOn leafPaths.collect { "${it}:publishAllPublicationsToGiteaRepository" } def url = providers.gradleProperty('packagesUrl') def artifacts = leaves.collect { it.name } + ['grpc-library'] - def coordinates = [group.toString(), version.toString()] + def coordinates = libraryCoordinates def verifier = file('scripts/release/verify-published.sh') doLast { def command = ['bash', verifier.path, url.get(), coordinates[0], coordinates[1]] + artifacts diff --git a/scripts/release/sbom.sh b/scripts/release/sbom.sh index 3f88171..9dccac0 100755 --- a/scripts/release/sbom.sh +++ b/scripts/release/sbom.sh @@ -11,5 +11,5 @@ output=${1:?usage: sbom.sh } mkdir -p "$(dirname "$output")" trivy=$("$root/scripts/tool.sh" trivy) cd "$root" -"$trivy" fs --format cyclonedx --skip-dirs build-logic --output "$output" . +"$trivy" fs --skip-version-check --format cyclonedx --skip-dirs build-logic --output "$output" . python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); assert d.get("bomFormat")=="CycloneDX" and d.get("components"), "empty SBOM"; print("sbom:", len(d["components"]), "components")' "$output" diff --git a/scripts/release/vulnerability-scan.sh b/scripts/release/vulnerability-scan.sh index 31c2f47..f8d73ae 100755 --- a/scripts/release/vulnerability-scan.sh +++ b/scripts/release/vulnerability-scan.sh @@ -16,9 +16,9 @@ mkdir -p "$out" trivy=$("$root/scripts/tool.sh" trivy) cd "$root" -"$trivy" fs --scanners vuln --severity CRITICAL,HIGH --exit-code 1 --ignorefile .trivyignore.yaml . -"$trivy" fs --scanners vuln --severity MEDIUM,LOW --exit-code 0 --ignorefile .trivyignore.yaml . -"$trivy" fs --scanners vuln --severity CRITICAL,HIGH,MEDIUM,LOW,UNKNOWN --exit-code 0 \ +"$trivy" fs --skip-version-check --scanners vuln --severity CRITICAL,HIGH --exit-code 1 --ignorefile .trivyignore.yaml . +"$trivy" fs --skip-version-check --scanners vuln --severity MEDIUM,LOW --exit-code 0 --ignorefile .trivyignore.yaml . +"$trivy" fs --skip-version-check --scanners vuln --severity CRITICAL,HIGH,MEDIUM,LOW,UNKNOWN --exit-code 0 \ --ignorefile .trivyignore.yaml --format json --output "$out/trivy-all.json" . kev_url=${KEV_FEED_URL:-https://www.cisa.gov/sites/default/files/feeds/known_exploited_vulnerabilities.json}