Skip to content

Commit

Permalink
make version.localchanges match API logic (microsoft#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmc-msft authored and anshuman-goel committed Oct 1, 2020
1 parent bf01dbd commit dcbfe9b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
12 changes: 6 additions & 6 deletions src/agent/onefuzz-agent/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn read_file(filename: &str) -> Result<String, Box<dyn Error>> {
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 sha = run_cmd(&["git", "rev-parse", "HEAD"])?;

Expand All @@ -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
// unstaged changes
if run_cmd(&["git", "diff", "--quiet"]).is_err() {
if include_local && run_cmd(&["git", "diff", "--quiet"]).is_err() {
version.push('.');
version.push_str("localchanges");
}
Expand All @@ -47,10 +47,10 @@ fn print_version(include_sha: bool) -> 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
// modify it to indicate local build
let include_sha = if let Ok(val) = env::var("GITHUB_REF") {
!val.starts_with("refs/tags/")
let (include_sha, include_local_changes) = if let Ok(val) = env::var("GITHUB_REF") {
(!val.starts_with("refs/tags/"), false)
} else {
true
(true, true)
};
print_version(include_sha)
print_version(include_sha, include_local_changes)
}
12 changes: 6 additions & 6 deletions src/agent/onefuzz-supervisor/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn read_file(filename: &str) -> Result<String, Box<dyn Error>> {
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 sha = run_cmd(&["git", "rev-parse", "HEAD"])?;

Expand All @@ -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
// unstaged changes
if run_cmd(&["git", "diff", "--quiet"]).is_err() {
if include_local && run_cmd(&["git", "diff", "--quiet"]).is_err() {
version.push('.');
version.push_str("localchanges");
}
Expand All @@ -47,10 +47,10 @@ fn print_version(include_sha: bool) -> 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
// modify it to indicate local build
let include_sha = if let Ok(val) = env::var("GITHUB_REF") {
!val.starts_with("refs/tags/")
let (include_sha, include_local_changes) = if let Ok(val) = env::var("GITHUB_REF") {
(!val.starts_with("refs/tags/"), false)
} else {
true
(true, true)
};
print_version(include_sha)
print_version(include_sha, include_local_changes)
}
12 changes: 6 additions & 6 deletions src/proxy-manager/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn read_file(filename: &str) -> Result<String, Box<dyn Error>> {
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 sha = run_cmd(&["git", "rev-parse", "HEAD"])?;

Expand All @@ -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
// unstaged changes
if run_cmd(&["git", "diff", "--quiet"]).is_err() {
if include_local && run_cmd(&["git", "diff", "--quiet"]).is_err() {
version.push('.');
version.push_str("localchanges");
}
Expand All @@ -47,10 +47,10 @@ fn print_version(include_sha: bool) -> 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
// modify it to indicate local build
let include_sha = if let Ok(val) = env::var("GITHUB_REF") {
!val.starts_with("refs/tags/")
let (include_sha, include_local_changes) = if let Ok(val) = env::var("GITHUB_REF") {
(!val.starts_with("refs/tags/"), false)
} else {
true
(true, true)
};
print_version(include_sha)
print_version(include_sha, include_local_changes)
}

0 comments on commit dcbfe9b

Please sign in to comment.