Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: smoke tests #1388

Merged
merged 31 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
602bac1
feat: smoke tests
0marperez Aug 23, 2024
989d8ec
Merge branch 'main' of https://github.com/awslabs/aws-sdk-kotlin into…
0marperez Aug 23, 2024
9ca8f2e
Sending verified commit to trigger CI
0marperez Aug 23, 2024
b00ec1f
Actually sign commit message[B
0marperez Aug 23, 2024
35708df
PR feedback
0marperez Aug 28, 2024
2399355
Remove error log commited by accident
0marperez Aug 28, 2024
2d98a99
Add TODO
0marperez Aug 28, 2024
d7a4877
Added E2E tests
0marperez Sep 13, 2024
f390f6a
Remove dangerous gradle task, move sdk denylist check to codegen inst…
0marperez Sep 17, 2024
90a93ac
Fix kotlin native builds failing
0marperez Sep 18, 2024
6b288ed
Temp print statement to debug
0marperez Sep 18, 2024
c6701cb
Change debugging print to exception
0marperez Sep 18, 2024
95b553d
chmod gradlew before tests
0marperez Sep 18, 2024
5ac3db2
Use gradlew.bat
0marperez Sep 19, 2024
ca30211
ls sdk root dir
0marperez Sep 19, 2024
08356db
Use gradle connector instead of process builder
0marperez Sep 20, 2024
e7fdeff
build before testing
0marperez Sep 20, 2024
8f0dec1
increase gradle connection timeout
0marperez Sep 20, 2024
431e63e
run from sdk root dir, better logging, use explicit gradle distributi…
0marperez Sep 20, 2024
1706764
Enable gradle daemon with an idle timeout, increment internal timeout
0marperez Sep 21, 2024
bb53c3d
use gradle runner instead of connector
0marperez Sep 22, 2024
e13e9fc
Specify smokeTests to run & better test failure logging
0marperez Sep 22, 2024
afc5168
fix parallel task execution issues
0marperez Sep 22, 2024
c39f3fe
move task dependency from ci tests to code
0marperez Sep 23, 2024
5dfd004
easy to fix PR feedback and decoupling SmokeTestRunnerGenerator from SDK
0marperez Sep 23, 2024
87fa6bb
Merge branch 'main' of https://github.com/awslabs/aws-sdk-kotlin into…
0marperez Sep 23, 2024
c1e0edf
Remove accidental changes to AWS model
0marperez Sep 24, 2024
dfcffbb
Run smoke tests in common
0marperez Sep 24, 2024
25b8e8e
Self nits
0marperez Sep 24, 2024
8aae6e4
Use new runtime function for env vars
0marperez Sep 24, 2024
5687f7e
Cleanup, Clarity changes to test code in src
0marperez Sep 25, 2024
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
5 changes: 5 additions & 0 deletions .changes/ab4f3405-e013-4caf-89d7-1d820bcdd228.json
Copy link
Member

Choose a reason for hiding this comment

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

opinion: I don't think we need a changelog entry here in aws-sdk-kotlin, it's not customer-facing

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "ab4f3405-e013-4caf-89d7-1d820bcdd228",
"type": "feature",
"description": "Add support for smoke tests"
}
1 change: 1 addition & 0 deletions codegen/aws-sdk-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {
api(libs.smithy.aws.cloudformation.traits)
api(libs.smithy.protocol.test.traits)
implementation(libs.smithy.aws.endpoints)
implementation(libs.smithy.smoke.test.traits)

testImplementation(libs.junit.jupiter)
testImplementation(libs.junit.jupiter.params)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
*/
package aws.sdk.kotlin.codegen

import software.amazon.smithy.kotlin.codegen.KotlinSettings
import software.amazon.smithy.kotlin.codegen.core.*
import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration
import software.amazon.smithy.kotlin.codegen.model.hasTrait
import software.amazon.smithy.kotlin.codegen.rendering.GradleWriter
import software.amazon.smithy.kotlin.codegen.rendering.smoketests.smokeTestDenyList
import software.amazon.smithy.kotlin.codegen.utils.operations
import software.amazon.smithy.model.Model
import software.amazon.smithy.smoketests.traits.SmokeTestsTrait
import java.util.concurrent.atomic.AtomicBoolean

// TODO - would be nice to allow integrations to define custom settings in the plugin
// e.g. we could then more consistently apply this integration if we could define a property like: `build.isAwsSdk: true`
Expand All @@ -16,6 +23,14 @@ import software.amazon.smithy.kotlin.codegen.rendering.GradleWriter
*/
class GradleGenerator : KotlinIntegration {

private var hasSmokeTests = AtomicBoolean(false)

// Only used to access settings - will always be true
override fun enabledForService(model: Model, settings: KotlinSettings): Boolean {
hasSmokeTests.set(model.operations(settings.service).any { it.hasTrait<SmokeTestsTrait>() })
return super.enabledForService(model, settings)
}

Copy link
Member

Choose a reason for hiding this comment

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

You can access ctx.settings in generateGradleBuild, do you need this atomic boolean / enabledForService?

// Specify to run last, to ensure all other integrations have had a chance to register dependencies.
override val order: Byte
get() = 127
Expand Down Expand Up @@ -50,6 +65,10 @@ class GradleGenerator : KotlinIntegration {
writer
.write("")
.withBlock("kotlin {", "}") {
if (hasSmokeTests.get() && !smokeTestDenyList.contains(ctx.settings.sdkId)) {
generateSmokeTestJarTask(writer)
generateSmokeTestTask(writer)
}
withBlock("sourceSets {", "}") {
allDependencies
.sortedWith(compareBy({ it.config }, { it.artifact }))
Expand All @@ -69,4 +88,41 @@ class GradleGenerator : KotlinIntegration {
val contents = writer.toString()
delegator.fileManifest.writeFile("build.gradle.kts", contents)
}

private fun generateSmokeTestJarTask(writer: GradleWriter) {
val moneySign = "$"
writer.withBlock("jvm {", "}") {
withBlock("compilations {", "}") {
write("val main = getByName(\"main\")")
withBlock("tasks {", "}") {
withBlock("register<Jar>(\"smokeTestJar\") {", "}") {
Copy link
Member

Choose a reason for hiding this comment

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

Use #S instead of managing the quotes yourself

write("description = \"Creates smoke tests jar\"")
write("group = \"application\"")
write("dependsOn(build)")
withBlock("manifest {", "}") {
write("attributes[\"Main-Class\"] = \"smoketests.SmokeTestsKt\"")
}
write("duplicatesStrategy = DuplicatesStrategy.EXCLUDE")
write("from(configurations.getByName(\"jvmRuntimeClasspath\").map { if (it.isDirectory) it else zipTree(it) }, main.output.classesDirs)")
write("archiveBaseName.set(\"$moneySign{project.name}-smoketests\")")
}
}
}
}
writer.emptyLine()
}

private fun generateSmokeTestTask(writer: GradleWriter) {
val moneySign = "$"
writer.withBlock("tasks.register<JavaExec>(\"smokeTest\") {", "}") {
write("description = \"Runs smoke tests jar\"")
write("group = \"verification\"")
write("dependsOn(tasks.getByName(\"smokeTestJar\"))")
emptyLine()
write("val sdkVersion: String by project")
write("val jarFile = file(\"build/libs/$moneySign{project.name}-smoketests-\$sdkVersion.jar\")")
write("classpath = files(jarFile)")
}
writer.emptyLine()
}
}
4 changes: 4 additions & 0 deletions codegen/sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ val stageSdks = tasks.register("stageSdks") {
from("$projectionOutputDir/src")
into("${it.destinationDir}/generated-src")
}
copy {
from("$projectionOutputDir/jvm-src")
into("${it.destinationDir}/generated-src-jvm")
}
copy {
from("$projectionOutputDir/build.gradle.kts")
into(it.destinationDir)
Expand Down
4 changes: 4 additions & 0 deletions services/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ subprojects {
kotlin.srcDir("generated-src/main/kotlin")
}

getByName("jvmMain") {
kotlin.srcDir("generated-src-jvm/main/java")
}

getByName("commonTest") {
kotlin.srcDir("generated-src/test")

Expand Down
Loading