Unverified Commit fa61448b authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Remove warning banner code (#3407)

## Motivation and Context
Remove warning banner related code. The test is broken so this code is
just causing a hassle and will never be used again.

- [ ] A generated code diff should be audited prior to merging.
----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent c43fc71c
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ 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:
@@ -17,10 +16,6 @@ To update it, edit the `aws/SDK_README.md.hb` Handlebars template in that reposi

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://smithy.io/2.0/index.html) 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).

+0 −13
Original line number Diff line number Diff line
@@ -126,7 +126,6 @@ internal class AwsCrateDocGenerator(private val codegenContext: ClientCodegenCon
            check(moduleVersion.isNotEmpty() && moduleVersion[0].isDigit())

            val moduleName = codegenContext.settings.moduleName
            val stableVersion = !moduleVersion.startsWith("0.")
            val description =
                normalizeDescription(
                    codegenContext.moduleName,
@@ -139,18 +138,6 @@ internal class AwsCrateDocGenerator(private val codegenContext: ClientCodegenCon
                template(asComments, escape("# $moduleName\n"))
            }

            // TODO(PostGA): Remove warning banner conditionals.
            // NOTE: when you change this, you must also change SDK_README.md.hb
            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"))
            }
+0 −57
Original line number Diff line number Diff line
@@ -4,18 +4,10 @@
 */

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())
@@ -114,53 +106,4 @@ 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"))
    }
}
+0 −53
Original line number Diff line number Diff line
@@ -4,10 +4,7 @@
 */

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 {
@@ -56,54 +53,4 @@ class SdkCodegenIntegrationTest {
            // 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");
                    }
                    """,
                )
            }
        }
    }
}
+0 −145
Original line number Diff line number Diff line
@@ -9,7 +9,6 @@ use fs_err as fs;
use handlebars::Handlebars;
use serde::Serialize;
use serde_json::json;
use smithy_rs_tool_common::package::PackageCategory;
use smithy_rs_tool_common::versions_manifest::VersionsManifest;
use std::path::PathBuf;

@@ -58,12 +57,6 @@ fn hydrate_template<C: Serialize>(template_string: &str, template_context: &C) -
fn make_context(msrv: &str, versions_manifest: &VersionsManifest) -> serde_json::Value {
    let mut context = json!({ "msrv": msrv });

    // TODO(PostGA): Remove warning banner conditionals
    context.as_object_mut().unwrap().insert(
        "warning_banner".into(),
        serde_json::Value::Bool(!stable_release(versions_manifest)),
    );

    for (crate_name, metadata) in &versions_manifest.crates {
        let key = format!("sdk_version_{}", crate_name.replace('-', "_"));
        context
@@ -74,23 +67,10 @@ fn make_context(msrv: &str, versions_manifest: &VersionsManifest) -> serde_json:
    context
}

// TODO(PostGA): Remove warning banner conditionals
fn stable_release(manifest: &VersionsManifest) -> bool {
    manifest.crates.iter().any(|(_name, version)| {
        version.category == PackageCategory::AwsSdk && !version.version.starts_with("0.")
    })
}

#[cfg(test)]
mod tests {
    use super::hydrate_template;
    use crate::subcommand::hydrate_readme::make_context;
    use serde_json::json;
    use smithy_rs_tool_common::package::PackageCategory;
    use smithy_rs_tool_common::versions_manifest::{
        CrateVersion, ManualInterventions, VersionsManifest,
    };
    use std::collections::BTreeMap;

    #[test]
    fn test_hydrate_template() {
@@ -115,129 +95,4 @@ mod tests {
            hydrated,
        )
    }

    fn version(category: PackageCategory, version: &str) -> CrateVersion {
        CrateVersion {
            category,
            version: version.into(),
            source_hash: "dontcare".into(),
            model_hash: None,
        }
    }
    fn make_manifest(crates: &BTreeMap<String, CrateVersion>) -> VersionsManifest {
        VersionsManifest {
            smithy_rs_revision: "dontcare".into(),
            aws_doc_sdk_examples_revision: "dontcare".into(),
            manual_interventions: ManualInterventions::default(),
            crates: crates.clone(),
            release: None,
        }
    }

    // TODO(PostGA): Remove warning banner conditionals
    #[test]
    fn test_stable_release() {
        // Validate assumptions about package categories with some precondition checks
        assert_eq!(
            PackageCategory::SmithyRuntime,
            PackageCategory::from_package_name("aws-smithy-runtime"),
            "precondition"
        );
        assert_eq!(
            PackageCategory::AwsRuntime,
            PackageCategory::from_package_name("aws-runtime"),
            "precondition"
        );
        assert_eq!(
            PackageCategory::AwsSdk,
            PackageCategory::from_package_name("aws-sdk-s3"),
            "precondition"
        );

        // With S3 at 0.36, it is not considered stable
        let mut crates = BTreeMap::new();
        crates.insert(
            "aws-smithy-http".to_string(),
            version(PackageCategory::SmithyRuntime, "0.36.0"),
        );
        crates.insert(
            "aws-smithy-runtime".to_string(),
            version(PackageCategory::SmithyRuntime, "1.0.0"),
        );
        crates.insert(
            "aws-runtime".to_string(),
            version(PackageCategory::AwsRuntime, "1.0.0"),
        );
        crates.insert(
            "aws-sdk-s3".to_string(),
            version(PackageCategory::AwsSdk, "0.36.0"),
        );
        let manifest = make_manifest(&crates);
        assert!(
            !super::stable_release(&manifest),
            "it is not stable since S3 is 0.36"
        );

        // Now with S3 at 1.0, it is considered stable
        crates.insert(
            "aws-sdk-s3".to_string(),
            version(PackageCategory::AwsSdk, "1.0.0"),
        );
        let manifest = make_manifest(&crates);
        assert!(
            super::stable_release(&manifest),
            "it is stable since S3 is 1.0"
        );
    }

    // TODO(PostGA): Remove warning banner conditionals
    #[test]
    fn test_warning_banner() {
        // First, test with unstable versions
        let mut crates = BTreeMap::new();
        crates.insert(
            "aws-smithy-runtime".to_string(),
            version(PackageCategory::SmithyRuntime, "1.0.0"),
        );
        crates.insert(
            "aws-runtime".to_string(),
            version(PackageCategory::AwsRuntime, "1.0.0"),
        );
        crates.insert(
            "aws-sdk-s3".to_string(),
            version(PackageCategory::AwsSdk, "0.36.0"),
        );
        let manifest = make_manifest(&crates);

        let context = make_context("dontcare-msrv", &manifest);
        assert!(
            context
                .as_object()
                .unwrap()
                .get("warning_banner")
                .unwrap()
                .as_bool()
                .unwrap(),
            "it should have the warning banner because it's unstable"
        );

        // Next, test with stable versions
        crates.insert(
            "aws-sdk-s3".to_string(),
            version(PackageCategory::AwsSdk, "1.0.0"),
        );
        let manifest = make_manifest(&crates);

        let context = make_context("dontcare-msrv", &manifest);
        assert!(
            !context
                .as_object()
                .unwrap()
                .get("warning_banner")
                .unwrap()
                .as_bool()
                .unwrap(),
            "it should _not_ have the warning banner because it's unstable"
        );
    }
}