Skip to content

Commit 4f1e17b

Browse files
authored
kn: merge back into main (#111)
1 parent f66c20d commit 4f1e17b

File tree

8 files changed

+261
-72
lines changed

8 files changed

+261
-72
lines changed

.github/actions/checkout-head/action.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ inputs:
2323
commands. The post-job step removes the PAT.
2424
default: ${{ github.token }}
2525
required: false
26+
submodules:
27+
description: >
28+
Whether to checkout submodules. `true` to checkout submodules or `recursive` to recursively checkout submodules
29+
default: 'false'
30+
required: 'false'
2631

2732
runs:
2833
using: composite
@@ -44,7 +49,9 @@ runs:
4449
echo "ref=$ref" >> "$GITHUB_OUTPUT"
4550
else
4651
baseref="main"
47-
if [ -n "$GITHUB_BASE_REF" ]; then
52+
if [[ "$ref" == kn-* ]] && git ls-remote --exit-code --heads "https://github.com/$REPOSITORY.git" "kn-main"; then
53+
baseref="kn-main"
54+
elif [ -n "$GITHUB_BASE_REF" ]; then
4855
echo "attempting GH base ref: $GITHUB_BASE_REF"
4956
if git ls-remote --exit-code --heads "https://github.com/$REPOSITORY.git" "$GITHUB_BASE_REF"; then
5057
baseref="$GITHUB_BASE_REF"
@@ -60,4 +67,5 @@ runs:
6067
path: ${{ inputs.path }}
6168
repository: ${{ inputs.repository }}
6269
ref: ${{ steps.repo.outputs.ref }}
63-
token: ${{ inputs.token }}
70+
token: ${{ inputs.token }}
71+
submodules: ${{ inputs.submodules }}

build-plugins/build-support/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ dependencies {
2929
compileOnly(gradleApi())
3030
implementation(libs.aws.sdk.s3)
3131
implementation(libs.aws.sdk.cloudwatch)
32-
testImplementation(libs.junit.jupiter)
32+
testImplementation(kotlin("test"))
33+
testImplementation(libs.kotlinx.coroutines.test)
3334
}
3435

3536
gradlePlugin {

build-plugins/build-support/src/main/kotlin/aws/sdk/kotlin/gradle/dsl/Publish.kt

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ private object EnvironmentVariables {
3838
const val GPG_SECRET_KEY = "JRELEASER_GPG_SECRET_KEY"
3939
}
4040

41-
private val ALLOWED_PUBLICATION_NAMES = setOf(
41+
internal val ALLOWED_PUBLICATION_NAMES = setOf(
4242
"common",
4343
"jvm",
44-
"metadata",
4544
"kotlinMultiplatform",
45+
"metadata",
4646
"bom",
4747
"versionCatalog",
48-
"android", // aws-crt-kotlin
4948
"codegen",
5049
"codegen-testutils",
5150

@@ -57,6 +56,22 @@ private val ALLOWED_PUBLICATION_NAMES = setOf(
5756
"dynamodb-mapper-schema-generatorPluginMarkerMaven",
5857
)
5958

59+
internal val KOTLIN_NATIVE_PUBLICATION_NAMES = setOf(
60+
"iosArm64",
61+
"iosX64",
62+
"linuxArm64",
63+
"linuxX64",
64+
"macosArm64",
65+
"macosX64",
66+
"mingwX64",
67+
)
68+
69+
// TODO Refactor to support project names _or_ publication group names.
70+
// aws-crt-kotlin is not published with a group name, so we need to check project names instead.
71+
private val KOTLIN_NATIVE_PROJECT_NAMES = setOf(
72+
"aws-crt-kotlin",
73+
)
74+
6075
/**
6176
* Mark this project as excluded from publishing
6277
*/
@@ -360,7 +375,7 @@ fun Project.configureJReleaser() {
360375
}
361376
}
362377

363-
private fun isAvailableForPublication(project: Project, publication: MavenPublication): Boolean {
378+
internal fun isAvailableForPublication(project: Project, publication: MavenPublication): Boolean {
364379
var shouldPublish = true
365380

366381
// Check SKIP_PUBLISH_PROP
@@ -371,7 +386,12 @@ private fun isAvailableForPublication(project: Project, publication: MavenPublic
371386
shouldPublish = shouldPublish && (publishGroupName == null || publication.groupId.startsWith(publishGroupName))
372387

373388
// Validate publication name is allowed to be published
374-
shouldPublish = shouldPublish && ALLOWED_PUBLICATION_NAMES.any { publication.name.equals(it, ignoreCase = true) }
389+
shouldPublish = shouldPublish &&
390+
(
391+
ALLOWED_PUBLICATION_NAMES.any { publication.name.equals(it, ignoreCase = true) } ||
392+
// standard publication
393+
(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
394+
)
375395

376396
return shouldPublish
377397
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package aws.sdk.kotlin.gradle.dsl
6+
7+
import kotlinx.coroutines.test.runTest
8+
import org.gradle.api.publish.PublishingExtension
9+
import org.gradle.api.publish.maven.MavenPublication
10+
import org.gradle.testfixtures.ProjectBuilder
11+
import kotlin.test.Test
12+
import kotlin.test.assertFalse
13+
import kotlin.test.assertTrue
14+
15+
class PublishTest {
16+
@Test
17+
fun `aws-crt-kotlin can publish Kotlin Native artifacts`() = runTest {
18+
val project = ProjectBuilder.builder().withName("aws-crt-kotlin").build()
19+
project.group = "aws.sdk.kotlin.crt"
20+
project.version = "1.2.3"
21+
22+
project.configurePublishing("aws-crt-kotlin")
23+
24+
val publishing = project.extensions.getByType(PublishingExtension::class.java)
25+
publishing.publications {
26+
ALLOWED_PUBLICATION_NAMES.forEach {
27+
val jvmRuntimePublication = create(it, MavenPublication::class.java).apply {
28+
groupId = "aws.sdk.kotlin.crt"
29+
version = "1.2.3"
30+
artifactId = "aws-crt-kotlin"
31+
}
32+
assertTrue(isAvailableForPublication(project, jvmRuntimePublication))
33+
}
34+
35+
KOTLIN_NATIVE_PUBLICATION_NAMES.forEach {
36+
val nativeRuntimePublication = create(it, MavenPublication::class.java).apply {
37+
groupId = "aws.sdk.kotlin.crt"
38+
version = "1.2.3"
39+
artifactId = "aws-crt-kotlin"
40+
}
41+
assertTrue(isAvailableForPublication(project, nativeRuntimePublication))
42+
}
43+
}
44+
}
45+
46+
@Test
47+
fun `aws-sdk-kotlin cannot publish Kotlin Native artifacts`() = runTest {
48+
val project = ProjectBuilder.builder().withName("aws-sdk-kotlin").build()
49+
project.group = "aws.sdk.kotlin"
50+
project.version = "1.2.3"
51+
52+
project.configurePublishing("aws-sdk-kotlin")
53+
54+
val publishing = project.extensions.getByType(PublishingExtension::class.java)
55+
publishing.publications {
56+
ALLOWED_PUBLICATION_NAMES.forEach {
57+
val jvmRuntimePublication = create(it, MavenPublication::class.java).apply {
58+
groupId = "aws.sdk.kotlin"
59+
version = "1.2.3"
60+
artifactId = "aws-runtime"
61+
}
62+
assertTrue(isAvailableForPublication(project, jvmRuntimePublication))
63+
}
64+
65+
KOTLIN_NATIVE_PUBLICATION_NAMES.forEach {
66+
val nativeRuntimePublication = create(it, MavenPublication::class.java).apply {
67+
groupId = "aws.sdk.kotlin"
68+
version = "1.2.3"
69+
artifactId = "aws-runtime"
70+
}
71+
assertFalse(isAvailableForPublication(project, nativeRuntimePublication))
72+
}
73+
}
74+
}
75+
76+
@Test
77+
fun `smithy-kotlin cannot publish Kotlin Native artifacts`() = runTest {
78+
val project = ProjectBuilder.builder().withName("aws-smithy-kotlin").build()
79+
project.group = "aws.smithy.kotlin"
80+
project.version = "1.2.3"
81+
82+
project.configurePublishing("smithy-kotlin", "smithy-lang")
83+
84+
val publishing = project.extensions.getByType(PublishingExtension::class.java)
85+
publishing.publications {
86+
ALLOWED_PUBLICATION_NAMES.forEach {
87+
val jvmRuntimePublication = create(it, MavenPublication::class.java).apply {
88+
groupId = "aws.smithy.kotlin"
89+
version = "1.2.3"
90+
artifactId = "runtime"
91+
}
92+
assertTrue(isAvailableForPublication(project, jvmRuntimePublication))
93+
}
94+
95+
KOTLIN_NATIVE_PUBLICATION_NAMES.forEach {
96+
val nativeRuntimePublication = create(it, MavenPublication::class.java).apply {
97+
groupId = "aws.smithy.kotlin"
98+
version = "1.2.3"
99+
artifactId = "runtime"
100+
}
101+
assertFalse(isAvailableForPublication(project, nativeRuntimePublication))
102+
}
103+
}
104+
}
105+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package aws.sdk.kotlin.gradle.kmp
6+
7+
import org.gradle.api.Project
8+
import org.gradle.api.tasks.Exec
9+
import org.gradle.kotlin.dsl.withType
10+
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest
11+
import org.jetbrains.kotlin.konan.target.HostManager
12+
13+
private val DEFAULT_SIMULATOR_DEVICE_NAME = "iPhone 16"
14+
15+
/**
16+
* Disables standalone mode in simulator tests since it causes issues with TLS.
17+
* This means we need to manage the simulator state ourselves (booting, shutting down).
18+
* https://youtrack.jetbrains.com/issue/KT-38317
19+
*/
20+
public fun Project.configureIosSimulatorTasks() {
21+
if (!HostManager.hostIsMac) return
22+
23+
val simulatorDeviceName = project.findProperty("iosSimulatorDevice") as? String ?: DEFAULT_SIMULATOR_DEVICE_NAME
24+
val xcrun = "/usr/bin/xcrun"
25+
26+
val bootTask = rootProject.tasks.maybeCreate("bootIosSimulatorDevice", Exec::class.java).apply {
27+
isIgnoreExitValue = true
28+
commandLine(xcrun, "simctl", "boot", simulatorDeviceName)
29+
30+
doLast {
31+
val result = executionResult.get()
32+
val code = result.exitValue
33+
if (code != 148 && code != 149) { // ignore "simulator already running" errors
34+
result.assertNormalExitValue()
35+
}
36+
}
37+
}
38+
39+
val shutdownTask = rootProject.tasks.maybeCreate("shutdownIosSimulatorDevice", Exec::class.java).apply {
40+
isIgnoreExitValue = true
41+
commandLine(xcrun, "simctl", "shutdown", simulatorDeviceName)
42+
43+
doLast {
44+
val result = executionResult.get()
45+
val code = result.exitValue
46+
if (code != 148 && code != 149) { // ignore "simulator already shutdown" errors
47+
result.assertNormalExitValue()
48+
}
49+
}
50+
}
51+
52+
allprojects {
53+
val simulatorTasks = tasks.withType<KotlinNativeSimulatorTest>()
54+
simulatorTasks.configureEach {
55+
dependsOn(bootTask)
56+
standalone.set(false)
57+
device.set(simulatorDeviceName)
58+
}
59+
shutdownTask.mustRunAfter(simulatorTasks)
60+
}
61+
}

0 commit comments

Comments
 (0)