mirror of
https://github.com/Xevion/banner.git
synced 2025-12-05 23:14:20 -06:00
feat: embed git commit into binary, provide link on frontend
This commit is contained in:
32
build.rs
Normal file
32
build.rs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// Get the current Git commit hash
|
||||||
|
let output = Command::new("git").args(["rev-parse", "HEAD"]).output();
|
||||||
|
|
||||||
|
let git_hash = match output {
|
||||||
|
Ok(output) => {
|
||||||
|
if output.status.success() {
|
||||||
|
String::from_utf8_lossy(&output.stdout).trim().to_string()
|
||||||
|
} else {
|
||||||
|
"unknown".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_) => "unknown".to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get the short hash (first 7 characters)
|
||||||
|
let short_hash = if git_hash != "unknown" && git_hash.len() >= 7 {
|
||||||
|
git_hash[..7].to_string()
|
||||||
|
} else {
|
||||||
|
git_hash.clone()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set the environment variables that will be available at compile time
|
||||||
|
println!("cargo:rustc-env=GIT_COMMIT_HASH={}", git_hash);
|
||||||
|
println!("cargo:rustc-env=GIT_COMMIT_SHORT={}", short_hash);
|
||||||
|
|
||||||
|
// Rebuild if the Git commit changes
|
||||||
|
println!("cargo:rerun-if-changed=.git/HEAD");
|
||||||
|
println!("cargo:rerun-if-changed=.git/refs/heads");
|
||||||
|
}
|
||||||
@@ -239,6 +239,10 @@ async fn status(State(_state): State<BannerState>) -> Json<Value> {
|
|||||||
"banner_api": {
|
"banner_api": {
|
||||||
"status": "connected"
|
"status": "connected"
|
||||||
},
|
},
|
||||||
|
"git": {
|
||||||
|
"commit": env!("GIT_COMMIT_HASH"),
|
||||||
|
"short": env!("GIT_COMMIT_SHORT")
|
||||||
|
},
|
||||||
"timestamp": chrono::Utc::now().to_rfc3339()
|
"timestamp": chrono::Utc::now().to_rfc3339()
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ export interface StatusResponse {
|
|||||||
banner_api: {
|
banner_api: {
|
||||||
status: string;
|
status: string;
|
||||||
};
|
};
|
||||||
|
git: {
|
||||||
|
commit: string;
|
||||||
|
short: string;
|
||||||
|
};
|
||||||
timestamp: string;
|
timestamp: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -234,6 +234,29 @@ function App() {
|
|||||||
</Flex>
|
</Flex>
|
||||||
</Card>
|
</Card>
|
||||||
)}
|
)}
|
||||||
|
{status?.git?.commit && (
|
||||||
|
<Flex justify="center" style={{ marginTop: "12px" }}>
|
||||||
|
<Text
|
||||||
|
size="1"
|
||||||
|
style={{
|
||||||
|
color: "#8B949E",
|
||||||
|
textDecoration: "none",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
href={`https://github.com/Xevion/banner/commit/${status.git.commit}`}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
style={{
|
||||||
|
color: "inherit",
|
||||||
|
textDecoration: "none",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
GitHub
|
||||||
|
</a>
|
||||||
|
</Text>
|
||||||
|
</Flex>
|
||||||
|
)}
|
||||||
</Flex>
|
</Flex>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user