From 987024bfef597ed875809876f35dbf06c9d82e4c Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Tue, 12 Mar 2024 16:28:34 -0400 Subject: [PATCH 1/2] Fix publisher check of published versions (#3483) ## Motivation and Context Switch to the sparse index broke the publishers check if whether or not a version was already published. ## Description Fix check, add tests. ## Testing - Ran test against the real sparse index. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --- .../publisher/src/subcommand/publish.rs | 10 ++-- .../smithy-rs-tool-common/src/index.rs | 60 +++++++++++++++++++ 2 files changed, 66 insertions(+), 4 deletions(-) diff --git a/tools/ci-build/publisher/src/subcommand/publish.rs b/tools/ci-build/publisher/src/subcommand/publish.rs index fa3ada1aac..d724557f9b 100644 --- a/tools/ci-build/publisher/src/subcommand/publish.rs +++ b/tools/ci-build/publisher/src/subcommand/publish.rs @@ -109,10 +109,12 @@ pub fn resolve_publish_location(location: &Path) -> PathBuf { } async fn is_published(index: Arc, handle: &PackageHandle) -> Result { - let crate_name = handle.name.clone(); - let versions = - tokio::task::spawn_blocking(move || index.published_versions(&crate_name)).await??; - Ok(!versions.is_empty()) + let name = handle.name.clone(); + let version = handle.version.clone(); + tokio::task::spawn_blocking(move || { + smithy_rs_tool_common::index::is_published(index.as_ref(), &name, &version) + }) + .await? } /// Waits for the given package to show up on crates.io diff --git a/tools/ci-build/smithy-rs-tool-common/src/index.rs b/tools/ci-build/smithy-rs-tool-common/src/index.rs index 7785229094..532ab0f07d 100644 --- a/tools/ci-build/smithy-rs-tool-common/src/index.rs +++ b/tools/ci-build/smithy-rs-tool-common/src/index.rs @@ -7,6 +7,7 @@ use crate::retry::{run_with_retry_sync, ErrorClass}; use anyhow::{anyhow, Context, Error, Result}; use crates_index::Crate; use reqwest::StatusCode; +use semver::Version; use std::{collections::HashMap, time::Duration}; use std::{fs, path::Path}; @@ -31,6 +32,11 @@ impl CratesIndex { Self(Inner::Fake(FakeIndex::from_file(path))) } + /// Returns a fake crates.io index from a hashmap + pub fn fake_from_map(versions: HashMap>) -> Self { + Self(Inner::Fake(FakeIndex { crates: versions })) + } + /// Retrieves the published versions for the given crate name. pub fn published_versions(&self, crate_name: &str) -> Result> { match &self.0 { @@ -46,6 +52,12 @@ impl CratesIndex { } } +pub fn is_published(index: &CratesIndex, crate_name: &str, version: &Version) -> Result { + let crate_name = crate_name.to_string(); + let versions = index.published_versions(&crate_name)?; + Ok(versions.contains(&version.to_string())) +} + fn published_versions(index: &crates_index::SparseIndex, crate_name: &str) -> Result> { let url = index .crate_url(crate_name) @@ -106,3 +118,51 @@ impl FakeIndex { FakeIndex { crates } } } + +#[cfg(test)] +mod test { + use crate::index::{is_published, CratesIndex}; + use semver::Version; + use std::collections::HashMap; + use std::sync::Arc; + + /// Ignored test against the real index + #[ignore] + #[test] + fn test_known_published_versions() { + let index = Arc::new(CratesIndex::real().unwrap()); + let known_published = Version::new(1, 1, 7); + let known_never_published = Version::new(999, 999, 999); + assert_eq!( + is_published(&index, "aws-smithy-runtime-api", &known_published).unwrap(), + true + ); + + assert_eq!( + is_published(&index, "aws-smithy-runtime-api", &known_never_published).unwrap(), + false + ); + } + + /// Ignored test against the real index + #[test] + fn test_against_fake_index() { + let mut crates = HashMap::new(); + crates.insert( + "aws-smithy-runtime-api".to_string(), + vec!["1.1.7".to_string()], + ); + let index = Arc::new(CratesIndex::fake_from_map(crates)); + let known_published = Version::new(1, 1, 7); + let known_never_published = Version::new(999, 999, 999); + assert_eq!( + is_published(&index, "aws-smithy-runtime-api", &known_published).unwrap(), + true + ); + + assert_eq!( + is_published(&index, "aws-smithy-runtime-api", &known_never_published).unwrap(), + false + ); + } +} From b43c7ad2e7733f0e1d62b8c959ac7ff47045804d Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Wed, 13 Mar 2024 21:36:25 -0400 Subject: [PATCH 2/2] Ignore aws-config/clippy.toml (#3489) ## Motivation and Context Fix CI breakage during release. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --- .../runtime-versioner/src/command/audit.rs | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tools/ci-build/runtime-versioner/src/command/audit.rs b/tools/ci-build/runtime-versioner/src/command/audit.rs index 1071ff3414..b27d648208 100644 --- a/tools/ci-build/runtime-versioner/src/command/audit.rs +++ b/tools/ci-build/runtime-versioner/src/command/audit.rs @@ -114,14 +114,23 @@ impl RuntimeCrate { /// True if this runtime crate changed since the given release tag. fn changed_since_release(&self, repo: &Repo, release_tag: &ReleaseTag) -> Result { let status = repo - .git(["diff", "--quiet", release_tag.as_str(), self.path.as_str()]) - .status() + .git([ + "diff", + "--name-only", + release_tag.as_str(), + self.path.as_str(), + ]) + .output() .with_context(|| format!("failed to git diff {}", self.name))?; - match status.code() { - Some(0) => Ok(false), - Some(1) => Ok(true), - code => bail!("unknown git diff result: {code:?}"), - } + let output = String::from_utf8(status.stdout)?; + let changed_files = output + .lines() + // When run during a release, this file is replaced with it's actual contents. + // This breaks this git-based comparison and incorrectly requires a version bump. + // Temporary fix to allow the build to succeed. + .filter(|line| !line.contains("aws-config/clippy.toml")) + .collect::>(); + Ok(!changed_files.is_empty()) } }