Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

make version.localchanges match API logic #62

Merged
merged 2 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}