New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change manifest locations, repos and branches based on major version #6012
Merged
jhugman
merged 2 commits into
main
from
jhugman/exp-4162-add-version-aware-manifest-locations-to-nimbus-cli
Dec 20, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
use anyhow::Result; | ||
|
||
pub(crate) fn is_before(current_version: &Option<String>, upto_version: usize) -> bool { | ||
if current_version.is_none() { | ||
false | ||
} else { | ||
let current_version = current_version.as_deref().unwrap(); | ||
is_between(0, current_version, upto_version).unwrap_or(false) | ||
} | ||
} | ||
|
||
fn is_between(min_version: usize, current_version: &str, max_version: usize) -> Result<bool> { | ||
let (major, _) = current_version | ||
.split_once('.') | ||
.unwrap_or((current_version, "")); | ||
let v = major.parse::<usize>()?; | ||
Ok(min_version <= v && v < max_version) | ||
} | ||
|
||
/// The following are dumb string manipulations to pad out a version number. | ||
/// We might use a version library if we need much more functionality, but right now | ||
/// it's isolated in a single file where it can be replaced as/when necessary. | ||
|
||
/// pad_major_minor_patch will zero pad the minor and patch versions if they are not present. | ||
/// 112.1.3 --> 112.1.3 | ||
/// 112.1 --> 112.1.0 | ||
/// 112 --> 112.0.0 | ||
pub(crate) fn pad_major_minor_patch(version: &str) -> String { | ||
match version_split(version) { | ||
(Some(_), Some(_), Some(_)) => version.to_owned(), | ||
(Some(major), Some(minor), None) => format!("{major}.{minor}.0"), | ||
(Some(major), None, None) => format!("{major}.0.0"), | ||
_ => format!("{version}.0.0"), | ||
} | ||
} | ||
|
||
/// pad_major_minor will zero pad the minor version if it is not present. | ||
/// If the patch version is present, then it is left intact. | ||
/// 112.1.3 --> 112.1.3 | ||
/// 112.1 --> 112.1 | ||
/// 112 --> 112.0 | ||
pub(crate) fn pad_major_minor(version: &str) -> String { | ||
match version_split(version) { | ||
(Some(_), Some(_), Some(_)) => version.to_owned(), | ||
(Some(major), Some(minor), None) => format!("{major}.{minor}"), | ||
(Some(major), None, None) => format!("{major}.0"), | ||
_ => format!("{version}.0"), | ||
} | ||
} | ||
|
||
/// pad_major will keep the string as it is. | ||
/// If the minor and/or patch versions are present, then they are left intact. | ||
/// 112.1.3 --> 112.1.3 | ||
/// 112.1 --> 112.1 | ||
/// 112 --> 112 | ||
pub(crate) fn pad_major(version: &str) -> String { | ||
version.to_owned() | ||
} | ||
|
||
fn version_split(version: &str) -> (Option<&str>, Option<&str>, Option<&str>) { | ||
let mut split = version.splitn(3, '.'); | ||
(split.next(), split.next(), split.next()) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should consider using a crate like semver long term.