make version.localchanges match API logic (#62)

This commit is contained in:
bmc-msft 2020-10-01 11:28:58 -04:00 committed by GitHub
parent eae0f42938
commit d2ee7e5e7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 18 deletions

View File

@ -22,7 +22,7 @@ fn read_file(filename: &str) -> Result<String, Box<dyn Error>> {
Ok(contents) Ok(contents)
} }
fn print_version(include_sha: bool) -> Result<(), Box<dyn Error>> { fn print_version(include_sha: bool, include_local: bool) -> Result<(), Box<dyn Error>> {
let mut version = read_file("../../../CURRENT_VERSION")?; let mut version = read_file("../../../CURRENT_VERSION")?;
let sha = run_cmd(&["git", "rev-parse", "HEAD"])?; let sha = run_cmd(&["git", "rev-parse", "HEAD"])?;
@ -32,7 +32,7 @@ fn print_version(include_sha: bool) -> Result<(), Box<dyn Error>> {
// if we're a non-release build, check to see if git has // if we're a non-release build, check to see if git has
// unstaged changes // unstaged changes
if run_cmd(&["git", "diff", "--quiet"]).is_err() { if include_local && run_cmd(&["git", "diff", "--quiet"]).is_err() {
version.push('.'); version.push('.');
version.push_str("localchanges"); version.push_str("localchanges");
} }
@ -47,10 +47,10 @@ fn print_version(include_sha: bool) -> Result<(), Box<dyn Error>> {
fn main() -> Result<(), Box<dyn Error>> { fn main() -> Result<(), Box<dyn Error>> {
// If we're built off of a tag, we accept CURRENT_VERSION as is. Otherwise // If we're built off of a tag, we accept CURRENT_VERSION as is. Otherwise
// modify it to indicate local build // modify it to indicate local build
let include_sha = if let Ok(val) = env::var("GITHUB_REF") { let (include_sha, include_local_changes) = if let Ok(val) = env::var("GITHUB_REF") {
!val.starts_with("refs/tags/") (!val.starts_with("refs/tags/"), false)
} else { } else {
true (true, true)
}; };
print_version(include_sha) print_version(include_sha, include_local_changes)
} }

View File

@ -22,7 +22,7 @@ fn read_file(filename: &str) -> Result<String, Box<dyn Error>> {
Ok(contents) Ok(contents)
} }
fn print_version(include_sha: bool) -> Result<(), Box<dyn Error>> { fn print_version(include_sha: bool, include_local: bool) -> Result<(), Box<dyn Error>> {
let mut version = read_file("../../../CURRENT_VERSION")?; let mut version = read_file("../../../CURRENT_VERSION")?;
let sha = run_cmd(&["git", "rev-parse", "HEAD"])?; let sha = run_cmd(&["git", "rev-parse", "HEAD"])?;
@ -32,7 +32,7 @@ fn print_version(include_sha: bool) -> Result<(), Box<dyn Error>> {
// if we're a non-release build, check to see if git has // if we're a non-release build, check to see if git has
// unstaged changes // unstaged changes
if run_cmd(&["git", "diff", "--quiet"]).is_err() { if include_local && run_cmd(&["git", "diff", "--quiet"]).is_err() {
version.push('.'); version.push('.');
version.push_str("localchanges"); version.push_str("localchanges");
} }
@ -47,10 +47,10 @@ fn print_version(include_sha: bool) -> Result<(), Box<dyn Error>> {
fn main() -> Result<(), Box<dyn Error>> { fn main() -> Result<(), Box<dyn Error>> {
// If we're built off of a tag, we accept CURRENT_VERSION as is. Otherwise // If we're built off of a tag, we accept CURRENT_VERSION as is. Otherwise
// modify it to indicate local build // modify it to indicate local build
let include_sha = if let Ok(val) = env::var("GITHUB_REF") { let (include_sha, include_local_changes) = if let Ok(val) = env::var("GITHUB_REF") {
!val.starts_with("refs/tags/") (!val.starts_with("refs/tags/"), false)
} else { } else {
true (true, true)
}; };
print_version(include_sha) print_version(include_sha, include_local_changes)
} }

View File

@ -22,7 +22,7 @@ fn read_file(filename: &str) -> Result<String, Box<dyn Error>> {
Ok(contents) Ok(contents)
} }
fn print_version(include_sha: bool) -> Result<(), Box<dyn Error>> { fn print_version(include_sha: bool, include_local: bool) -> Result<(), Box<dyn Error>> {
let mut version = read_file("../../CURRENT_VERSION")?; let mut version = read_file("../../CURRENT_VERSION")?;
let sha = run_cmd(&["git", "rev-parse", "HEAD"])?; let sha = run_cmd(&["git", "rev-parse", "HEAD"])?;
@ -32,7 +32,7 @@ fn print_version(include_sha: bool) -> Result<(), Box<dyn Error>> {
// if we're a non-release build, check to see if git has // if we're a non-release build, check to see if git has
// unstaged changes // unstaged changes
if run_cmd(&["git", "diff", "--quiet"]).is_err() { if include_local && run_cmd(&["git", "diff", "--quiet"]).is_err() {
version.push('.'); version.push('.');
version.push_str("localchanges"); version.push_str("localchanges");
} }
@ -47,10 +47,10 @@ fn print_version(include_sha: bool) -> Result<(), Box<dyn Error>> {
fn main() -> Result<(), Box<dyn Error>> { fn main() -> Result<(), Box<dyn Error>> {
// If we're built off of a tag, we accept CURRENT_VERSION as is. Otherwise // If we're built off of a tag, we accept CURRENT_VERSION as is. Otherwise
// modify it to indicate local build // modify it to indicate local build
let include_sha = if let Ok(val) = env::var("GITHUB_REF") { let (include_sha, include_local_changes) = if let Ok(val) = env::var("GITHUB_REF") {
!val.starts_with("refs/tags/") (!val.starts_with("refs/tags/"), false)
} else { } else {
true (true, true)
}; };
print_version(include_sha) print_version(include_sha, include_local_changes)
} }