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

always add commit hash to version.build for /status endpoint #12722

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 4 additions & 5 deletions neard/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
//! The build script sets `NEARD_VERSION` and `NEARD_BUILD` to be neard version
//! and build respectively. Version is the official semver such as 1.24.1 if
//! the executable is built from a release branch or `trunk` if it’s built from
//! master. Build is a `git describe` of the commit the binary was built at
//! (for official releases it should be the same as version).
//! master. Build is a `git describe` of the commit the binary was built at.

use anyhow::{anyhow, Result};

Expand Down Expand Up @@ -50,8 +49,7 @@ fn command(prog: &str, args: &[&str], cwd: Option<std::path::PathBuf>) -> Result
/// Returns version read from git repository or ‘unknown’ if could not be
/// determined.
///
/// Uses `git describe --always --dirty=-modified` to get the version. For
/// builds on release tags this will return that tag. In other cases the
/// Uses `git describe --always --dirty=-modified` to get the version. The
/// version will describe the commit by including its hash. If the working
/// directory isn’t clean, the version will include `-modified` suffix.
fn get_git_version() -> Result<String> {
Expand Down Expand Up @@ -84,7 +82,8 @@ fn get_git_version() -> Result<String> {
// * --tags → consider tags even if they are unnanotated
// * --match=[0-9]* → only consider tags starting with a digit; this
// prevents tags such as `crates-0.14.0` from being considered
let args = &["describe", "--always", "--dirty=-modified", "--tags", "--match=[0-9]*"];
// * --long → always output the abbreviated commit name even it matches a tag
let args = &["describe", "--always", "--dirty=-modified", "--tags", "--long", "--match=[0-9]*"];
let out = command("git", args, None)?;
match String::from_utf8_lossy(&out) {
std::borrow::Cow::Borrowed(version) => Ok(version.trim().to_string()),
Expand Down