diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 354f7d493..cd882a787 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -45,6 +45,7 @@ jobs: outputs: release: ${{ steps.decide.outputs.release }} tag: ${{ steps.decide.outputs.tag }} + version: ${{ steps.decide.outputs.version }} head: ${{ steps.decide.outputs.head }} dry_run: ${{ steps.mode.outputs.dry_run }} steps: @@ -65,6 +66,9 @@ jobs: run: | python3 tools/release_train.py decide --kind game ${HEAD_SHA:+--head "$HEAD_SHA"} ${FORCE:+--force} | tee decision.json echo "### $(jq -r '.reason' decision.json)" >> "$GITHUB_STEP_SUMMARY" + # The version the programs are built with (docs/versioning.md): the tag without its v. + tag=$(jq -r '.tag' decision.json) + echo "version=${tag#v}" >> "$GITHUB_OUTPUT" # A dry run builds whatever the decision, to test the builds. if [[ "${{ steps.mode.outputs.dry_run }}" == true ]]; then echo "release=true" >> "$GITHUB_OUTPUT"; fi @@ -99,6 +103,9 @@ jobs: timeout-minutes: ${{ matrix.mac && 60 || 40 }} env: RUSTFLAGS: ${{ matrix.rustflags }} + # The release's version, built in (horizon_core::release): --version, user agents, crash reports and + # telemetry say it. No version-bump commits. + HORIZON_VERSION: ${{ needs.decide.outputs.version }} defaults: run: shell: bash @@ -162,9 +169,13 @@ jobs: bin=target/release "$bin/horizon-client${{ matrix.exe }}" --help | grep -q -- '--resources' "$bin/horizon-ctl${{ matrix.exe }}" --help > /dev/null - "$bin/horizon-prepare${{ matrix.exe }}" --version "$bin/horizon-prepare${{ matrix.exe }}" --help | grep -q -- '--minecraft-dir' - "$bin/horizon-server${{ matrix.exe }}" --version + # The version is the release's. + for binary in horizon-prepare horizon-server; do + out=$("$bin/$binary${{ matrix.exe }}" --version | tr -d '\r') + echo "$out" + [[ "$out" == "$binary $HORIZON_VERSION" ]] || { echo "::error::expected $binary $HORIZON_VERSION"; exit 1; } + done - name: Tools from the runner if: runner.environment == 'self-hosted' run: bash tools/ci/runner-env.sh @@ -245,7 +256,7 @@ jobs: folder="dist/${{ matrix.server_dir }}" python3 tools/check_imports.py --server "$folder/horizon-engine" "$folder/horizon-server" "$folder/horizon-prepare" "$folder/horizon-engine" --help | grep -q -- '--resources' - "$folder/horizon-server" --version + [[ "$("$folder/horizon-server" --version)" == "horizon-server $HORIZON_VERSION" ]] cd dist rm -f "${{ matrix.server_asset }}" tar czf "${{ matrix.server_asset }}" "${{ matrix.server_dir }}" diff --git a/crates/horizon-client/src/auth.rs b/crates/horizon-client/src/auth.rs index a6dfab1ee..b899ea5d5 100644 --- a/crates/horizon-client/src/auth.rs +++ b/crates/horizon-client/src/auth.rs @@ -174,7 +174,7 @@ pub fn discovery_url() -> String { fn agent() -> ureq::Agent { ureq::AgentBuilder::new() .timeout(Duration::from_secs(15)) - .user_agent(concat!("Horizon/", env!("CARGO_PKG_VERSION"))) + .user_agent(&format!("Horizon/{}", horizon_core::release::VERSION)) .build() } diff --git a/crates/horizon-client/src/bin/horizon-ctl/mcp.rs b/crates/horizon-client/src/bin/horizon-ctl/mcp.rs index fa60b38f9..8d67953a5 100644 --- a/crates/horizon-client/src/bin/horizon-ctl/mcp.rs +++ b/crates/horizon-client/src/bin/horizon-ctl/mcp.rs @@ -130,7 +130,7 @@ impl Session { "initialize" => Ok(json!({ "protocolVersion": params.get("protocolVersion").and_then(Value::as_str).unwrap_or(PROTOCOL), "capabilities": { "tools": {} }, - "serverInfo": { "name": "horizon-ctl", "version": env!("CARGO_PKG_VERSION") }, + "serverInfo": { "name": "horizon-ctl", "version": horizon_core::release::VERSION }, "instructions": "Play Horizon, a Rust reimplementation of Minecraft Java Edition. Start with launch (it finds the game installed by the Horizon launcher and opens or creates a world), then read the world with state, inventory, screen, entities and find_block, and act with goto, look_at_block, break, place, interact, click_slot and click_button. Actions block until they finish and report what happened. Coordinates are block coordinates; yaw 0 faces south (+Z).", })), "ping" => Ok(json!({})), diff --git a/crates/horizon-client/src/crash.rs b/crates/horizon-client/src/crash.rs index 8ee5803b5..e147bfb4c 100644 --- a/crates/horizon-client/src/crash.rs +++ b/crates/horizon-client/src/crash.rs @@ -105,18 +105,23 @@ impl Report { } } -/// The release tag (the launcher installs each build in a folder named after it) and the client's -/// own version, or just the latter. +/// The release this binary is (`v0.2.3`); for a release from before 0.2, its tag and the client's +/// crate version; for a build from source, that version alone. pub fn version() -> String { let version = env!("CARGO_PKG_VERSION"); - match release_tag() { - Some(tag) => format!("{tag} (client {version})"), - None => version.to_owned(), + match (horizon_core::release::RELEASE, release_tag()) { + (Some(_), Some(tag)) => tag, + (None, Some(tag)) => format!("{tag} (client {version})"), + (_, None) => version.to_owned(), } } -/// The release this binary came with: launcher installs live in a folder named after the tag. +/// The release this binary came with: the version release.yml built in (docs/versioning.md), else +/// the folder the launcher installed it in, named after the tag (releases from before 0.2). pub fn release_tag() -> Option { + if let Some(version) = horizon_core::release::RELEASE { + return Some(format!("v{version}")); + } let exe = std::env::current_exe().ok()?; let folder = exe.parent()?.file_name()?.to_str()?; (folder.starts_with('v') && folder[1..].starts_with(|c: char| c.is_ascii_digit())) @@ -517,6 +522,18 @@ pub fn debug_crash_after() -> Option { mod tests { use super::*; + #[test] + fn a_release_reports_its_built_in_version() { + // release.yml builds with HORIZON_VERSION (docs/versioning.md): `v0.2.3`, wherever it is installed. + match horizon_core::release::RELEASE { + Some(version) => { + assert_eq!(release_tag(), Some(format!("v{version}"))); + assert_eq!(super::version(), format!("v{version}")); + } + None => assert!(release_tag().is_none() || super::version().contains("(client ")), + } + } + fn report() -> Report { Report { time: chrono::TimeZone::with_ymd_and_hms(&Local, 2026, 10, 14, 9, 5, 7).unwrap(), diff --git a/crates/horizon-client/src/telemetry.rs b/crates/horizon-client/src/telemetry.rs index d0140f941..2010df04a 100644 --- a/crates/horizon-client/src/telemetry.rs +++ b/crates/horizon-client/src/telemetry.rs @@ -75,7 +75,7 @@ pub fn system() -> System { system } -/// The release (`v2026.10.15`), or the client's crate version for a build from source. +/// The release (`v0.2.3`), or the client's crate version for a build from source. pub fn version() -> String { crate::crash::release_tag().unwrap_or_else(|| format!("dev {}", env!("CARGO_PKG_VERSION"))) } diff --git a/crates/horizon-core/src/lib.rs b/crates/horizon-core/src/lib.rs index c8077b327..9034ef2eb 100644 --- a/crates/horizon-core/src/lib.rs +++ b/crates/horizon-core/src/lib.rs @@ -17,6 +17,7 @@ pub mod storage; pub mod text; pub mod ticks; +pub mod release; pub mod version; pub use version::VANILLA_VERSION; diff --git a/crates/horizon-core/src/release.rs b/crates/horizon-core/src/release.rs new file mode 100644 index 000000000..54a3cb94e --- /dev/null +++ b/crates/horizon-core/src/release.rs @@ -0,0 +1,32 @@ +//! Which Horizon release this build is (docs/versioning.md). Not Minecraft's version: that is +//! [`crate::version`], generated from the game's own files. + +/// The release's version (`0.2.3`, no `v`): release.yml builds every release with `HORIZON_VERSION` +/// set from its tag, so there are no version-bump commits. None for a build from source. +pub const RELEASE: Option<&str> = match option_env!("HORIZON_VERSION") { + Some(version) if !version.is_empty() => Some(version), + _ => None, +}; + +/// [`RELEASE`], or this crate's Cargo.toml version for a build from source: what `--version`, user +/// agents and reports say. +pub const VERSION: &str = match RELEASE { + Some(version) => version, + None => env!("CARGO_PKG_VERSION"), +}; + +#[cfg(test)] +mod tests { + #[test] + fn the_version_is_the_release_or_the_crate() { + assert_eq!( + super::RELEASE, + option_env!("HORIZON_VERSION").filter(|v| !v.is_empty()) + ); + assert_eq!( + super::VERSION, + super::RELEASE.unwrap_or(env!("CARGO_PKG_VERSION")) + ); + assert!(!super::VERSION.starts_with('v')); + } +} diff --git a/crates/horizon-prepare/src/main.rs b/crates/horizon-prepare/src/main.rs index 0e8adc927..71b7a40cc 100644 --- a/crates/horizon-prepare/src/main.rs +++ b/crates/horizon-prepare/src/main.rs @@ -5,6 +5,13 @@ use std::io::Write; use std::path::{Path, PathBuf}; use std::process::ExitCode; +/// This release's version: release.yml builds it with `HORIZON_VERSION` from the tag +/// (docs/versioning.md); a build from source says Cargo.toml's. +const VERSION: &str = match option_env!("HORIZON_VERSION") { + Some(version) if !version.is_empty() => version, + _ => env!("CARGO_PKG_VERSION"), +}; + const HELP: &str = "\ horizon-prepare: prepare Horizon's resources from your own Minecraft Java Edition @@ -92,7 +99,7 @@ fn main() -> ExitCode { return ExitCode::SUCCESS; } "-V" | "--version" => { - println!("horizon-prepare {}", env!("CARGO_PKG_VERSION")); + println!("horizon-prepare {VERSION}"); return ExitCode::SUCCESS; } _ => Err(format!("unrecognized argument: {text}")), diff --git a/crates/horizon-server-files/src/profiles.rs b/crates/horizon-server-files/src/profiles.rs index 3e16e2a41..3f7e2e509 100644 --- a/crates/horizon-server-files/src/profiles.rs +++ b/crates/horizon-server-files/src/profiles.rs @@ -45,7 +45,7 @@ pub fn resolve(name: &str, online: bool) -> Option { pub fn find_by_name(discovery: &str, name: &str) -> Option { let agent = ureq::AgentBuilder::new() .timeout(Duration::from_secs(15)) - .user_agent(concat!("Horizon/", env!("CARGO_PKG_VERSION"))) + .user_agent(&format!("Horizon/{}", horizon_core::release::VERSION)) .build(); let doc = json::parse(&agent.get(discovery).call().ok()?.into_string().ok()?, true).ok()?; let url = endpoint(&doc, "profiles", "getByName")?.replace("{name}", &name.to_lowercase()); @@ -61,7 +61,7 @@ pub fn fetch_profile_key_keys(discovery: &str) -> Result, &'st const FAILED: &str = "Failed to request Minecraft Services public key"; let agent = ureq::AgentBuilder::new() .timeout(Duration::from_secs(15)) - .user_agent(concat!("Horizon/", env!("CARGO_PKG_VERSION"))) + .user_agent(&format!("Horizon/{}", horizon_core::release::VERSION)) .build(); let get = |url: &str| agent.get(url).call().ok()?.into_string().ok(); let doc = get(discovery) diff --git a/crates/horizon-server/src/api.rs b/crates/horizon-server/src/api.rs index 03f7ae079..c9e553fab 100644 --- a/crates/horizon-server/src/api.rs +++ b/crates/horizon-server/src/api.rs @@ -286,7 +286,7 @@ fn status(shared: &Shared) -> Value { let state = shared.state.lock().unwrap(); json!({ "phase": state.phase.name(), - "version": env!("CARGO_PKG_VERSION"), + "version": crate::VERSION, "pid": std::process::id(), "uptime_seconds": shared.started.elapsed().as_secs(), "engine_pid": state.engine_pid, diff --git a/crates/horizon-server/src/main.rs b/crates/horizon-server/src/main.rs index 627961d81..b4512530c 100644 --- a/crates/horizon-server/src/main.rs +++ b/crates/horizon-server/src/main.rs @@ -18,6 +18,13 @@ mod update; use std::{path::PathBuf, process::ExitCode}; +/// This release's version: release.yml builds it with `HORIZON_VERSION` from the tag +/// (docs/versioning.md); a build from source says Cargo.toml's. +const VERSION: &str = match option_env!("HORIZON_VERSION") { + Some(version) if !version.is_empty() => version, + _ => env!("CARGO_PKG_VERSION"), +}; + const HELP: &str = "\ horizon-server: host a Horizon (Minecraft Java Edition 26.3) server @@ -86,7 +93,7 @@ fn main() -> ExitCode { Ok(()) } Some("version" | "-V" | "--version") => { - println!("horizon-server {}", env!("CARGO_PKG_VERSION")); + println!("horizon-server {VERSION}"); Ok(()) } Some("init") => init_answers(&args[1..]).and_then(|a| init::run(&dir, a)), diff --git a/launcher/src/perf.rs b/launcher/src/perf.rs index 864f6cfa0..7d652283f 100644 --- a/launcher/src/perf.rs +++ b/launcher/src/perf.rs @@ -307,7 +307,7 @@ pub fn benchmark(repeats: usize) -> Result { if let Ok(data) = serde_json::to_value(report.for_upload()) { let item = horizon_telemetry::Item::new( horizon_telemetry::Source::Launcher, - env!("CARGO_PKG_VERSION"), + crate::backend::VERSION, horizon_telemetry::Payload::Benchmark(data), ); let _ = horizon_telemetry::outbox::push(&crate::backend::game_home(), &item); @@ -320,7 +320,7 @@ pub fn benchmark(repeats: usize) -> Result { fn app() -> App { App { name: "horizon-launcher".into(), - version: env!("CARGO_PKG_VERSION").into(), + version: crate::backend::VERSION.into(), ..App::default() } }