Skip to content

Commit 357edf6

Browse files
committed
build: add verifyProjectArtifacts to double check expected jars
1 parent 6ac2d45 commit 357edf6

File tree

6 files changed

+99
-26
lines changed

6 files changed

+99
-26
lines changed

.github/workflows/reusable-build-publish.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ jobs:
5757
run: |
5858
if [[ "${{ inputs.version }}" != "" ]]; then
5959
echo "Version specified, running clean build with no cache for ${{ inputs.version }}"
60-
gradle clean build --no-build-cache --rerun-tasks
60+
gradle clean check --no-build-cache --rerun-tasks
6161
else
6262
echo "No version specified, running normal build"
63-
gradle clean build
63+
gradle clean check
6464
fi
6565
env:
6666
RELEASE_VERSION: ${{ inputs.version }}
@@ -77,6 +77,9 @@ jobs:
7777
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.signing_key }}
7878
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.signing_pass }}
7979
run: gradle publishAllPublicationsToMavenCentralRepository --no-scan --no-configuration-cache
80+
- name: Look at files in verification
81+
- if: ${{ failure() || steps.build.outcome == 'failure' || steps.publish.outcome == 'failure' }}
82+
run: ls -lR verification
8083
- name: Upload hyper logs on failure
8184
if: ${{ failure() || steps.build.outcome == 'failure' || steps.publish.outcome == 'failure' }}
8285
uses: actions/upload-artifact@v4

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ pom.xml.bak
2828
.gradle
2929
.hyper
3030
.kotlin
31+
bin

buildSrc/src/main/kotlin/publishing-conventions.gradle.kts

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,13 @@
11
plugins {
22
id("base-conventions")
3+
id("version-conventions")
34
signing
45
`maven-publish`
56
id("dev.adamko.dev-publish")
67
}
78

8-
val revision: String by project
9-
109
val mavenCentralRepoName = "MavenCentral"
11-
12-
private val ci = object {
13-
private val snapshotVersion = when (System.getenv("GITHUB_RUN_NUMBER")) {
14-
null -> "$revision-LOCAL"
15-
else -> "$revision-SNAPSHOT"
16-
}
17-
18-
private val releaseVersion = System.getenv("RELEASE_VERSION")?.ifBlank {
19-
logger.lifecycle("env.RELEASE_VERSION not present, assuming snapshot")
20-
null
21-
}
22-
23-
val isRelease = releaseVersion != null
24-
25-
val resolvedVersion = releaseVersion ?: snapshotVersion
26-
}
27-
28-
group = "com.salesforce.datacloud"
29-
version = ci.resolvedVersion
10+
val isRelease = !System.getenv("RELEASE_VERSION").isNullOrBlank()
3011

3112
signing {
3213
val signingPassword: String? by project
@@ -37,15 +18,15 @@ signing {
3718
}
3819

3920
sign(publishing.publications)
40-
setRequired { ci.isRelease }
21+
setRequired { isRelease }
4122
}
4223

4324
gradle.taskGraph.whenReady {
4425
val isPublishingToMavenCentral = allTasks
4526
.filterIsInstance<PublishToMavenRepository>()
4627
.any { it.repository?.name == mavenCentralRepoName }
4728

48-
signing.setRequired({ isPublishingToMavenCentral || ci.isRelease })
29+
signing.setRequired({ isPublishingToMavenCentral || isRelease })
4930

5031
tasks.withType<Sign> {
5132
val isPublishingToMavenCentralCustom = isPublishingToMavenCentral
@@ -68,7 +49,7 @@ publishing {
6849
name = mavenCentralRepoName
6950
val releasesRepoUrl = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
7051
val snapshotsRepoUrl = uri("https://oss.sonatype.org/content/repositories/snapshots/")
71-
url = if (ci.isRelease) releasesRepoUrl else snapshotsRepoUrl
52+
url = if (isRelease) releasesRepoUrl else snapshotsRepoUrl
7253
credentials {
7354
username = System.getenv("OSSRH_USERNAME")
7455
password = System.getenv("OSSRH_PASSWORD")
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
val revision: String by project
3+
4+
private val ci = object {
5+
private val snapshotVersion = when (System.getenv("GITHUB_RUN_NUMBER")) {
6+
null -> "$revision-LOCAL"
7+
else -> "$revision-SNAPSHOT"
8+
}
9+
10+
private val releaseVersion = System.getenv("RELEASE_VERSION")?.ifBlank {
11+
logger.lifecycle("env.RELEASE_VERSION not present, assuming snapshot")
12+
null
13+
}
14+
15+
val resolvedVersion = releaseVersion ?: snapshotVersion
16+
}
17+
18+
group = "com.salesforce.datacloud"
19+
version = ci.resolvedVersion

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ rootProject.name = "jdbc-build"
33
include(":jdbc-grpc")
44
include(":jdbc-core")
55
include(":jdbc")
6+
include(":verification")

verification/build.gradle.kts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
plugins {
2+
id("base-conventions")
3+
id("version-conventions")
4+
id("dev.adamko.dev-publish")
5+
}
6+
7+
dependencies {
8+
devPublication(project(":jdbc"))
9+
devPublication(project(":jdbc-core"))
10+
devPublication(project(":jdbc-grpc"))
11+
}
12+
13+
tasks.named("check") {
14+
dependsOn("updateDevRepo")
15+
16+
group = "verification"
17+
description = "Verifies that all subprojects produce required JAR artifacts"
18+
19+
var expectedVersion = "$version"
20+
21+
val repo = devPublish.devMavenRepo.file("maven-dev/com/salesforce/datacloud/").get().asFile
22+
23+
doLast {
24+
val expectedPublications = setOf("jdbc", "jdbc-grpc", "jdbc-proto", "jdbc-core")
25+
val shaded = setOf("jdbc")
26+
27+
fun hasJar(artifactId: String, version: String, classifier: String? = null): Boolean {
28+
val path = "${artifactId}/${version}/${artifactId}-${version}${classifier?.let { "-$it" } ?: ""}.jar"
29+
return repo.resolve(path).exists()
30+
}
31+
32+
val failures = mutableListOf<String>()
33+
val verified = mutableListOf<String>()
34+
35+
expectedPublications.forEach { artifactId ->
36+
logger.lifecycle("Verifying artifacts for publication $artifactId:$expectedVersion...")
37+
38+
if (!hasJar(artifactId, expectedVersion)) {
39+
failures.add("Publication '$artifactId' is missing main JAR")
40+
}
41+
42+
if (!hasJar(artifactId, expectedVersion, "sources")) {
43+
failures.add("Publication '$artifactId' is missing sources JAR")
44+
}
45+
46+
if (!hasJar(artifactId, expectedVersion, "javadoc")) {
47+
failures.add("Publication '$artifactId' is missing javadoc JAR")
48+
}
49+
50+
if (shaded.contains(artifactId) && !hasJar(artifactId, expectedVersion, "shaded")) {
51+
failures.add("Publication '$artifactId' is missing shaded JAR")
52+
}
53+
54+
verified.add(artifactId)
55+
logger.lifecycle(" Checked publication: $artifactId version $expectedVersion")
56+
}
57+
58+
if (failures.isNotEmpty()) {
59+
failures.forEach { logger.error(it) }
60+
throw GradleException("Artifact verification failed. Some projects are missing required JAR files:\n" + failures.joinToString("\n"))
61+
} else if (!verified.containsAll(expectedPublications)) {
62+
val missing = expectedPublications - verified.toSet()
63+
throw GradleException("Missing expected publication(s): $missing")
64+
} else {
65+
logger.lifecycle("All subprojects successfully generated required JAR artifacts.")
66+
}
67+
}
68+
}

0 commit comments

Comments
 (0)