Skip to content

Commit 13f9ed2

Browse files
committed
Add git semver build version and add version field to admin /api/config.
1 parent 268755a commit 13f9ed2

7 files changed

Lines changed: 19 additions & 4 deletions

File tree

Makefile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
# Try to get the semver from 1) git 2) fallback.
2-
VERSION := $(or $(shell git describe --tags --abbrev=0 2> /dev/null),"v0.0.0")
2+
VERSION := $(or $(shell git describe --tags --abbrev=0 2> /dev/null),0.0.0)
3+
34
COMMIT := $(or $(shell git rev-parse --short HEAD 2> /dev/null),"unknown")
45

56
BIN := dictpress
67

78
.PHONY: build
89
build:
9-
cargo build --release
10+
VERSION=$(VERSION) cargo build --release
11+
12+
.PHONY: build-debug
13+
build-debug:
14+
VERSION=$(VERSION) cargo build
1015

1116
.PHONY: run
1217
run:

build.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
let version = std::env::var("VERSION").unwrap_or_else(|_| "v0.0.0".to_string());
3+
println!("cargo:rustc-env=VERSION={}", version);
4+
}

src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clap::{Parser, Subcommand};
55
#[derive(Parser)]
66
#[command(name = "dictpress")]
77
#[command(about = "dictpress - Build dictionary websites. https://dict.press")]
8-
#[command(version)]
8+
#[command(version = env!("VERSION"))]
99
pub struct Cli {
1010
/// Path to one or more config files (merged in order).
1111
#[arg(long, default_value = "config.toml", action = clap::ArgAction::Append)]

src/handlers/admin.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::models::Stats;
1313
pub struct ConfigResp {
1414
pub languages: HashMap<String, LangResp>,
1515
pub dicts: Vec<[String; 2]>,
16+
pub version: String,
1617
}
1718

1819
#[derive(serde::Serialize)]
@@ -50,6 +51,7 @@ pub async fn get_config(State(ctx): State<Arc<Ctx>>) -> Result<ApiResp<ConfigRes
5051
.iter()
5152
.map(|(from, to)| [from.id.clone(), to.id.clone()])
5253
.collect(),
54+
version: ctx.version.clone(),
5355
};
5456

5557
Ok(json(out))

src/handlers/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub struct Ctx {
4444

4545
pub consts: Consts,
4646
pub asset_ver: String,
47+
pub version: String,
4748
}
4849

4950
/// Application constants.

src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ async fn main() {
312312
"{:08}",
313313
chrono::Local::now().timestamp_nanos_opt().unwrap_or(0) % 100_000_000
314314
),
315+
316+
// App build version.
317+
version: env!("VERSION").to_string(),
315318
});
316319

317320
// Start the HTTP server.

static/admin/oat.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)