Skip to content
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

Version string verbosity #3240

Closed
wants to merge 1 commit into from
Closed
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
23 changes: 19 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ fn version_from_git_info() -> Result<String, std::io::Error> {

// The last available tag, equal to exact_tag when
// the current commit is tagged
let last_tag = run(&["git", "describe", "--abbrev=0", "--tags"])?;
println!("cargo:rustc-env=GIT_LAST_TAG={last_tag}");
let last_tag_maybe = run(&["git", "describe", "--abbrev=0", "--tags"]).ok();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use https://crates.io/crates/vergen for that

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is maybe a nice one to use instead of our custom calls, and it could provide some more info.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yean and its very easy to use, I use it on wdes/mail-autodiscover-autoconfig#3 (comment)
if examples are needed

if let Some(ref last_tag) = last_tag_maybe {
println!("cargo:rustc-env=GIT_LAST_TAG={last_tag}");
}

// The current branch name
let branch = run(&["git", "rev-parse", "--abbrev-ref", "HEAD"])?;
Expand All @@ -69,12 +71,25 @@ fn version_from_git_info() -> Result<String, std::io::Error> {
let rev_short = rev.get(..8).unwrap_or_default();
println!("cargo:rustc-env=GIT_REV={rev_short}");

// The current git commit time
let commit_time = run(&["git", "log", "-1", "--format=%cd", "--date=format:%Y-%m-%d %H:%M:%S"])?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the commit time to the version string seems overly verbose, and isn't something that's usually included in a version string itself. While I don't feel that including the commit time is all that valuable, if you really want to include it, I think it should go on its own line of output, and it should also include timezone info.

BTW, hooks/build already includes the build (not commit) time in the Docker image. To me it seems a bit odd for those times not to match, so that's another reason I'd favor not including the commit time.


// Combined version
if let Some(exact) = exact_tag {
Ok(exact)
} else if &branch != "main" && &branch != "master" {
Ok(format!("{last_tag}-{rev_short} ({branch})"))
if let Some(ref last_tag) = last_tag_maybe {
Ok(format!("{last_tag}-{rev_short} ({branch}) {commit_time}"))
}
else {
Ok(format!("{rev_short} ({branch}) {commit_time}"))
}
} else {
Ok(format!("{last_tag}-{rev_short}"))
if let Some(ref last_tag) = last_tag_maybe {
Ok(format!("{last_tag}-{rev_short} {commit_time}"))
}
else {
Ok(format!("main-{rev_short} {commit_time}"))
}
}
}