Skip to content

Commit dd95cc2

Browse files
committed
fix(coordinator): report the shared build identity from --version
The nightly release roster added coordinator and coordinatorctl for 0.44.0, and the additional-platform build checks every binary's --version against the release identity. Both Coordinator CLIs used clap's bare crate version, so under a nightly tag they printed `coordinator 0.44.0` where the check expected the nightly identity, and the build step exited 1 without saying which binary disagreed. Both executables now report `registry_platform_buildinfo::DISPLAY_VERSION` like the other products, and both build scripts name the binary, the observed output, and the expected identity when the check fails. Signed-off-by: Jeremi Joslin <jeremi@joslin.fr>
1 parent da8126c commit dd95cc2

7 files changed

Lines changed: 64 additions & 5 deletions

File tree

‎Cargo.lock‎

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

‎crates/registry-coordinator/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ registry-platform-activation.workspace = true
120120
registry-platform-audit.workspace = true
121121
registry-platform-oidc.workspace = true
122122
registry-platform-authcommon.workspace = true
123+
registry-platform-buildinfo.workspace = true
123124
registry-platform-httpsec = { workspace = true, features = ["server"] }
124125
jsonwebtoken.workspace = true
125126
registry-platform-canonical-json.workspace = true

‎crates/registry-coordinator/src/cli.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub const CTL_REPORT_KIND: &str = "CoordinatorCtlReport";
2222
#[command(
2323
name = "coordinatorctl",
2424
about = "Author, package, activate and operate Registry Coordinator",
25-
version
25+
version = registry_platform_buildinfo::DISPLAY_VERSION
2626
)]
2727
struct Cli {
2828
#[arg(long, global = true, value_enum, default_value_t = Format::Human)]

‎crates/registry-coordinator/src/service.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const SHUTDOWN_GRACE: Duration = ATTEMPT_TIMEOUT.saturating_add(LEASE_FINALIZATI
2626
#[command(
2727
name = "coordinator",
2828
about = "Authenticated Registry Coordinator workflow service",
29-
version
29+
version = registry_platform_buildinfo::DISPLAY_VERSION
3030
)]
3131
struct Cli {
3232
/// Runtime configuration file.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
use std::process::Command;
3+
4+
fn version_output(executable: &str, flag: &str) -> String {
5+
let output = Command::new(executable)
6+
.arg(flag)
7+
.output()
8+
.unwrap_or_else(|err| panic!("{executable} {flag} runs: {err}"));
9+
assert!(
10+
output.status.success(),
11+
"{executable} {flag} failed: {}",
12+
String::from_utf8_lossy(&output.stderr)
13+
);
14+
String::from_utf8_lossy(&output.stdout).into_owned()
15+
}
16+
17+
/// Both Coordinator executables report the version text the shared build
18+
/// identity decides, so a nightly build names its dated source identity and
19+
/// an unmarked build names a development version. The release scripts compare
20+
/// `--version` against that text before they stage a binary.
21+
#[test]
22+
fn both_executables_report_the_shared_build_identity() {
23+
for (name, executable) in [
24+
("coordinator", env!("CARGO_BIN_EXE_coordinator")),
25+
("coordinatorctl", env!("CARGO_BIN_EXE_coordinatorctl")),
26+
] {
27+
for flag in ["--version", "-V"] {
28+
assert_eq!(
29+
version_output(executable, flag),
30+
format!("{name} {}\n", registry_platform_buildinfo::DISPLAY_VERSION)
31+
);
32+
}
33+
}
34+
}
35+
36+
#[test]
37+
fn version_output_distinguishes_the_build_identity() {
38+
let expected = if registry_platform_buildinfo::IS_RELEASE_BUILD {
39+
env!("CARGO_PKG_VERSION").to_owned()
40+
} else if registry_platform_buildinfo::IS_NIGHTLY_BUILD {
41+
registry_platform_buildinfo::DISPLAY_VERSION.to_owned()
42+
} else {
43+
format!("{}-dev", env!("CARGO_PKG_VERSION"))
44+
};
45+
assert_eq!(
46+
version_output(env!("CARGO_BIN_EXE_coordinator"), "--version"),
47+
format!("coordinator {expected}\n")
48+
);
49+
}

‎release/scripts/build-additional-platform-binaries.sh‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,9 @@ while read -r package binary; do
4242
test -n "${typst_pin}"
4343
expected+=" (typst ${typst_pin})"
4444
fi
45-
test "$("${destination}" --version)" = "${expected}"
45+
observed="$("${destination}" --version)"
46+
if [[ "${observed}" != "${expected}" ]]; then
47+
printf '%s reports "%s"; the release identity expects "%s"\n' "${binary}" "${observed}" "${expected}" >&2
48+
exit 1
49+
fi
4650
done <<<"${builds}"

‎release/scripts/build-release-native-platform.sh‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ if [[ "${exclude_discovery}" -eq 1 ]]; then
326326
additional_platform_builds="${filtered_platform_builds%$'\n'}"
327327
fi
328328
build_additional_platforms() {
329-
local package binary expected typst_pin
329+
local package binary expected observed typst_pin
330330
[[ -n "${additional_platform_builds}" ]] || return 0
331331
while read -r package binary; do
332332
[[ "${binary}" != scheduling ]] || continue
@@ -338,7 +338,11 @@ build_additional_platforms() {
338338
test -n "${typst_pin}"
339339
expected+=" (typst ${typst_pin})"
340340
fi
341-
test "$("${staged_executable}" --version)" = "${expected}"
341+
observed="$("${staged_executable}" --version)"
342+
if [[ "${observed}" != "${expected}" ]]; then
343+
printf '%s reports "%s"; the release identity expects "%s"\n' "${binary}" "${observed}" "${expected}" >&2
344+
exit 1
345+
fi
342346
done <<<"${additional_platform_builds}"
343347
}
344348

0 commit comments

Comments
 (0)