-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: get client version from crate and git
- Loading branch information
Eason
committed
Aug 7, 2023
1 parent
8f3eded
commit 15d8b4d
Showing
14 changed files
with
123 additions
and
49 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
fn main() { | ||
let desc = std::process::Command::new("git") | ||
.args(["describe", "--always", "--dirty", "--exclude", "*"]) | ||
let commit_id = std::process::Command::new("git") | ||
.args([ | ||
"describe", | ||
"--always", | ||
"--match", | ||
"__EXCLUDE__", | ||
"--abbrev=7", | ||
]) | ||
.output() | ||
.ok() | ||
.and_then(|r| String::from_utf8(r.stdout).ok()) | ||
.map(|d| format!(" {d}")) | ||
.unwrap_or_default(); | ||
println!("cargo:rustc-env=AXON_GIT_DESCRIPTION={desc}"); | ||
.map(|r| String::from_utf8(r.stdout).unwrap()) | ||
.unwrap(); | ||
|
||
println!("cargo:rustc-env=AXON_COMMIT_ID={}", commit_id); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "common-version" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
semver = "1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use std::fmt::{Display, Formatter}; | ||
use std::str::FromStr; | ||
|
||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] | ||
pub struct Version { | ||
inner: semver::Version, | ||
} | ||
|
||
impl FromStr for Version { | ||
type Err = semver::Error; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
semver::Version::from_str(s).map(|inner| Version { inner }) | ||
} | ||
} | ||
|
||
impl Display for Version { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{}", self.inner) | ||
} | ||
} | ||
|
||
impl Version { | ||
pub fn new(ver: &str) -> Self { | ||
Version::from_str(ver).unwrap_or_else(|e| panic!("Parse version error {:?}", e)) | ||
} | ||
|
||
pub fn new_with_commit_id(ver: &str, commit_id: &str) -> Self { | ||
Version::new(ver).set_commit_id(commit_id) | ||
} | ||
|
||
pub fn commit_id(&self) -> String { | ||
self.inner.build.to_ascii_lowercase() | ||
} | ||
|
||
fn set_commit_id(mut self, commit_id: &str) -> Self { | ||
self.inner.build = semver::BuildMetadata::new(commit_id) | ||
.unwrap_or_else(|e| panic!("Parse commit id error {:?}", e)); | ||
|
||
self | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters