diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 84557c8..774aea5 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -7,6 +7,7 @@ services: networks: bfile: volumes: + - './.git:/opt/code/.git' - './filed:/opt/code' - './filed/config:/etc/filed' - '/opt/code/target' diff --git a/filed/build.rs b/filed/build.rs index 6d6c080..04b9494 100644 --- a/filed/build.rs +++ b/filed/build.rs @@ -17,6 +17,19 @@ fn extfilter(valid: String, x: Option<&OsStr>) -> bool { ext == valid } +fn system(cmd: &str, args: &[&str]) -> String { + let out = Command::new(cmd) + .args(args) + .output() + .unwrap(); + + if out.stderr.len() != 0 { + panic!("Got this while running {cmd} with \"{}\": {}", args.join(" "), String::from_utf8(out.stderr).unwrap()) + } + + String::from_utf8(out.stdout).unwrap() +} + fn main() { println!("cargo:rerun-if-changed=static/assets"); @@ -58,5 +71,11 @@ fn main() { .arg(asset_path(asset)) .spawn() .unwrap(); - }) + }); + + let commit = system("git", &["rev-parse", "HEAD"]); + let branch = system("git", &["rev-parse", "--abbrev-ref", "HEAD"]); + + println!("cargo:rustc-env=COMMIT_HASH={commit}"); + println!("cargo:rustc-env=COMMIT_BRANCH={branch}"); } \ No newline at end of file diff --git a/filed/src/env.rs b/filed/src/env.rs index 545dac4..46aac2e 100644 --- a/filed/src/env.rs +++ b/filed/src/env.rs @@ -15,6 +15,23 @@ pub struct Redis { pub prefix: String } +#[derive(Debug, Clone)] +pub struct VersionData { + pub commit: String, + pub short_commit: String, + pub branch: String +} + +impl Default for VersionData { + fn default() -> Self { + VersionData { + commit: env!("COMMIT_HASH").to_string(), + short_commit: env!("COMMIT_HASH").to_string().chars().take(6).collect(), + branch: env!("COMMIT_BRANCH").to_string() + } + } +} + #[derive(Debug, Clone)] pub struct Env { pub logging: bool, @@ -24,7 +41,8 @@ pub struct Env { pub filedir: String, pub instanceurl: String, pub uploadspath: String, - pub confpath: String + pub confpath: String, + pub version: VersionData } fn get_var, O: From>(name: T) -> Result { @@ -140,7 +158,8 @@ pub fn loadenv() -> Result> { return Err(format!("CONF_FILE is {}, which is not a file!", spath).into()) } spath - } + }, + version: VersionData::default() } ) } diff --git a/filed/templates/base.html b/filed/templates/base.html index 761bbb5..4e23bf8 100644 --- a/filed/templates/base.html +++ b/filed/templates/base.html @@ -66,6 +66,13 @@ Made with Rust and <3 + + + Version + + {{ env!("CARGO_PKG_VERSION") }} ({{ env.version.branch -}}/{{- env.version.short_commit }}) + +