Skip to content

Commit

Permalink
Fix old version uploading to Maven Central Stage (#5185)
Browse files Browse the repository at this point in the history
Fixes
https://youtrack.jetbrains.com/issue/CMP-1339/Change-description-of-androidx-artifacts-in-Maven-Central-stage
Fixes
https://youtrack.jetbrains.com/issue/CMP-7198/Maven-Central-publication-publishes-old-artifacts-for-Core-Bundle

Related change on CI:

https://jetbrains.team/p/ui/repositories/compose-teamcity-config/revision/94d34d0e

Now it matches by wildcards. It doesn't fix the core issue - associating
the exact library group with the exact artifacts, but fixing that
requires decoupling maven central upload per project instead of
comparing it by packages. It is not easy, as we not only have artifacts
in compose-multiplatform-core - we have Gradle plugin, components,
`compose-full`, Compose HTML.

## Testing
Run CI on igor.demin/upload-to-maven-central-fixes branch

Should be verified on the next 1.8.0-alpha02 release as well.
  • Loading branch information
igordmn committed Dec 12, 2024
1 parent 83b9768 commit 4ce6a59
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 28 deletions.
9 changes: 3 additions & 6 deletions ci/build-helpers/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ plugins {
}

val mavenCentral = MavenCentralProperties(project)
val mavenCentralGroup = project.providers.gradleProperty("maven.central.group")
val mavenCentralStage = project.providers.gradleProperty("maven.central.stage")
if (mavenCentral.signArtifacts) {
signing.useInMemoryPgpKeys(
mavenCentral.signArtifactsKey.get(),
Expand All @@ -20,8 +18,7 @@ val preparedArtifactsRoot = publishingDir.map { it.dir("prepared") }
val modulesFile = publishingDir.map { it.file("modules.txt") }

val findComposeModules by tasks.registering(FindModulesInSpaceTask::class) {
requestedGroupId.set(mavenCentralGroup)
requestedVersion.set(mavenCentral.version)
requestedCoordinates.set(mavenCentral.coordinates)
spaceInstanceUrl.set("https://public.jetbrains.space")
spaceClientId.set(System.getenv("COMPOSE_REPO_USERNAME") ?: "")
spaceClientSecret.set(System.getenv("COMPOSE_REPO_KEY") ?: "")
Expand Down Expand Up @@ -50,14 +47,14 @@ val fixModulesBeforePublishing by tasks.registering(FixModulesBeforePublishingTa
val reuploadArtifactsToMavenCentral by tasks.registering(UploadToSonatypeTask::class) {
dependsOn(fixModulesBeforePublishing)

version.set(mavenCentral.version)
modulesToUpload.set(project.provider { readComposeModules(modulesFile, preparedArtifactsRoot) })

sonatypeServer.set("https://oss.sonatype.org")
user.set(mavenCentral.user)
password.set(mavenCentral.password)
autoCommitOnSuccess.set(mavenCentral.autoCommitOnSuccess)
stagingProfileName.set(mavenCentralStage)
stagingProfileName.set(mavenCentral.stage)
stagingDescription.set(mavenCentral.description)
}

fun readComposeModules(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.OutputFile
import org.gradle.api.tasks.TaskAction
import org.jetbrains.compose.internal.publishing.utils.SpaceApiClient
import org.jetbrains.compose.internal.publishing.utils.SpaceApiClient.PackageInfo
import space.jetbrains.api.runtime.types.PackageRepositoryIdentifier
import space.jetbrains.api.runtime.types.ProjectIdentifier
import java.util.regex.Pattern

abstract class FindModulesInSpaceTask : DefaultTask() {
@get:Input
abstract val requestedGroupId: Property<String>

@get:Input
abstract val requestedVersion: Property<String>
abstract val requestedCoordinates: Property<String>

@get:Input
abstract val spaceInstanceUrl: Property<String>
Expand Down Expand Up @@ -52,11 +51,14 @@ abstract class FindModulesInSpaceTask : DefaultTask() {
val projectId = ProjectIdentifier.Id(spaceProjectId.get())
val repoId = PackageRepositoryIdentifier.Id(spaceRepoId.get())
val modules = ArrayList<String>()
val requestedGroupId = requestedGroupId.get()
val requestedVersion = requestedVersion.get()
space.forEachPackageWithVersion(projectId, repoId, requestedVersion) { pkg ->
if (pkg.groupId.startsWith(requestedGroupId)) {
modules.add("${pkg.groupId}:${pkg.artifactId}:${pkg.version}")
val requestedCoordinates = requestedCoordinates.get().split(",")
requestedCoordinates.forEach { req ->
val version = req.substringAfterLast(":") // suppose we don't support wildcards in version
space.forEachPackageWithVersion(projectId, repoId, version) { pkg ->
val pkgStr = pkg.toString()
if (pkgStr.matchesWildcard(req)) {
modules.add(pkgStr)
}
}
}

Expand All @@ -65,4 +67,9 @@ abstract class FindModulesInSpaceTask : DefaultTask() {
writeText(modules.joinToString("\n"))
}
}
}
}

private fun String.matchesWildcard(pattern: String): Boolean = "\\Q$pattern\\E"
.replace("*", "\\E.*\\Q")
.toRegex()
.matches(this)
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ import org.gradle.api.provider.Provider

@Suppress("unused") // public api
class MavenCentralProperties(private val myProject: Project) {
val version: Provider<String> =
propertyProvider("maven.central.version")
val coordinates: Provider<String> =
propertyProvider("maven.central.coordinates")

val stage: Provider<String> =
propertyProvider("maven.central.stage")

val description: Provider<String> =
propertyProvider("maven.central.description")

val user: Provider<String> =
propertyProvider("maven.central.user", envVar = "MAVEN_CENTRAL_USER")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ abstract class UploadToSonatypeTask : DefaultTask() {
abstract val stagingProfileName: Property<String>

@get:Internal
abstract val autoCommitOnSuccess: Property<Boolean>
abstract val stagingDescription: Property<String>

@get:Internal
abstract val version: Property<String>
abstract val autoCommitOnSuccess: Property<Boolean>

@get:Internal
abstract val modulesToUpload: ListProperty<ModuleToUpload>
Expand Down Expand Up @@ -59,7 +59,7 @@ abstract class UploadToSonatypeTask : DefaultTask() {
validate(stagingProfile, modules)

val stagingRepo = sonatype.createStagingRepo(
stagingProfile, "Staging repo for '${stagingProfile.name}' release '${version.get()}'"
stagingProfile, stagingDescription.get()
)
try {
for (module in modules) {
Expand All @@ -76,7 +76,7 @@ abstract class UploadToSonatypeTask : DefaultTask() {
private fun validate(stagingProfile: StagingProfile, modules: List<ModuleToUpload>) {
val validationIssues = arrayListOf<Pair<ModuleToUpload, ModuleValidator.Status.Error>>()
for (module in modules) {
val status = ModuleValidator(stagingProfile, module, version.get()).validate()
val status = ModuleValidator(stagingProfile, module).validate()
if (status is ModuleValidator.Status.Error) {
validationIssues.add(module to status)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import java.io.File
internal class ModuleValidator(
private val stagingProfile: StagingProfile,
private val module: ModuleToUpload,
private val version: String
) {
private val errors = arrayListOf<String>()
private var status: Status? = null
Expand All @@ -37,10 +36,6 @@ internal class ModuleValidator(
errors.add("Module's group id '${module.groupId}' does not match staging repo '${stagingProfile.name}'")
}

if (module.version != version) {
errors.add("Unexpected version '${module.version}' (expected: '$version')")
}

val pomFile = artifactFile(extension = "pom")
val pom = when {
pomFile.exists() ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ internal class SpaceApiClient(
val groupId: String,
val artifactId: String,
val version: String
)
) {
override fun toString() = "$groupId:$artifactId:$version"
}

fun forEachPackageWithVersion(
projectId: ProjectIdentifier,
Expand Down

0 comments on commit 4ce6a59

Please sign in to comment.