Skip to content

Commit 167e3b5

Browse files
authored
Add suffix support to release tags in tooling (#3261)
This will fix the yank tool and canary in the event there are multiple SDK releases in a day. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
1 parent cb227b5 commit 167e3b5

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::str::FromStr;
1313

1414
lazy_static! {
1515
static ref VERSION_TAG: Regex = Regex::new(r"^v(\d+)\.(\d+)\.(\d+)$").unwrap();
16-
static ref DATE_TAG: Regex = Regex::new(r"^release-(\d{4}-\d{2}-\d{2})$").unwrap();
16+
static ref DATE_TAG: Regex = Regex::new(r"^release-(\d{4}-\d{2}-\d{2})(.(\d+))?$").unwrap();
1717
}
1818

1919
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -25,6 +25,7 @@ pub struct VersionReleaseTag {
2525
#[derive(Clone, Debug, Eq, PartialEq)]
2626
pub struct DateReleaseTag {
2727
date: String,
28+
suffix: Option<usize>,
2829
original: String,
2930
}
3031

@@ -66,6 +67,7 @@ impl FromStr for ReleaseTag {
6667
} else if let Some(caps) = DATE_TAG.captures(value) {
6768
Ok(ReleaseTag::Date(DateReleaseTag {
6869
date: caps.get(1).expect("validated by regex").as_str().into(),
70+
suffix: caps.get(3).map(|s| usize::from_str(s.as_str()).unwrap()),
6971
original: value.into(),
7072
}))
7173
} else {
@@ -95,7 +97,9 @@ impl PartialOrd for ReleaseTag {
9597
match (self, other) {
9698
(ReleaseTag::Date(_), ReleaseTag::Version(_)) => Some(Ordering::Greater),
9799
(ReleaseTag::Version(_), ReleaseTag::Date(_)) => Some(Ordering::Less),
98-
(ReleaseTag::Date(lhs), ReleaseTag::Date(rhs)) => Some(lhs.date.cmp(&rhs.date)),
100+
(ReleaseTag::Date(lhs), ReleaseTag::Date(rhs)) => {
101+
Some(lhs.date.cmp(&rhs.date).then(lhs.suffix.cmp(&rhs.suffix)))
102+
}
99103
(ReleaseTag::Version(lhs), ReleaseTag::Version(rhs)) => {
100104
Some(lhs.version.cmp(&rhs.version))
101105
}
@@ -125,10 +129,20 @@ mod tests {
125129
ReleaseTag::Date(DateReleaseTag {
126130
date: "2022-07-26".into(),
127131
original: "release-2022-07-26".into(),
132+
suffix: None
128133
}),
129134
tag("release-2022-07-26")
130135
);
131136

137+
assert_eq!(
138+
ReleaseTag::Date(DateReleaseTag {
139+
date: "2022-07-26".into(),
140+
original: "release-2022-07-26.2".into(),
141+
suffix: Some(2)
142+
}),
143+
tag("release-2022-07-26.2")
144+
);
145+
132146
assert!(ReleaseTag::from_str("foo").is_err());
133147
}
134148

@@ -140,6 +154,10 @@ mod tests {
140154
assert!(tag("release-2022-07-20") < tag("release-2022-07-26"));
141155
assert!(tag("release-2022-06-20") < tag("release-2022-07-01"));
142156
assert!(tag("release-2021-06-20") < tag("release-2022-06-20"));
157+
assert!(tag("release-2022-06-20") < tag("release-2022-06-20.2"));
158+
assert!(tag("release-2022-06-20.2") < tag("release-2022-06-20.3"));
159+
assert!(tag("release-2022-06-20.1") < tag("release-2022-06-20.10"));
160+
assert!(tag("release-2022-06-20.10") < tag("release-2022-06-20.11"));
143161
}
144162

145163
#[test]
@@ -149,5 +167,9 @@ mod tests {
149167
"release-2022-07-26",
150168
format!("{}", tag("release-2022-07-26"))
151169
);
170+
assert_eq!(
171+
"release-2022-07-26.2",
172+
format!("{}", tag("release-2022-07-26.2"))
173+
);
152174
}
153175
}

0 commit comments

Comments
 (0)