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

Implement release-aware yank tooling (#1407)

parent 16fda3a8
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -979,7 +979,7 @@ dependencies = [

[[package]]
name = "publisher"
version = "0.3.0"
version = "0.4.0"
dependencies = [
 "anyhow",
 "async-recursion",
@@ -992,6 +992,7 @@ dependencies = [
 "lazy_static",
 "num_cpus",
 "regex",
 "reqwest",
 "semver",
 "serde",
 "serde_json",
+2 −1
Original line number Diff line number Diff line
[package]
name = "publisher"
version = "0.3.0"
version = "0.4.0"
authors = ["AWS Rust SDK Team <aws-sdk-rust@amazon.com>"]
description = "Tool used to publish the AWS SDK to crates.io"
edition = "2021"
@@ -25,6 +25,7 @@ handlebars = "4.2"
lazy_static = "1"
num_cpus = "1.13"
regex = "1.5.4"
reqwest = "0.11.10"
semver = "1.0"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
+15 −26
Original line number Diff line number Diff line
@@ -3,26 +3,24 @@
 * SPDX-License-Identifier: Apache-2.0
 */

use crate::package::PackageHandle;
use anyhow::Result;
use smithy_rs_tool_common::shell::{capture_error, output_text, ShellOperation};
use std::path::PathBuf;
use std::process::Command;
use tracing::info;

/// Yanks a package version from crates.io
pub struct Yank {
    program: &'static str,
    package_handle: PackageHandle,
    package_path: PathBuf,
    crate_name: String,
    crate_version: String,
}

impl Yank {
    pub fn new(package_handle: PackageHandle, package_path: impl Into<PathBuf>) -> Yank {
    pub fn new(crate_name: impl Into<String>, crate_version: impl Into<String>) -> Yank {
        Yank {
            program: "cargo",
            package_handle,
            package_path: package_path.into(),
            crate_name: crate_name.into(),
            crate_version: crate_version.into(),
        }
    }
}
@@ -33,22 +31,21 @@ impl ShellOperation for Yank {
    fn run(&self) -> Result<()> {
        let mut command = Command::new(self.program);
        command
            .current_dir(&self.package_path)
            .arg("yank")
            .arg("--vers")
            .arg(format!("{}", self.package_handle.version))
            .arg(&self.package_handle.name);
            .arg(&self.crate_version)
            .arg(&self.crate_name);
        let output = command.output()?;
        if !output.status.success() {
            let (_, stderr) = output_text(&output);
            let no_such_version = format!(
                "error: crate `{}` does not have a version `{}`",
                self.package_handle.name, self.package_handle.version
                self.crate_name, self.crate_version
            );
            if stderr.contains(&no_such_version) {
                info!(
                    "{} never had a version {}.",
                    self.package_handle.name, self.package_handle.version
                    self.crate_name, self.crate_version
                );
            } else {
                return Err(capture_error("cargo yank", &output));
@@ -61,18 +58,13 @@ impl ShellOperation for Yank {
#[cfg(all(test, not(target_os = "windows")))]
mod tests {
    use super::*;
    use semver::Version;
    use std::env;

    #[tokio::test]
    async fn yank_succeeds() {
        Yank {
            program: "./fake_cargo/cargo_success",
            package_handle: PackageHandle::new(
                "aws-sdk-dynamodb",
                Version::parse("0.0.22-alpha").unwrap(),
            ),
            package_path: env::current_dir().unwrap().into(),
            crate_name: "aws-sdk-dynamodb".into(),
            crate_version: "0.0.22-alpha".into(),
        }
        .spawn()
        .await
@@ -83,11 +75,8 @@ mod tests {
    async fn yank_fails() {
        let result = Yank {
            program: "./fake_cargo/cargo_fails",
            package_handle: PackageHandle::new(
                "something",
                Version::parse("0.0.22-alpha").unwrap(),
            ),
            package_path: env::current_dir().unwrap().into(),
            crate_name: "something".into(),
            crate_version: "0.0.22-alpha".into(),
        }
        .spawn()
        .await;
@@ -105,8 +94,8 @@ mod tests {
    async fn yank_no_such_version() {
        Yank {
            program: "./fake_cargo/cargo_yank_not_found",
            package_handle: PackageHandle::new("aws-sigv4", Version::parse("0.0.0").unwrap()),
            package_path: env::current_dir().unwrap().into(),
            crate_name: "aws-sigv4".into(),
            crate_version: "0.0.0".into(),
        }
        .spawn()
        .await
+5 −5
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@

use crate::subcommand::fix_manifests::subcommand_fix_manifests;
use crate::subcommand::publish::subcommand_publish;
use crate::subcommand::yank_category::subcommand_yank_category;
use crate::subcommand::yank_release::{subcommand_yank_release, YankReleaseArgs};
use anyhow::Result;
use clap::Parser;
use subcommand::fix_manifests::FixManifestsArgs;
@@ -14,7 +14,6 @@ use subcommand::generate_version_manifest::{
};
use subcommand::hydrate_readme::{subcommand_hydrate_readme, HydrateReadmeArgs};
use subcommand::publish::PublishArgs;
use subcommand::yank_category::YankCategoryArgs;

mod cargo;
mod fs;
@@ -36,8 +35,9 @@ enum Args {
    FixManifests(FixManifestsArgs),
    /// Publishes crates to crates.io
    Publish(PublishArgs),
    /// Yanks a category of packages with the given version number
    YankCategory(YankCategoryArgs),
    /// 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(HydrateReadmeArgs),
    /// Generates a version manifest file for a generated SDK
@@ -55,7 +55,7 @@ async fn main() -> Result<()> {
    match Args::parse() {
        Args::Publish(args) => subcommand_publish(&args).await?,
        Args::FixManifests(args) => subcommand_fix_manifests(&args).await?,
        Args::YankCategory(args) => subcommand_yank_category(&args).await?,
        Args::YankRelease(args) => subcommand_yank_release(&args).await?,
        Args::HydrateReadme(args) => subcommand_hydrate_readme(&args).await?,
        Args::GenerateVersionManifest(args) => subcommand_generate_version_manifest(&args).await?,
    }
+1 −1
Original line number Diff line number Diff line
@@ -7,4 +7,4 @@ pub mod fix_manifests;
pub mod generate_version_manifest;
pub mod hydrate_readme;
pub mod publish;
pub mod yank_category;
pub mod yank_release;
Loading