Display current branch and version on the footer #10

Merged
blek merged 6 commits from display-version into 0.2-dev 2023-10-29 10:48:35 +01:00
4 changed files with 49 additions and 3 deletions

View File

@ -7,6 +7,7 @@ services:
networks:
bfile:
volumes:
- './.git:/opt/code/.git'
- './filed:/opt/code'
- './filed/config:/etc/filed'
- '/opt/code/target'

View File

@ -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}");
}

View File

@ -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<T: Into<String>, O: From<String>>(name: T) -> Result<O, String> {
@ -140,7 +158,8 @@ pub fn loadenv() -> Result<Env, Box<dyn std::error::Error>> {
return Err(format!("CONF_FILE is {}, which is not a file!", spath).into())
}
spath
}
},
version: VersionData::default()
}
)
}

View File

@ -67,6 +67,13 @@
<td>
<small>Made with Rust and &lt;3</small>
<small style="display:block">
Version
<a href="https://git.blek.codes/blek/bfile/commit/{{ env.version.commit }}" target="_blank">
{{ env!("CARGO_PKG_VERSION") }} ({{ env.version.branch -}}/{{- env.version.short_commit }})
</a>
</small>
<ul style='margin:10px 0'>
<li>
<a href="https://git.blek.codes/blek/bfile">