Compare commits

...

6 Commits

Author SHA1 Message Date
blek 12614078ad
print version at the footer 2023-10-29 19:44:31 +10:00
blek 99807b9722
fix few obscure errors 2023-10-29 19:25:53 +10:00
blek 32375127a9
display errors 2023-10-29 19:25:33 +10:00
blek 8d5d739568
include branch data 2023-10-29 19:14:58 +10:00
blek b9f0d80dc3
move out code to a function 2023-10-29 19:13:27 +10:00
blek d09f88f7fa
load commit hash at compile time 2023-10-29 19:11:38 +10: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

@ -66,6 +66,13 @@
<tr>
<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>