Add /version endpoint and GitHub Actions release workflow
This commit is contained in:
@@ -1 +1,2 @@
|
||||
pub mod emotes;
|
||||
pub mod version;
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
use axum::response::{IntoResponse, Json};
|
||||
use serde_json::json;
|
||||
|
||||
/// GET /version
|
||||
/// Returns the current git commit hash and tag (if present).
|
||||
pub async fn version() -> impl IntoResponse {
|
||||
let commit = env!("GIT_COMMIT_HASH");
|
||||
let tag = env!("GIT_TAG");
|
||||
|
||||
// `git describe --tags --exact-match` sets an exact semver-like tag when the
|
||||
// commit is tagged; otherwise the build script stores "untagged".
|
||||
let response = if tag == "untagged" {
|
||||
json!({
|
||||
"commit": commit,
|
||||
"version": null
|
||||
})
|
||||
} else {
|
||||
json!({
|
||||
"commit": commit,
|
||||
"version": tag
|
||||
})
|
||||
};
|
||||
|
||||
Json(response)
|
||||
}
|
||||
Reference in New Issue
Block a user