Skip to content

Commit 4b9c9b7

Browse files
merge release branch back into main (#3490)
2 parents 2392a24 + b43c7ad commit 4b9c9b7

File tree

3 files changed

+82
-11
lines changed

3 files changed

+82
-11
lines changed

tools/ci-build/publisher/src/subcommand/publish.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,12 @@ pub fn resolve_publish_location(location: &Path) -> PathBuf {
109109
}
110110

111111
async fn is_published(index: Arc<CratesIndex>, handle: &PackageHandle) -> Result<bool> {
112-
let crate_name = handle.name.clone();
113-
let versions =
114-
tokio::task::spawn_blocking(move || index.published_versions(&crate_name)).await??;
115-
Ok(!versions.is_empty())
112+
let name = handle.name.clone();
113+
let version = handle.version.clone();
114+
tokio::task::spawn_blocking(move || {
115+
smithy_rs_tool_common::index::is_published(index.as_ref(), &name, &version)
116+
})
117+
.await?
116118
}
117119

118120
/// Waits for the given package to show up on crates.io

tools/ci-build/runtime-versioner/src/command/audit.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,23 @@ impl RuntimeCrate {
114114
/// True if this runtime crate changed since the given release tag.
115115
fn changed_since_release(&self, repo: &Repo, release_tag: &ReleaseTag) -> Result<bool> {
116116
let status = repo
117-
.git(["diff", "--quiet", release_tag.as_str(), self.path.as_str()])
118-
.status()
117+
.git([
118+
"diff",
119+
"--name-only",
120+
release_tag.as_str(),
121+
self.path.as_str(),
122+
])
123+
.output()
119124
.with_context(|| format!("failed to git diff {}", self.name))?;
120-
match status.code() {
121-
Some(0) => Ok(false),
122-
Some(1) => Ok(true),
123-
code => bail!("unknown git diff result: {code:?}"),
124-
}
125+
let output = String::from_utf8(status.stdout)?;
126+
let changed_files = output
127+
.lines()
128+
// When run during a release, this file is replaced with it's actual contents.
129+
// This breaks this git-based comparison and incorrectly requires a version bump.
130+
// Temporary fix to allow the build to succeed.
131+
.filter(|line| !line.contains("aws-config/clippy.toml"))
132+
.collect::<Vec<_>>();
133+
Ok(!changed_files.is_empty())
125134
}
126135
}
127136

tools/ci-build/smithy-rs-tool-common/src/index.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::retry::{run_with_retry_sync, ErrorClass};
77
use anyhow::{anyhow, Context, Error, Result};
88
use crates_index::Crate;
99
use reqwest::StatusCode;
10+
use semver::Version;
1011
use std::{collections::HashMap, time::Duration};
1112
use std::{fs, path::Path};
1213

@@ -31,6 +32,11 @@ impl CratesIndex {
3132
Self(Inner::Fake(FakeIndex::from_file(path)))
3233
}
3334

35+
/// Returns a fake crates.io index from a hashmap
36+
pub fn fake_from_map(versions: HashMap<String, Vec<String>>) -> Self {
37+
Self(Inner::Fake(FakeIndex { crates: versions }))
38+
}
39+
3440
/// Retrieves the published versions for the given crate name.
3541
pub fn published_versions(&self, crate_name: &str) -> Result<Vec<String>> {
3642
match &self.0 {
@@ -46,6 +52,12 @@ impl CratesIndex {
4652
}
4753
}
4854

55+
pub fn is_published(index: &CratesIndex, crate_name: &str, version: &Version) -> Result<bool> {
56+
let crate_name = crate_name.to_string();
57+
let versions = index.published_versions(&crate_name)?;
58+
Ok(versions.contains(&version.to_string()))
59+
}
60+
4961
fn published_versions(index: &crates_index::SparseIndex, crate_name: &str) -> Result<Vec<String>> {
5062
let url = index
5163
.crate_url(crate_name)
@@ -106,3 +118,51 @@ impl FakeIndex {
106118
FakeIndex { crates }
107119
}
108120
}
121+
122+
#[cfg(test)]
123+
mod test {
124+
use crate::index::{is_published, CratesIndex};
125+
use semver::Version;
126+
use std::collections::HashMap;
127+
use std::sync::Arc;
128+
129+
/// Ignored test against the real index
130+
#[ignore]
131+
#[test]
132+
fn test_known_published_versions() {
133+
let index = Arc::new(CratesIndex::real().unwrap());
134+
let known_published = Version::new(1, 1, 7);
135+
let known_never_published = Version::new(999, 999, 999);
136+
assert_eq!(
137+
is_published(&index, "aws-smithy-runtime-api", &known_published).unwrap(),
138+
true
139+
);
140+
141+
assert_eq!(
142+
is_published(&index, "aws-smithy-runtime-api", &known_never_published).unwrap(),
143+
false
144+
);
145+
}
146+
147+
/// Ignored test against the real index
148+
#[test]
149+
fn test_against_fake_index() {
150+
let mut crates = HashMap::new();
151+
crates.insert(
152+
"aws-smithy-runtime-api".to_string(),
153+
vec!["1.1.7".to_string()],
154+
);
155+
let index = Arc::new(CratesIndex::fake_from_map(crates));
156+
let known_published = Version::new(1, 1, 7);
157+
let known_never_published = Version::new(999, 999, 999);
158+
assert_eq!(
159+
is_published(&index, "aws-smithy-runtime-api", &known_published).unwrap(),
160+
true
161+
);
162+
163+
assert_eq!(
164+
is_published(&index, "aws-smithy-runtime-api", &known_never_published).unwrap(),
165+
false
166+
);
167+
}
168+
}

0 commit comments

Comments
 (0)