Add /version endpoint and GitHub Actions release workflow
This commit is contained in:
@@ -54,6 +54,7 @@ async fn main() {
|
||||
|
||||
let app = Router::new()
|
||||
.route("/", get(routes::emotes::root))
|
||||
.route("/version", get(routes::version::version))
|
||||
.route("/json", get(routes::emotes::list_emotes))
|
||||
.route("/emotes", post(routes::emotes::create_emote))
|
||||
.route("/emotes/{uuid}", put(routes::emotes::update_emote))
|
||||
|
||||
@@ -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