Skip to content

Commit

Permalink
merge release branch back into main (smithy-lang#3490)
Browse files Browse the repository at this point in the history
  • Loading branch information
aws-sdk-rust-ci authored Mar 14, 2024
2 parents 2392a24 + b43c7ad commit 4b9c9b7
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 11 deletions.
10 changes: 6 additions & 4 deletions tools/ci-build/publisher/src/subcommand/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,12 @@ pub fn resolve_publish_location(location: &Path) -> PathBuf {
}

async fn is_published(index: Arc<CratesIndex>, handle: &PackageHandle) -> Result<bool> {
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
Expand Down
23 changes: 16 additions & 7 deletions tools/ci-build/runtime-versioner/src/command/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> {
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::<Vec<_>>();
Ok(!changed_files.is_empty())
}
}

Expand Down
60 changes: 60 additions & 0 deletions tools/ci-build/smithy-rs-tool-common/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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<String, Vec<String>>) -> 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<Vec<String>> {
match &self.0 {
Expand All @@ -46,6 +52,12 @@ impl CratesIndex {
}
}

pub fn is_published(index: &CratesIndex, crate_name: &str, version: &Version) -> Result<bool> {
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<Vec<String>> {
let url = index
.crate_url(crate_name)
Expand Down Expand Up @@ -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
);
}
}

0 comments on commit 4b9c9b7

Please sign in to comment.