Unverified Commit fd987561 authored by david-perez's avatar david-perez Committed by GitHub
Browse files

Add `awslabs/smithy-rs-server` as a crate owner in the `publisher` tool (#1619)

This commit adds the SDK and server groups to smithy-rs runtime crates,
but only the SDK group on `AwsRuntime` and `AwsSdk` crates.

With this change, the `publisher` tool won't fail when publishing the
`aws-smithy-http-server` crate.
parent 7b2aef71
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -7,14 +7,14 @@ pub const SDK_REPO_CRATE_PATH: &str = "sdk";
pub const SDK_REPO_NAME: &str = "aws-sdk-rust";
pub const SMITHYRS_REPO_NAME: &str = "smithy-rs";

// Crate ownership for SDK crates. Crates.io requires that at least one owner
// is an individual rather than a team, so we use the automation user for that.
pub const CRATE_OWNERS: &[&str] = &[
// https://github.com/orgs/awslabs/teams/smithy-rs-server
pub const SMITHY_RS_SERVER_OWNER: &str = "github:awslabs:smithy-rs-server";

// https://github.com/orgs/awslabs/teams/rust-sdk-owners
    "github:awslabs:rust-sdk-owners",
pub const RUST_SDK_OWNER: &str = "github:awslabs:rust-sdk-owners";

// https://github.com/aws-sdk-rust-ci
    "aws-sdk-rust-ci",
];
pub const RUST_SDK_CI_OWNER: &str = "aws-sdk-rust-ci";

pub mod cargo;
pub mod fs;
+70 −1
Original line number Diff line number Diff line
@@ -7,11 +7,12 @@

use crate::fs::Fs;
use crate::sort::dependency_order;
use crate::{RUST_SDK_CI_OWNER, RUST_SDK_OWNER, SMITHY_RS_SERVER_OWNER};
use anyhow::{Context, Result};
use cargo_toml::{Dependency, DepsSet, Manifest};
use semver::Version;
use smithy_rs_tool_common::package::PackageCategory;
use std::collections::{BTreeMap, BTreeSet};
use std::collections::{BTreeMap, BTreeSet, HashSet};
use std::error::Error as StdError;
use std::fmt;
use std::path::{Path, PathBuf};
@@ -86,6 +87,26 @@ impl Package {
    pub fn locally_depends_on(&self, other: &PackageHandle) -> bool {
        self.local_dependencies.contains(other)
    }

    /// Returns the expected owners of the crate.
    pub fn expected_owners(&self) -> HashSet<String> {
        let mut ret = HashSet::new();

        // Crate ownership for SDK crates. Crates.io requires that at least one owner
        // is an individual rather than a team, so we use the automation user for that.
        ret.insert(String::from(RUST_SDK_CI_OWNER));

        if self.category.is_sdk() {
            ret.insert(String::from(RUST_SDK_OWNER));
        } else if self.handle.name.starts_with("aws-smithy-http-server") {
            ret.insert(String::from(SMITHY_RS_SERVER_OWNER));
        } else {
            ret.insert(String::from(RUST_SDK_OWNER));
            ret.insert(String::from(SMITHY_RS_SERVER_OWNER));
        }

        ret
    }
}

/// Batch of packages.
@@ -503,4 +524,52 @@ mod tests {
            format!("{}", error)
        );
    }

    #[test]
    fn test_expected_package_owners_server_crate() {
        let server_packages = vec![
            package("aws-smithy-http-server", &[]),
            package("aws-smithy-http-server-python", &[]),
        ];
        for pkg in server_packages {
            assert_eq!(
                [
                    String::from("github:awslabs:smithy-rs-server"),
                    String::from("aws-sdk-rust-ci")
                ]
                .into_iter()
                .collect::<HashSet<String>>(),
                pkg.expected_owners()
            );
        }
    }

    #[test]
    fn test_expected_package_owners_sdk_crate() {
        let sdk_package = package("aws-types", &[]);
        assert_eq!(
            [
                String::from("github:awslabs:rust-sdk-owners"),
                String::from("aws-sdk-rust-ci")
            ]
            .into_iter()
            .collect::<HashSet<String>>(),
            sdk_package.expected_owners()
        );
    }

    #[test]
    fn test_expected_package_owners_smithy_runtime_crate() {
        let smithy_runtime_package = package("aws-smithy-types", &[]);
        assert_eq!(
            [
                String::from("github:awslabs:smithy-rs-server"),
                String::from("github:awslabs:rust-sdk-owners"),
                String::from("aws-sdk-rust-ci")
            ]
            .into_iter()
            .collect::<HashSet<String>>(),
            smithy_runtime_package.expected_owners()
        );
    }
}
+16 −15
Original line number Diff line number Diff line
@@ -8,8 +8,8 @@ use crate::package::{
    discover_and_validate_package_batches, Package, PackageBatch, PackageHandle, PackageStats,
};
use crate::retry::{run_with_retry, BoxError, ErrorClass};
use crate::SDK_REPO_CRATE_PATH;
use crate::{cargo, SDK_REPO_NAME};
use crate::{CRATE_OWNERS, SDK_REPO_CRATE_PATH};
use anyhow::{bail, Context, Result};
use clap::Parser;
use crates_io_api::{AsyncClient, Error};
@@ -17,6 +17,7 @@ use dialoguer::Confirm;
use lazy_static::lazy_static;
use smithy_rs_tool_common::git;
use smithy_rs_tool_common::shell::ShellOperation;
use std::collections::HashSet;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::Duration;
@@ -180,10 +181,14 @@ async fn correct_owner(package: &Package) -> Result<()> {
        3,
        Duration::from_secs(5),
        || async {
            let owners = cargo::GetOwners::new(&package.handle.name).spawn().await?;
            let actual_owners: HashSet<String> = cargo::GetOwners::new(&package.handle.name).spawn().await?.into_iter().collect();
            let expected_owners = package.expected_owners();

            let owners_to_be_added = expected_owners.difference(&actual_owners);
            let incorrect_owners = actual_owners.difference(&expected_owners);

            let mut added_individual = false;
            for &crate_owner in CRATE_OWNERS {
                if !owners.iter().any(|owner| owner == crate_owner) {
            for crate_owner in owners_to_be_added {
                cargo::AddOwner::new(&package.handle.name, crate_owner)
                    .spawn()
                    .await?;
@@ -191,10 +196,6 @@ async fn correct_owner(package: &Package) -> Result<()> {
                // Teams in crates.io start with `github:` while individuals are just the GitHub user name
                added_individual |= !crate_owner.starts_with("github:");
            }
            }
            let incorrect_owners = owners
                .iter()
                .filter(|&owner| !CRATE_OWNERS.iter().any(|o| o == owner));
            for incorrect_owner in incorrect_owners {
                // Adding an individual owner requires accepting an invite, so don't attempt to remove
                // anyone if an owner was added, as removing the last individual owner may break.
@@ -203,7 +204,7 @@ async fn correct_owner(package: &Package) -> Result<()> {
                    cargo::RemoveOwner::new(&package.handle.name, incorrect_owner)
                        .spawn()
                        .await
                        .context("remove incorrect owner")?;
                        .context(format!("remove incorrect owner `{}` from crate `{}`", incorrect_owner, package.handle))?;
                    info!(
                        "Removed incorrect owner `{}` from crate `{}`",
                        incorrect_owner, package.handle