Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package aws.sdk.kotlin.gradle.dsl

import aws.sdk.kotlin.gradle.util.getOrNull
import aws.sdk.kotlin.gradle.util.verifyRootProject
import io.github.gradlenexus.publishplugin.NexusPublishExtension
import org.gradle.api.Project
Expand Down Expand Up @@ -56,22 +57,27 @@ internal val ALLOWED_PUBLICATION_NAMES = setOf(
"dynamodb-mapper-schema-generatorPluginMarkerMaven",
)

internal val KOTLIN_NATIVE_PUBLICATION_NAMES = setOf(
internal val ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES = setOf(
"iosArm64",
"iosSimulatorArm64",
"iosX64",

"linuxArm64",
"linuxX64",
"macosArm64",
"macosX64",
"mingwX64",
)

// TODO Refactor to support project names _or_ publication group names.
// aws-crt-kotlin is not published with a group name, so we need to check project names instead.
private val KOTLIN_NATIVE_PROJECT_NAMES = setOf(
"aws-crt-kotlin",
// Group names which are allowed to publish K/N artifacts
private val ALLOWED_KOTLIN_NATIVE_GROUP_NAMES = setOf(
"aws.sdk.kotlin.crt",
)

// Optional override to the above set.
// Used to support local development where you want to run publishToMavenLocal in smithy-kotlin, aws-sdk-kotlin.
internal const val OVERRIDE_KOTLIN_NATIVE_GROUP_NAME_VALIDATION = "aws.kotlin.native.allowPublication"

/**
* Mark this project as excluded from publishing
*/
Expand Down Expand Up @@ -381,16 +387,19 @@ internal fun isAvailableForPublication(project: Project, publication: MavenPubli
// Check SKIP_PUBLISH_PROP
if (project.extra.has(Properties.SKIP_PUBLISHING)) shouldPublish = false

// Only publish publications with the configured group from JReleaser or everything if JReleaser group is not configured
// Only publish publications with the configured group from JReleaser, or everything if JReleaser group is not configured
val publishGroupName = System.getenv(EnvironmentVariables.GROUP_ID)
shouldPublish = shouldPublish && (publishGroupName == null || publication.groupId.startsWith(publishGroupName))
shouldPublish = shouldPublish && (publishGroupName == null || publication.groupId.equals(publishGroupName, ignoreCase = true))

val overrideGroupNameValidation = project.extra.getOrNull<String>(OVERRIDE_KOTLIN_NATIVE_GROUP_NAME_VALIDATION) == "true"
if (overrideGroupNameValidation) println("Overriding group name validation for Kotlin/Native publications")

// Validate publication name is allowed to be published
shouldPublish = shouldPublish &&
(
ALLOWED_PUBLICATION_NAMES.any { publication.name.equals(it, ignoreCase = true) } ||
// standard publication
(KOTLIN_NATIVE_PUBLICATION_NAMES.any { publication.name.equals(it, ignoreCase = true) } && KOTLIN_NATIVE_PROJECT_NAMES.any { project.name.equals(it, ignoreCase = true) }) // Kotlin/Native publication
(ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES.any { publication.name.equals(it, ignoreCase = true) } && (overrideGroupNameValidation || ALLOWED_KOTLIN_NATIVE_GROUP_NAMES.any { publication.groupId.equals(it, ignoreCase = true) })) // Kotlin/Native publication
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: I'm a little confused at how this works. If you're trying to override and publish smithy-kotlin, won't shouldPublish get set to false on L392 because publication.groupId won't equal publishGroupName? And if so, won't the shouldPublish = shouldPublish && ... logic on L398 short-circuit and skip evaluating overrideGroupNameValidation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That logic on L392 is only used by our Catapult release (dependent on JReleaser environment variable). That needs to be cleaned up separately. In local development the publishGroupName == null part is true and short-circuits

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaned up this logic, should be ready for another review now


return shouldPublish
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package aws.sdk.kotlin.gradle.dsl
import kotlinx.coroutines.test.runTest
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.internal.extensions.core.extra
import org.gradle.testfixtures.ProjectBuilder
import kotlin.test.Test
import kotlin.test.assertFalse
Expand All @@ -32,7 +33,7 @@ class PublishTest {
assertTrue(isAvailableForPublication(project, jvmRuntimePublication))
}

KOTLIN_NATIVE_PUBLICATION_NAMES.forEach {
ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES.forEach {
val nativeRuntimePublication = create(it, MavenPublication::class.java).apply {
groupId = "aws.sdk.kotlin.crt"
version = "1.2.3"
Expand Down Expand Up @@ -62,7 +63,7 @@ class PublishTest {
assertTrue(isAvailableForPublication(project, jvmRuntimePublication))
}

KOTLIN_NATIVE_PUBLICATION_NAMES.forEach {
ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES.forEach {
val nativeRuntimePublication = create(it, MavenPublication::class.java).apply {
groupId = "aws.sdk.kotlin"
version = "1.2.3"
Expand Down Expand Up @@ -92,7 +93,69 @@ class PublishTest {
assertTrue(isAvailableForPublication(project, jvmRuntimePublication))
}

KOTLIN_NATIVE_PUBLICATION_NAMES.forEach {
ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES.forEach {
val nativeRuntimePublication = create(it, MavenPublication::class.java).apply {
groupId = "aws.smithy.kotlin"
version = "1.2.3"
artifactId = "runtime"
}
assertFalse(isAvailableForPublication(project, nativeRuntimePublication))
}
}
}

@Test
fun `users can override smithy-kotlin publication`() = runTest {
val project = ProjectBuilder.builder().withName("aws-smithy-kotlin").build()
project.group = "aws.smithy.kotlin"
project.version = "1.2.3"
project.extra.set(OVERRIDE_KOTLIN_NATIVE_GROUP_NAME_VALIDATION, "true")

project.configurePublishing("smithy-kotlin", "smithy-lang")

val publishing = project.extensions.getByType(PublishingExtension::class.java)
publishing.publications {
ALLOWED_PUBLICATION_NAMES.forEach {
val jvmRuntimePublication = create(it, MavenPublication::class.java).apply {
groupId = "aws.smithy.kotlin"
version = "1.2.3"
artifactId = "runtime"
}
assertTrue(isAvailableForPublication(project, jvmRuntimePublication))
}

ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES.forEach {
val nativeRuntimePublication = create(it, MavenPublication::class.java).apply {
groupId = "aws.smithy.kotlin"
version = "1.2.3"
artifactId = "runtime"
}
assertTrue(isAvailableForPublication(project, nativeRuntimePublication))
}
}
}

@Test
fun `override only works when set to true`() = runTest {
val project = ProjectBuilder.builder().withName("aws-smithy-kotlin").build()
project.group = "aws.smithy.kotlin"
project.version = "1.2.3"
project.extra.set(OVERRIDE_KOTLIN_NATIVE_GROUP_NAME_VALIDATION, "this is not true")

project.configurePublishing("smithy-kotlin", "smithy-lang")

val publishing = project.extensions.getByType(PublishingExtension::class.java)
publishing.publications {
ALLOWED_PUBLICATION_NAMES.forEach {
val jvmRuntimePublication = create(it, MavenPublication::class.java).apply {
groupId = "aws.smithy.kotlin"
version = "1.2.3"
artifactId = "runtime"
}
assertTrue(isAvailableForPublication(project, jvmRuntimePublication))
}

ALLOWED_KOTLIN_NATIVE_PUBLICATION_NAMES.forEach {
val nativeRuntimePublication = create(it, MavenPublication::class.java).apply {
groupId = "aws.smithy.kotlin"
version = "1.2.3"
Expand Down
Loading