Unverified Commit 9f446647 authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

Clean up independent crate versioning migration (#1566)

parent 3610085a
Loading
Loading
Loading
Loading
+3 −72
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@
 */

use crate::entry::{ChangeSet, ChangelogEntries, ChangelogEntry};
use anyhow::{Context, Result};
use anyhow::{bail, Context, Result};
use clap::Parser;
use ordinal::Ordinal;
use serde::Serialize;
@@ -14,7 +14,6 @@ use smithy_rs_tool_common::changelog::{
use smithy_rs_tool_common::git::{find_git_repository_root, Git, GitCLI};
use std::env;
use std::fmt::Write;
use std::fs;
use std::path::PathBuf;
use time::OffsetDateTime;

@@ -47,7 +46,6 @@ pub struct RenderArgs {
    /// Which set of changes to render
    #[clap(long, action)]
    pub change_set: ChangeSet,
    // TODO(https://github.com/awslabs/smithy-rs/issues/1531): Require this arg to be `true`
    /// Whether or not independent crate versions are being used (defaults to false)
    #[clap(long, action)]
    pub independent_versioning: bool,
@@ -95,27 +93,10 @@ pub fn subcommand_render(args: &RenderArgs) -> Result<()> {
        let sdk_metadata = date_based_release_metadata(now, "aws-sdk-rust-release-manifest.json");
        update_changelogs(args, &smithy_rs, &smithy_rs_metadata, &sdk_metadata)
    } else {
        // TODO(https://github.com/awslabs/smithy-rs/issues/1531): Remove this code path entirely
        let auto = auto_changelog_meta(&smithy_rs)?;
        let smithy_rs_metadata = version_based_release_metadata(
            now,
            &auto.smithy_version,
            "smithy-rs-release-manifest.json",
        );
        let sdk_metadata = version_based_release_metadata(
            now,
            &auto.sdk_version,
            "aws-sdk-rust-release-manifest.json",
        );
        update_changelogs(args, &smithy_rs, &smithy_rs_metadata, &sdk_metadata)
        bail!("the --independent-versioning flag must be set; synchronized versioning no longer supported");
    }
}

struct ChangelogMeta {
    smithy_version: String,
    sdk_version: String,
}

struct ReleaseMetadata {
    title: String,
    tag: String,
@@ -147,22 +128,6 @@ fn date_based_release_metadata(
    }
}

fn version_based_release_metadata(
    now: OffsetDateTime,
    version: &str,
    manifest_name: impl Into<String>,
) -> ReleaseMetadata {
    ReleaseMetadata {
        title: format!(
            "v{version} ({date})",
            version = version,
            date = date_title(&now)
        ),
        tag: format!("v{version}", version = version),
        manifest_name: manifest_name.into(),
    }
}

fn date_title(now: &OffsetDateTime) -> String {
    format!(
        "{month} {day}, {year}",
@@ -172,28 +137,6 @@ fn date_title(now: &OffsetDateTime) -> String {
    )
}

// TODO(https://github.com/awslabs/smithy-rs/issues/1531): Remove this function
/// Discover the new version for the changelog from gradle.properties and the date.
fn auto_changelog_meta(smithy_rs: &dyn Git) -> Result<ChangelogMeta> {
    let gradle_props = fs::read_to_string(smithy_rs.path().join("gradle.properties"))
        .context("failed to load gradle.properties")?;
    let load_gradle_prop = |key: &str| {
        let prop = gradle_props
            .lines()
            .flat_map(|line| line.trim().strip_prefix(key))
            .flat_map(|prop| prop.strip_prefix('='))
            .next();
        prop.map(|prop| prop.to_string())
            .ok_or_else(|| anyhow::Error::msg(format!("missing expected gradle property: {key}")))
    };
    let smithy_version = load_gradle_prop("smithy.rs.runtime.crate.version")?;
    let sdk_version = load_gradle_prop("aws.sdk.version")?;
    Ok(ChangelogMeta {
        smithy_version,
        sdk_version,
    })
}

fn render_model_entry(entry: &SdkModelEntry, out: &mut String) {
    write!(
        out,
@@ -445,10 +388,7 @@ fn render(entries: &[ChangelogEntry], release_header: &str) -> (String, String)

#[cfg(test)]
mod test {
    use super::{
        date_based_release_metadata, render, version_based_release_metadata, Changelog,
        ChangelogEntries, ChangelogEntry,
    };
    use super::{date_based_release_metadata, render, Changelog, ChangelogEntries, ChangelogEntry};
    use smithy_rs_tool_common::changelog::SdkAffected;
    use time::OffsetDateTime;

@@ -582,15 +522,6 @@ Thank you for your contributions! ❤
        assert_eq!("some-manifest.json", result.manifest_name);
    }

    #[test]
    fn test_version_based_release_metadata() {
        let now = OffsetDateTime::from_unix_timestamp(100_000_000).unwrap();
        let result = version_based_release_metadata(now, "0.11.0", "some-other-manifest.json");
        assert_eq!("v0.11.0 (March 3rd, 1973)", result.title);
        assert_eq!("v0.11.0", result.tag);
        assert_eq!("some-other-manifest.json", result.manifest_name);
    }

    #[test]
    fn test_partition_client_server() {
        let sample = r#"
+14 −14
Original line number Diff line number Diff line
@@ -210,7 +210,7 @@ fn render_smithy_rs_test() {

    subcommand_render(&RenderArgs {
        change_set: ChangeSet::SmithyRs,
        independent_versioning: false,
        independent_versioning: true,
        source: vec![source_path.clone()],
        source_to_truncate: source_path.clone(),
        changelog_output: dest_path.clone(),
@@ -228,8 +228,8 @@ fn render_smithy_rs_test() {
    pretty_assertions::assert_str_eq!(EXAMPLE_ENTRY.trim(), source);
    pretty_assertions::assert_str_eq!(
        r#"<!-- Do not manually edit this file. Use the `changelogger` tool. -->
v0.42.0 (January 1st, 1970)
===========================
January 1st, 1970
=================
**New this release:**
- (all, [smithy-rs#1234](https://github.com/awslabs/smithy-rs/issues/1234), @another-dev) Another change

@@ -246,8 +246,8 @@ Old entry contents
    );
    pretty_assertions::assert_str_eq!(
        r#"{
  "tagName": "v0.42.0",
  "name": "v0.42.0 (January 1st, 1970)",
  "tagName": "release-1970-01-01",
  "name": "January 1st, 1970",
  "body": "**New this release:**\n- (all, [smithy-rs#1234](https://github.com/awslabs/smithy-rs/issues/1234), @another-dev) Another change\n\n**Contributors**\nThank you for your contributions! ❤\n- @another-dev ([smithy-rs#1234](https://github.com/awslabs/smithy-rs/issues/1234))\n",
  "prerelease": true
}"#,
@@ -296,7 +296,7 @@ fn render_aws_sdk_test() {

    subcommand_render(&RenderArgs {
        change_set: ChangeSet::AwsSdk,
        independent_versioning: false,
        independent_versioning: true,
        source: vec![source1_path.clone(), source2_path.clone()],
        source_to_truncate: source1_path.clone(),
        changelog_output: dest_path.clone(),
@@ -319,8 +319,8 @@ fn render_aws_sdk_test() {
    // the other should be filtered out by the `since_commit` attribute
    pretty_assertions::assert_str_eq!(
        r#"<!-- Do not manually edit this file. Use the `changelogger` tool. -->
v0.12.0 (January 1st, 1970)
===========================
January 1st, 1970
=================
**New this release:**
- 🐛 ([aws-sdk-rust#234](https://github.com/awslabs/aws-sdk-rust/issues/234), [smithy-rs#567](https://github.com/awslabs/smithy-rs/issues/567), @test-dev) Some other change

@@ -340,8 +340,8 @@ Old entry contents
    );
    pretty_assertions::assert_str_eq!(
        r#"{
  "tagName": "v0.12.0",
  "name": "v0.12.0 (January 1st, 1970)",
  "tagName": "release-1970-01-01",
  "name": "January 1st, 1970",
  "body": "**New this release:**\n- 🐛 ([aws-sdk-rust#234](https://github.com/awslabs/aws-sdk-rust/issues/234), [smithy-rs#567](https://github.com/awslabs/smithy-rs/issues/567), @test-dev) Some other change\n\n**Service Features:**\n- `aws-sdk-ec2` (0.12.0): Some API change\n\n**Contributors**\nThank you for your contributions! ❤\n- @test-dev ([aws-sdk-rust#234](https://github.com/awslabs/aws-sdk-rust/issues/234), [smithy-rs#567](https://github.com/awslabs/smithy-rs/issues/567))\n",
  "prerelease": true
}"#,
@@ -417,7 +417,7 @@ author = "rcoh"

    subcommand_render(&RenderArgs {
        change_set: ChangeSet::SmithyRs,
        independent_versioning: false,
        independent_versioning: true,
        source: vec![source_path.clone()],
        source_to_truncate: source_path.clone(),
        changelog_output: dest_path.clone(),
@@ -435,8 +435,8 @@ author = "rcoh"
    pretty_assertions::assert_str_eq!(EXAMPLE_ENTRY.trim(), source);
    pretty_assertions::assert_str_eq!(
        r#"<!-- Do not manually edit this file. Use the `changelogger` tool. -->
v0.42.0 (January 1st, 1970)
===========================
January 1st, 1970
=================
**Breaking Changes:**
- ⚠ (all, [smithy-rs#3](https://github.com/awslabs/smithy-rs/issues/3)) Third change - empty

@@ -526,7 +526,7 @@ author = "rcoh"

    let result = subcommand_render(&RenderArgs {
        change_set: ChangeSet::SmithyRs,
        independent_versioning: false,
        independent_versioning: true,
        source: vec![source_path.clone()],
        source_to_truncate: source_path.clone(),
        changelog_output: dest_path.clone(),
+8 −45
Original line number Diff line number Diff line
@@ -10,33 +10,13 @@ use publisher::subcommand::fix_manifests::FixManifestsArgs;
use publisher::subcommand::generate_version_manifest::{
    subcommand_generate_version_manifest, GenerateVersionManifestArgs,
};
use publisher::subcommand::hydrate_readme::subcommand_hydrate_readme_v1;
use publisher::subcommand::hydrate_readme::{
    subcommand_hydrate_readme, HydrateReadmeArgs, HydrateReadmeArgsV1,
};
use publisher::subcommand::hydrate_readme::{subcommand_hydrate_readme, HydrateReadmeArgs};
use publisher::subcommand::publish::subcommand_publish;
use publisher::subcommand::publish::PublishArgs;
use publisher::subcommand::tag_versions_manifest::subcommand_tag_versions_manifest;
use publisher::subcommand::tag_versions_manifest::TagVersionsManifestArgs;
use publisher::subcommand::yank_release::{subcommand_yank_release, YankReleaseArgs};

// TODO(https://github.com/awslabs/smithy-rs/issues/1531): Remove V1 args
#[derive(Parser, Debug)]
#[clap(author, version, about)]
enum ArgsV1 {
    /// Fixes path dependencies in manifests to also have version numbers
    FixManifests(FixManifestsArgs),
    /// Publishes crates to crates.io
    Publish(PublishArgs),
    /// Yanks an entire SDK release. For individual packages, use `cargo yank` instead.
    /// Only one of the `--github-release-tag` or `--versions-toml` options are required.
    YankRelease(YankReleaseArgs),
    /// Hydrates the SDK README template file
    HydrateReadme(HydrateReadmeArgsV1),
    /// Generates a version manifest file for a generated SDK
    GenerateVersionManifest(GenerateVersionManifestArgs),
}

#[derive(Parser, Debug)]
#[clap(author, version, about)]
enum Args {
@@ -63,31 +43,14 @@ async fn main() -> Result<()> {
        )
        .init();

    if let Ok(args) = Args::try_parse() {
        match args {
    match Args::parse() {
        Args::Publish(args) => subcommand_publish(&args).await?,
        Args::FixManifests(args) => subcommand_fix_manifests(&args).await?,
        Args::YankRelease(args) => subcommand_yank_release(&args).await?,
        Args::HydrateReadme(args) => subcommand_hydrate_readme(&args)?,
            Args::GenerateVersionManifest(args) => {
                subcommand_generate_version_manifest(&args).await?
            }
        Args::GenerateVersionManifest(args) => subcommand_generate_version_manifest(&args).await?,
        Args::TagVersionsManifest(args) => subcommand_tag_versions_manifest(&args)?,
    }
    } else {
        // TODO(https://github.com/awslabs/smithy-rs/issues/1531): Remove V1 args
        eprintln!("Failed to match new arg format. Trying to parse the old arg format.");
        let working_dir = std::env::current_dir()?;
        match ArgsV1::parse() {
            ArgsV1::Publish(args) => subcommand_publish(&args).await?,
            ArgsV1::FixManifests(args) => subcommand_fix_manifests(&args).await?,
            ArgsV1::YankRelease(args) => subcommand_yank_release(&args).await?,
            ArgsV1::HydrateReadme(args) => subcommand_hydrate_readme_v1(&args, &working_dir)?,
            ArgsV1::GenerateVersionManifest(args) => {
                subcommand_generate_version_manifest(&args).await?
            }
        }
    }

    Ok(())
}
+0 −4
Original line number Diff line number Diff line
@@ -29,10 +29,6 @@ pub struct GenerateVersionManifestArgs {
    /// Path containing the generated SDK to generate a version manifest for
    #[clap(long)]
    location: PathBuf,
    // TODO(https://github.com/awslabs/smithy-rs/issues/1531): Remove the unused `--release-tag` arg
    /// Unused.
    #[clap(long)]
    release_tag: Option<String>,
    /// Optional path to the `versions.toml` manifest from the previous SDK release
    #[clap(long)]
    previous_release_versions: Option<PathBuf>,
+1 −45
Original line number Diff line number Diff line
@@ -3,31 +3,14 @@
 * SPDX-License-Identifier: Apache-2.0
 */

use crate::SMITHYRS_REPO_NAME;
use anyhow::{Context, Result};
use clap::Parser;
use handlebars::Handlebars;
use semver::Version;
use serde::Serialize;
use serde_json::json;
use smithy_rs_tool_common::git;
use smithy_rs_tool_common::versions_manifest::VersionsManifest;
use std::fs;
use std::path::{Path, PathBuf};

// TODO(https://github.com/awslabs/smithy-rs/issues/1531): Remove V1 args
#[derive(Parser, Debug)]
pub struct HydrateReadmeArgsV1 {
    /// AWS Rust SDK version to put in the README
    #[clap(long)]
    pub sdk_version: Version,
    /// Rust MSRV to put in the README
    #[clap(long)]
    pub msrv: String,
    /// Path to output the hydrated readme into
    #[clap(short, long)]
    pub output: PathBuf,
}
use std::path::PathBuf;

#[derive(Parser, Debug)]
pub struct HydrateReadmeArgs {
@@ -45,33 +28,6 @@ pub struct HydrateReadmeArgs {
    pub output: PathBuf,
}

// TODO(https://github.com/awslabs/smithy-rs/issues/1531): Remove V1 implementation
pub fn subcommand_hydrate_readme_v1(
    HydrateReadmeArgsV1 {
        sdk_version,
        msrv,
        output,
    }: &HydrateReadmeArgsV1,
    working_dir: &Path,
) -> Result<()> {
    let repo_root = git::find_git_repository_root(SMITHYRS_REPO_NAME, working_dir)?;
    let template_path = repo_root.join("aws/SDK_README.md.hb");
    let template_contents = fs::read(&template_path)
        .with_context(|| format!("Failed to read README template file at {:?}", template_path))?;
    let template_string =
        String::from_utf8(template_contents).context("README template file was invalid UTF-8")?;

    let template_context = &json!({
        "sdk_version": format!("{}", sdk_version),
        "msrv": msrv
    });

    let hydrated = hydrate_template(&template_string, &template_context)?;
    fs::write(output, hydrated.as_bytes())
        .with_context(|| format!("Failed to write hydrated README to {:?}", output))?;
    Ok(())
}

pub fn subcommand_hydrate_readme(
    HydrateReadmeArgs {
        versions_manifest,
Loading