Skip to content

Commit

Permalink
Only output dev preview warning messages for 0.x versions
Browse files Browse the repository at this point in the history
  • Loading branch information
jdisanti committed Nov 16, 2023
1 parent 68eade9 commit c2c9086
Show file tree
Hide file tree
Showing 8 changed files with 291 additions and 21 deletions.
11 changes: 8 additions & 3 deletions aws/SDK_README.md.hb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ It gets instantiated and copied into the build artifacts by the `aws:sdk:assembl
Available template arguments:
- `{{sdk_version_<crate_name_in_snake_case>}}` (e.g., `{{sdk_version_aws_config}}` for the `aws-config` crate): the version number of the given crate (just the number, no `v` prefix)
- `{{msrv}}`: The MSRV Rust compiler version (just the number, no `v` prefix)
- `{{warning_banner}}`: Show the production warning banner
--}}
<!--
IMPORTANT:
Expand All @@ -14,11 +15,14 @@ To update it, edit the `aws/SDK_README.md.hb` Handlebars template in that reposi

# The AWS SDK for Rust [![Docs](https://img.shields.io/badge/docs-blue)](https://awslabs.github.io/aws-sdk-rust/) ![MSRV](https://img.shields.io/badge/msrv-{{msrv}}-red) [![Usage Guide](https://img.shields.io/badge/Developer_Guide-blue)](https://docs.aws.amazon.com/sdk-for-rust/latest/dg/welcome.html)

This repo contains the new AWS SDK for Rust (the SDK) and its [public roadmap](https://github.com/orgs/awslabs/projects/50/views/1).
This repo contains the AWS SDK for Rust and its [public roadmap](https://github.com/orgs/awslabs/projects/50/views/1).

{{#if warning_banner}}
**Please Note**: The SDK is currently released as a developer preview, without support or assistance for use on production workloads. Any use in production is at your own risk.
{{/if}}

The SDK is code generated from [Smithy models](https://awslabs.github.io/smithy/) that represent each AWS service. The code used to generate the SDK can be found in [smithy-rs](https://github.com/smithy-lang/smithy-rs).
The SDK is code generated from [Smithy models](https://awslabs.github.io/smithy/) that represent each AWS service.
The code used to generate the SDK can be found in [smithy-rs](https://github.com/smithy-lang/smithy-rs).

## Getting Started with the SDK

Expand Down Expand Up @@ -67,7 +71,8 @@ In order to use the SDK, you must already have Rust and Cargo installed. If you
## Using the SDK
While we're working on the SDK, detailed usage instructions will be added to the [Developer Guide](https://docs.aws.amazon.com/sdk-for-rust/latest/dg/welcome.html). Please suggest additional sections for the guide by opening an issue and describing what you are trying to do.
While we're working on the SDK, detailed usage instructions will be added to the [Developer Guide](https://docs.aws.amazon.com/sdk-for-rust/latest/dg/welcome.html).
Please suggest additional sections for the guide by opening an issue and describing what you are trying to do.

## Getting Help
* [Developer Guide](https://docs.aws.amazon.com/sdk-for-rust/latest/dg/welcome.html)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ internal class AwsCrateDocGenerator(private val codegenContext: ClientCodegenCon
else -> rawTemplate(text + "\n", *args)
}

private fun docText(
internal fun docText(
includeHeader: Boolean,
includeLicense: Boolean,
asComments: Boolean,
): Writable = writable {
val moduleName = codegenContext.settings.moduleName
val stableVersion = !codegenContext.settings.moduleVersion.startsWith("0.")
val description = normalizeDescription(
codegenContext.moduleName,
codegenContext.settings.getService(codegenContext.model).getTrait<DocumentationTrait>()?.value ?: "",
Expand All @@ -119,14 +120,18 @@ internal class AwsCrateDocGenerator(private val codegenContext: ClientCodegenCon
if (includeHeader) {
template(asComments, escape("# $moduleName\n"))
}

// TODO(PostGA): Remove warning banner conditionals.
// NOTE: when you change this, you must also change SDK_README.md.hb
template(
asComments,
"""
**Please Note: The SDK is currently released as a developer preview, without support or assistance for use
on production workloads. Any use in production is at your own risk.**${"\n"}
""".trimIndent(),
)
if (!stableVersion) {
template(
asComments,
"""
**Please Note: The SDK is currently released as a developer preview, without support or assistance for use
on production workloads. Any use in production is at your own risk.**${"\n"}
""".trimIndent(),
)
}

if (description.isNotBlank()) {
template(asComments, escape("$description\n"))
Expand Down
53 changes: 53 additions & 0 deletions aws/sdk-codegen/src/test/kotlin/AwsCrateDocsDecoratorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
*/

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import software.amazon.smithy.model.loader.ModelAssembler
import software.amazon.smithy.model.node.ObjectNode
import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.rust.codegen.client.testutil.testClientCodegenContext
import software.amazon.smithy.rust.codegen.client.testutil.testClientRustSettings
import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel
import software.amazon.smithy.rustsdk.AwsCrateDocGenerator
import software.amazon.smithy.rustsdk.AwsTestRuntimeConfig

class AwsCrateDocsDecoratorTest {
private val codegenContext = testClientCodegenContext(ModelAssembler().assemble().unwrap())
Expand Down Expand Up @@ -106,4 +114,49 @@ class AwsCrateDocsDecoratorTest {
),
)
}

// TODO(PostGA): Remove warning banner conditionals.
@Test
fun warningBanner() {
val context = { version: String ->
testClientCodegenContext(
model = """
namespace test
service Foobaz {
}
""".asSmithyModel(),
settings = testClientRustSettings(
moduleVersion = version,
service = ShapeId.from("test#Foobaz"),
runtimeConfig = AwsTestRuntimeConfig,
customizationConfig =
ObjectNode.parse(
"""
{ "awsSdk": {
"awsConfigVersion": "dontcare" } }
""",
) as ObjectNode,
),
)
}

// Test unstable versions first
var codegenContext = context("0.36.0")
var result = AwsCrateDocGenerator(codegenContext).docText(includeHeader = false, includeLicense = false, asComments = true).let { writable ->
val writer = RustWriter.root()
writable(writer)
writer.toString()
}
assertTrue(result.contains("The SDK is currently released as a developer preview"))

// And now stable versions
codegenContext = context("1.0.0")
result = AwsCrateDocGenerator(codegenContext).docText(includeHeader = false, includeLicense = false, asComments = true).let { writable ->
val writer = RustWriter.root()
writable(writer)
writer.toString()
}
assertFalse(result.contains("The SDK is currently released as a developer preview"))
}
}
53 changes: 53 additions & 0 deletions aws/sdk-codegen/src/test/kotlin/SdkCodegenIntegrationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
*/

import org.junit.jupiter.api.Test
import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel
import software.amazon.smithy.rust.codegen.core.testutil.integrationTest
import software.amazon.smithy.rustsdk.awsIntegrationTestParams
import software.amazon.smithy.rustsdk.awsSdkIntegrationTest

class SdkCodegenIntegrationTest {
Expand Down Expand Up @@ -50,4 +53,54 @@ class SdkCodegenIntegrationTest {
fun smokeTestSdkCodegen() {
awsSdkIntegrationTest(model) { _, _ -> /* it should compile */ }
}

// TODO(PostGA): Remove warning banner conditionals.
@Test
fun warningBanners() {
// Unstable version
awsSdkIntegrationTest(
model,
params = awsIntegrationTestParams().copy(moduleVersion = "0.36.0"),
) { _, rustCrate ->
rustCrate.integrationTest("banner") {
rust(
"""
##[test]
fn banner() {
use std::process::Command;
use std::path::Path;
// Verify we're in the right directory
assert!(Path::new("Cargo.toml").try_exists().unwrap());
let output = Command::new("grep").arg("developer preview").arg("-i").arg("-R").arg(".").output().unwrap();
assert_eq!(0, output.status.code().unwrap(), "it should output the banner");
}
""",
)
}
}

// Stable version
awsSdkIntegrationTest(
model,
params = awsIntegrationTestParams().copy(moduleVersion = "1.0.0"),
) { _, rustCrate ->
rustCrate.integrationTest("no_banner") {
rust(
"""
##[test]
fn banner() {
use std::process::Command;
use std::path::Path;
// Verify we're in the right directory
assert!(Path::new("Cargo.toml").try_exists().unwrap());
let output = Command::new("grep").arg("developer preview").arg("-i").arg("-R").arg(".").output().unwrap();
assert_eq!(1, output.status.code().unwrap(), "it should _not_ output the banner");
}
""",
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ fun awsTestCodegenContext(model: Model? = null, settings: ClientRustSettings? =

fun awsSdkIntegrationTest(
model: Model,
params: IntegrationTestParams = awsIntegrationTestParams(),
test: (ClientCodegenContext, RustCrate) -> Unit = { _, _ -> },
) =
clientIntegrationTest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import java.util.logging.Logger
data class IntegrationTestParams(
val addModuleToEventStreamAllowList: Boolean = false,
val service: String? = null,
val moduleVersion: String = "1.0.0",
val runtimeConfig: RuntimeConfig? = null,
val additionalSettings: ObjectNode = ObjectNode.builder().build(),
val overrideTestDir: File? = null,
Expand All @@ -36,6 +37,7 @@ fun codegenIntegrationTest(model: Model, params: IntegrationTestParams, invokePl
model,
params.additionalSettings,
params.addModuleToEventStreamAllowList,
params.moduleVersion,
params.service,
params.runtimeConfig,
params.overrideTestDir,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ fun generatePluginContext(
model: Model,
additionalSettings: ObjectNode = ObjectNode.builder().build(),
addModuleToEventStreamAllowList: Boolean = false,
moduleVersion: String = "1.0.0",
service: String? = null,
runtimeConfig: RuntimeConfig? = null,
overrideTestDir: File? = null,
Expand All @@ -174,7 +175,7 @@ fun generatePluginContext(
val manifest = FileManifest.create(testPath)
var settingsBuilder = Node.objectNodeBuilder()
.withMember("module", Node.from(moduleName))
.withMember("moduleVersion", Node.from("1.0.0"))
.withMember("moduleVersion", Node.from(moduleVersion))
.withMember("moduleDescription", Node.from("test"))
.withMember("moduleAuthors", Node.fromStrings("[email protected]"))
.letIf(service != null) { it.withMember("service", service) }
Expand Down
Loading

0 comments on commit c2c9086

Please sign in to comment.