From 399d073ab4fe46593eba63dea5b4b40222cc565d Mon Sep 17 00:00:00 2001 From: Michael Sproul Date: Tue, 23 Feb 2021 23:31:37 +0000 Subject: [PATCH] Fix lighthouse_version (#2221) ## Proposed Changes Somehow since Lighthouse v1.1.3 the behaviour of `git-describe` has changed so that it includes the version tag, the number of commits since that tag, _and_ the commit. According to the docs this is how it should always have behaved?? Weird! https://git-scm.com/docs/git-describe/2.30.1 Anyway, this lead to `lighthouse_version` producing this monstrosity of a version string when building #2194: ``` Lighthouse/v1.1.3-v1.1.3-5-gac07 ``` Observe it in the wild here: https://pyrmont.beaconcha.in/block/694880 Adding `--exclude="*"` prevents `git-describe` from trying to include the tag, and on that troublesome commit from #2194 it now produces the correct version string. --- Cargo.lock | 1 + common/lighthouse_version/Cargo.toml | 3 +++ common/lighthouse_version/src/lib.rs | 15 ++++++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 340ea32948..bca31b1f89 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3689,6 +3689,7 @@ name = "lighthouse_version" version = "0.1.0" dependencies = [ "git-version", + "regex", "target_info", ] diff --git a/common/lighthouse_version/Cargo.toml b/common/lighthouse_version/Cargo.toml index a9778787ad..7da51ea11f 100644 --- a/common/lighthouse_version/Cargo.toml +++ b/common/lighthouse_version/Cargo.toml @@ -9,3 +9,6 @@ edition = "2018" [dependencies] git-version = "0.3.4" target_info = "0.1.0" + +[dev-dependencies] +regex = "1" diff --git a/common/lighthouse_version/src/lib.rs b/common/lighthouse_version/src/lib.rs index 7f9d58d052..54b28bec75 100644 --- a/common/lighthouse_version/src/lib.rs +++ b/common/lighthouse_version/src/lib.rs @@ -9,7 +9,7 @@ use target_info::Target; /// /// `Lighthouse/v0.2.0-1419501f2+` pub const VERSION: &str = git_version!( - args = ["--always", "--dirty=+", "--abbrev=7"], + args = ["--always", "--dirty=+", "--abbrev=7", "--exclude=*"], prefix = "Lighthouse/v1.1.3-", fallback = "unknown" ); @@ -22,3 +22,16 @@ pub const VERSION: &str = git_version!( pub fn version_with_platform() -> String { format!("{}/{}-{}", VERSION, Target::arch(), Target::os()) } + +#[cfg(test)] +mod test { + use super::*; + use regex::Regex; + + #[test] + fn version_formatting() { + let re = Regex::new(r"^Lighthouse/v[0-9]+\.[0-9]+\.[0-9]+(-rc.[0-9])?-[[:xdigit:]]{7}\+?$") + .unwrap(); + assert!(re.is_match(VERSION), VERSION); + } +}