Show a real build identity (commit, date) for server and runners
Browse files at this commit1979f8054ceb553b80ffad5f98be3d731c1a1475Parent: a0bbdae- feat
- show a real build identity (commit, date) for server and runners
17 changed files +252 -15
- crates/forge-ci/build.rs +44 -0
- crates/forge-ci/src/build.rs +67 -0
- crates/forge-ci/src/lib.rs +1 -0
- crates/forge-ci/src/proto.rs +7 -0
- crates/forge-core/migrations/0056_runner_build.sql +4 -0
- crates/forge-core/src/ci.rs +2 -0
- crates/forge-core/src/store/ci.rs +7 -2
- crates/forge-core/src/store/migrate.rs +1 -0
- crates/forge-runner/src/cli.rs +1 -1
- crates/forge-runner/src/client.rs +4 -2
- crates/forge-runner/src/runner.rs +1 -1
- crates/forge-web/src/ci/api.rs +9 -2
- crates/forge-web/src/ci/api_tests.rs +62 -0
- crates/forge-web/src/main.rs +1 -5
- crates/forge-web/src/pages/admin_health.rs +7 -2
- crates/forge-web/src/pages/admin_runners.rs +33 -0
- crates/forge-web/src/pages/admin_server.rs +1 -0
crates/forge-ci/build.rsadded+44 -0
| @@ -0,0 +1,44 @@ | |||
| 1 | +//! Emits the build identity: the git commit short sha, whether the tree was dirty, and the commit | ||
| 2 | +//! date. It falls back to the FORGE_BUILD_COMMIT and FORGE_BUILD_DATE environment variables when | ||
| 3 | +//! there is no git (a source tarball, a sandbox without the binary), and then to "unknown". | ||
| 4 | +//! The dirty flag is only re-evaluated when HEAD or its ref moves. | ||
| 5 | + | ||
| 6 | +use std::{env, process::Command}; | ||
| 7 | + | ||
| 8 | +fn git(args: &[&str]) -> Option<String> { | ||
| 9 | + let out = Command::new("git").args(args).output().ok()?; | ||
| 10 | + if !out.status.success() { | ||
| 11 | + return None; | ||
| 12 | + } | ||
| 13 | + let text = String::from_utf8(out.stdout).ok()?.trim().to_owned(); | ||
| 14 | + (!text.is_empty()).then_some(text) | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +fn main() { | ||
| 18 | + println!("cargo:rerun-if-env-changed=FORGE_BUILD_COMMIT"); | ||
| 19 | + println!("cargo:rerun-if-env-changed=FORGE_BUILD_DATE"); | ||
| 20 | + println!("cargo:rerun-if-changed=build.rs"); | ||
| 21 | + if let Some(head) = git(&["rev-parse", "--git-path", "HEAD"]) { | ||
| 22 | + println!("cargo:rerun-if-changed={head}"); | ||
| 23 | + } | ||
| 24 | + if let Some(full) = git(&["symbolic-ref", "-q", "HEAD"]) | ||
| 25 | + && let Some(path) = git(&["rev-parse", "--git-path", &full]) | ||
| 26 | + { | ||
| 27 | + println!("cargo:rerun-if-changed={path}"); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + let sha = git(&["rev-parse", "--short=7", "HEAD"]) | ||
| 31 | + .or_else(|| { | ||
| 32 | + env::var("FORGE_BUILD_COMMIT") | ||
| 33 | + .ok() | ||
| 34 | + .filter(|s| !s.is_empty()) | ||
| 35 | + }) | ||
| 36 | + .unwrap_or_else(|| "unknown".into()); | ||
| 37 | + let date = git(&["show", "-s", "--format=%cs", "HEAD"]) | ||
| 38 | + .or_else(|| env::var("FORGE_BUILD_DATE").ok().filter(|s| !s.is_empty())) | ||
| 39 | + .unwrap_or_else(|| "unknown".into()); | ||
| 40 | + let dirty = git(&["status", "--porcelain", "--untracked-files=no"]).is_some(); | ||
| 41 | + println!("cargo:rustc-env=FORGE_GIT_SHA={sha}"); | ||
| 42 | + println!("cargo:rustc-env=FORGE_GIT_DATE={date}"); | ||
| 43 | + println!("cargo:rustc-env=FORGE_GIT_DIRTY={}", u8::from(dirty)); | ||
| 44 | +} | ||
crates/forge-ci/src/build.rsadded+67 -0
| @@ -0,0 +1,67 @@ | |||
| 1 | +//! The build identity of this binary: version, git commit, commit date. Shared by the server and | ||
| 2 | +//! the runner, which are the same binary, so a runner can be compared to the server it talks to. | ||
| 3 | + | ||
| 4 | +/// The crate version. | ||
| 5 | +pub const VERSION: &str = env!("CARGO_PKG_VERSION"); | ||
| 6 | +/// Short git sha of the commit built, or "unknown". | ||
| 7 | +pub const COMMIT: &str = env!("FORGE_GIT_SHA"); | ||
| 8 | +/// Commit date (YYYY-MM-DD), or "unknown". | ||
| 9 | +pub const DATE: &str = env!("FORGE_GIT_DATE"); | ||
| 10 | +/// True when the tree had uncommitted changes to tracked files at build time. | ||
| 11 | +pub const DIRTY: bool = matches!(env!("FORGE_GIT_DIRTY").as_bytes(), b"1"); | ||
| 12 | + | ||
| 13 | +/// `0.1.0 (cf8e648, 2026-10-20)`, with `cf8e648-dirty` for a dirty tree. | ||
| 14 | +pub fn display() -> String { | ||
| 15 | + format_build(VERSION, COMMIT, DATE, DIRTY) | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +pub fn format_build(version: &str, commit: &str, date: &str, dirty: bool) -> String { | ||
| 19 | + let dirty = if dirty { "-dirty" } else { "" }; | ||
| 20 | + format!("{version} ({commit}{dirty}, {date})") | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +/// The commit sha out of a build string made by [`display`], `None` when it is unknown or the | ||
| 24 | +/// string is not in that shape. | ||
| 25 | +pub fn commit_of(build: &str) -> Option<&str> { | ||
| 26 | + let inner = build.split_once('(')?.1; | ||
| 27 | + let commit = inner.split([',', ')']).next()?.trim(); | ||
| 28 | + let commit = commit.strip_suffix("-dirty").unwrap_or(commit); | ||
| 29 | + (!commit.is_empty() && commit != "unknown").then_some(commit) | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +/// How a runner's build compares with the server's. | ||
| 33 | +#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| 34 | +pub enum Freshness { | ||
| 35 | + UpToDate, | ||
| 36 | + Outdated, | ||
| 37 | + /// The runner reported nothing usable (an old runner), or this server's own commit is unknown. | ||
| 38 | + Unknown, | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +/// Compares by commit, ignoring the dirty marker. | ||
| 42 | +pub fn compare(runner: Option<&str>, server: &str) -> Freshness { | ||
| 43 | + match (runner.and_then(commit_of), commit_of(server)) { | ||
| 44 | + (Some(r), Some(s)) if r == s => Freshness::UpToDate, | ||
| 45 | + (Some(_), Some(_)) => Freshness::Outdated, | ||
| 46 | + _ => Freshness::Unknown, | ||
| 47 | + } | ||
| 48 | +} | ||
| 49 | + | ||
| 50 | +#[cfg(test)] | ||
| 51 | +mod tests { | ||
| 52 | + use super::*; | ||
| 53 | + | ||
| 54 | + #[test] | ||
| 55 | + fn up_to_date_compares_the_commit_only() { | ||
| 56 | + let server = format_build("0.1.0", "cf8e648", "2026-10-20", false); | ||
| 57 | + assert_eq!(server, "0.1.0 (cf8e648, 2026-10-20)"); | ||
| 58 | + let same = format_build("0.1.0", "cf8e648", "2026-10-20", true); | ||
| 59 | + assert_eq!(compare(Some(&same), &server), Freshness::UpToDate); | ||
| 60 | + let older = format_build("0.1.0", "4d21658", "2026-10-19", false); | ||
| 61 | + assert_eq!(compare(Some(&older), &server), Freshness::Outdated); | ||
| 62 | + assert_eq!(compare(None, &server), Freshness::Unknown); | ||
| 63 | + assert_eq!(compare(Some("0.1.0"), &server), Freshness::Unknown); | ||
| 64 | + let unknown = format_build("0.1.0", "unknown", "unknown", false); | ||
| 65 | + assert_eq!(compare(Some(&same), &unknown), Freshness::Unknown); | ||
| 66 | + } | ||
| 67 | +} | ||
crates/forge-ci/src/lib.rsmodified+1 -0
| @@ -1,6 +1,7 @@ | |||
| 1 | //! CI workflow config (`.forge/ci.toml`), the runner protocol, and log masking. Shared by | 1 | //! CI workflow config (`.forge/ci.toml`), the runner protocol, and log masking. Shared by |
| 2 | //! forge-web and forge-runner. | 2 | //! forge-web and forge-runner. |
| 3 | 3 | ||
| 4 | +pub mod build; | ||
| 4 | pub mod config; | 5 | pub mod config; |
| 5 | pub mod cron; | 6 | pub mod cron; |
| 6 | pub mod error; | 7 | pub mod error; |
crates/forge-ci/src/proto.rsmodified+7 -0
| @@ -61,8 +61,14 @@ pub struct ClaimRequest { | |||
| 61 | /// Total memory of the runner's host, in bytes. | 61 | /// Total memory of the runner's host, in bytes. |
| 62 | #[serde(default, skip_serializing_if = "Option::is_none")] | 62 | #[serde(default, skip_serializing_if = "Option::is_none")] |
| 63 | pub memory_bytes: Option<u64>, | 63 | pub memory_bytes: Option<u64>, |
| 64 | + /// The runner's build identity (`0.1.0 (cf8e648, 2026-10-20)`). Absent from an older runner. | ||
| 65 | + #[serde(default, skip_serializing_if = "Option::is_none")] | ||
| 66 | + pub build: Option<String>, | ||
| 64 | } | 67 | } |
| 65 | 68 | ||
| 69 | +/// Request header on a heartbeat: the runner's build identity, same value as `ClaimRequest::build`. | ||
| 70 | +pub const BUILD_HEADER: &str = "Forge-Runner-Build"; | ||
| 71 | + | ||
| 66 | /// Response header on a claim: the concurrency an admin set for this runner in the web UI. Absent | 72 | /// Response header on a claim: the concurrency an admin set for this runner in the web UI. Absent |
| 67 | /// when there is no override, which means the runner uses the value from its own `runner.toml`. | 73 | /// when there is no override, which means the runner uses the value from its own `runner.toml`. |
| 68 | pub const CONCURRENCY_HEADER: &str = "Forge-Runner-Concurrency"; | 74 | pub const CONCURRENCY_HEADER: &str = "Forge-Runner-Concurrency"; |
| @@ -192,6 +198,7 @@ mod tests { | |||
| 192 | version: Some("1.0.0".into()), | 198 | version: Some("1.0.0".into()), |
| 193 | cpus: Some(8), | 199 | cpus: Some(8), |
| 194 | memory_bytes: Some(1 << 33), | 200 | memory_bytes: Some(1 << 33), |
| 201 | + build: Some("0.1.0 (cf8e648, 2026-10-20)".into()), | ||
| 195 | }; | 202 | }; |
| 196 | let back: ClaimRequest = | 203 | let back: ClaimRequest = |
| 197 | serde_json::from_str(&serde_json::to_string(&new).unwrap()).unwrap(); | 204 | serde_json::from_str(&serde_json::to_string(&new).unwrap()).unwrap(); |
crates/forge-core/migrations/0056_runner_build.sqladded+4 -0
| @@ -0,0 +1,4 @@ | |||
| 1 | +-- The build identity a runner last reported ("0.1.0 (cf8e648, 2026-10-20)"). NULL for a runner | ||
| 2 | +-- that does not report one. Applied by store/migrate.rs. | ||
| 3 | + | ||
| 4 | +ALTER TABLE ci_runners ADD COLUMN reported_build TEXT NULL; | ||
crates/forge-core/src/ci.rsmodified+2 -0
| @@ -340,6 +340,8 @@ pub struct RunnerReport { | |||
| 340 | pub version: Option<String>, | 340 | pub version: Option<String>, |
| 341 | pub cpus: Option<u32>, | 341 | pub cpus: Option<u32>, |
| 342 | pub memory_bytes: Option<u64>, | 342 | pub memory_bytes: Option<u64>, |
| 343 | + /// The runner's build identity, like `0.1.0 (cf8e648, 2026-10-20)`. | ||
| 344 | + pub build: Option<String>, | ||
| 343 | } | 345 | } |
| 344 | 346 | ||
| 345 | /// The smallest and largest concurrency an admin may set. | 347 | /// The smallest and largest concurrency an admin may set. |
crates/forge-core/src/store/ci.rsmodified+7 -2
| @@ -29,7 +29,8 @@ const RUN_COLS: &str = "id, repo_id, number, trigger, git_ref, commit_oid, pull_ | |||
| 29 | const RUNNER_COLS: &str = "id, name, labels, created_at, last_seen_at, disabled, \ | 29 | const RUNNER_COLS: &str = "id, name, labels, created_at, last_seen_at, disabled, \ |
| 30 | concurrency_override, reported_concurrency, reported_version, reported_cpus, \ | 30 | concurrency_override, reported_concurrency, reported_version, reported_cpus, \ |
| 31 | reported_memory_bytes, reported_config, config_overrides, \ | 31 | reported_memory_bytes, reported_config, config_overrides, \ |
| 32 | - (SELECT COUNT(*) FROM ci_jobs WHERE ci_jobs.runner_id = ci_runners.id AND ci_jobs.state = 'running')"; | 32 | + (SELECT COUNT(*) FROM ci_jobs WHERE ci_jobs.runner_id = ci_runners.id AND ci_jobs.state = 'running'), \ |
| 33 | + reported_build"; | ||
| 33 | const ARTIFACT_COLS: &str = "id, job_id, name, size, sha256, created_at"; | 34 | const ARTIFACT_COLS: &str = "id, job_id, name, size, sha256, created_at"; |
| 34 | 35 | ||
| 35 | /// Longest runner name, in bytes. | 36 | /// Longest runner name, in bytes. |
| @@ -76,6 +77,7 @@ fn map_runner(row: &Row) -> Result<CiRunner> { | |||
| 76 | version: col_opt_text(row, 8)?, | 77 | version: col_opt_text(row, 8)?, |
| 77 | cpus: opt_u32(row, 9)?, | 78 | cpus: opt_u32(row, 9)?, |
| 78 | memory_bytes: opt_int(row, 10)?.and_then(|n| u64::try_from(n).ok()), | 79 | memory_bytes: opt_int(row, 10)?.and_then(|n| u64::try_from(n).ok()), |
| 80 | + build: col_opt_text(row, 14)?, | ||
| 79 | }, | 81 | }, |
| 80 | running_jobs: opt_u32(row, 13)?.unwrap_or(0), | 82 | running_jobs: opt_u32(row, 13)?.unwrap_or(0), |
| 81 | reported_config: json_map(row, 11)?, | 83 | reported_config: json_map(row, 11)?, |
| @@ -725,19 +727,21 @@ impl Store { | |||
| 725 | version: report.version.clone().or(current.reported.version.clone()), | 727 | version: report.version.clone().or(current.reported.version.clone()), |
| 726 | cpus: report.cpus.or(current.reported.cpus), | 728 | cpus: report.cpus.or(current.reported.cpus), |
| 727 | memory_bytes: report.memory_bytes.or(current.reported.memory_bytes), | 729 | memory_bytes: report.memory_bytes.or(current.reported.memory_bytes), |
| 730 | + build: report.build.clone().or(current.reported.build.clone()), | ||
| 728 | }; | 731 | }; |
| 729 | if merged == current.reported { | 732 | if merged == current.reported { |
| 730 | return Ok(false); | 733 | return Ok(false); |
| 731 | } | 734 | } |
| 732 | conn.execute( | 735 | conn.execute( |
| 733 | "UPDATE ci_runners SET reported_concurrency = ?2, reported_version = ?3, \ | 736 | "UPDATE ci_runners SET reported_concurrency = ?2, reported_version = ?3, \ |
| 734 | - reported_cpus = ?4, reported_memory_bytes = ?5 WHERE id = ?1", | 737 | + reported_cpus = ?4, reported_memory_bytes = ?5, reported_build = ?6 WHERE id = ?1", |
| 735 | ( | 738 | ( |
| 736 | id.to_string(), | 739 | id.to_string(), |
| 737 | opt_int_value(merged.concurrency.map(i64::from)), | 740 | opt_int_value(merged.concurrency.map(i64::from)), |
| 738 | opt_text(merged.version.as_deref()), | 741 | opt_text(merged.version.as_deref()), |
| 739 | opt_int_value(merged.cpus.map(i64::from)), | 742 | opt_int_value(merged.cpus.map(i64::from)), |
| 740 | opt_int_value(merged.memory_bytes.and_then(|n| i64::try_from(n).ok())), | 743 | opt_int_value(merged.memory_bytes.and_then(|n| i64::try_from(n).ok())), |
| 744 | + opt_text(merged.build.as_deref()), | ||
| 741 | ), | 745 | ), |
| 742 | ) | 746 | ) |
| 743 | .await | 747 | .await |
| @@ -1903,6 +1907,7 @@ mod tests { | |||
| 1903 | version: Some("0.9.1".into()), | 1907 | version: Some("0.9.1".into()), |
| 1904 | cpus: Some(8), | 1908 | cpus: Some(8), |
| 1905 | memory_bytes: Some(16 << 30), | 1909 | memory_bytes: Some(16 << 30), |
| 1910 | + build: Some("0.1.0 (cf8e648, 2026-10-20)".into()), | ||
| 1906 | }; | 1911 | }; |
| 1907 | assert!( | 1912 | assert!( |
| 1908 | fx.store | 1913 | fx.store |
crates/forge-core/src/store/migrate.rsmodified+1 -0
| @@ -95,6 +95,7 @@ pub const MIGRATIONS: &[(u32, &str)] = &[ | |||
| 95 | 55, | 95 | 55, |
| 96 | include_str!("../../migrations/0055_user_suspensions.sql"), | 96 | include_str!("../../migrations/0055_user_suspensions.sql"), |
| 97 | ), | 97 | ), |
| 98 | + (56, include_str!("../../migrations/0056_runner_build.sql")), | ||
| 98 | ]; | 99 | ]; |
| 99 | 100 | ||
| 100 | /// The highest migration version this binary knows about. | 101 | /// The highest migration version this binary knows about. |
crates/forge-runner/src/cli.rsmodified+1 -1
| @@ -29,7 +29,7 @@ const GC_INTERVAL: Duration = Duration::from_secs(24 * 60 * 60); | |||
| 29 | #[derive(Parser)] | 29 | #[derive(Parser)] |
| 30 | #[command( | 30 | #[command( |
| 31 | name = "forge-runner", | 31 | name = "forge-runner", |
| 32 | - version, | 32 | + version = forge_ci::build::display(), |
| 33 | about = "Runs forge CI jobs in a rootless sandbox (builtin) or rootless podman" | 33 | about = "Runs forge CI jobs in a rootless sandbox (builtin) or rootless podman" |
| 34 | )] | 34 | )] |
| 35 | struct Cli { | 35 | struct Cli { |
crates/forge-runner/src/client.rsmodified+4 -2
| @@ -7,8 +7,8 @@ use std::path::Path; | |||
| 7 | use std::time::Duration; | 7 | use std::time::Duration; |
| 8 | 8 | ||
| 9 | use forge_ci::proto::{ | 9 | use forge_ci::proto::{ |
| 10 | - CONCURRENCY_HEADER, ClaimRequest, FinishRequest, HeartbeatResponse, JobAssignment, | 10 | + BUILD_HEADER, CONCURRENCY_HEADER, ClaimRequest, FinishRequest, HeartbeatResponse, |
| 11 | - RegisterRequest, RegisterResponse, RunnerConfigOverrides, RunnerConfigReport, | 11 | + JobAssignment, RegisterRequest, RegisterResponse, RunnerConfigOverrides, RunnerConfigReport, |
| 12 | }; | 12 | }; |
| 13 | use reqwest::StatusCode; | 13 | use reqwest::StatusCode; |
| 14 | use reqwest::header::{CONTENT_LENGTH, HeaderMap}; | 14 | use reqwest::header::{CONTENT_LENGTH, HeaderMap}; |
| @@ -125,6 +125,7 @@ impl ForgeClient { | |||
| 125 | version: Some(env!("CARGO_PKG_VERSION").to_owned()), | 125 | version: Some(env!("CARGO_PKG_VERSION").to_owned()), |
| 126 | cpus: host.cpus, | 126 | cpus: host.cpus, |
| 127 | memory_bytes: host.memory_bytes, | 127 | memory_bytes: host.memory_bytes, |
| 128 | + build: Some(forge_ci::build::display()), | ||
| 128 | }; | 129 | }; |
| 129 | let target = format!("{}-{}", std::env::consts::ARCH, std::env::consts::OS); | 130 | let target = format!("{}-{}", std::env::consts::ARCH, std::env::consts::OS); |
| 130 | let resp = self | 131 | let resp = self |
| @@ -272,6 +273,7 @@ impl ForgeClient { | |||
| 272 | if let Some(n) = concurrency { | 273 | if let Some(n) = concurrency { |
| 273 | req = req.header(CONCURRENCY_HEADER, n.to_string()); | 274 | req = req.header(CONCURRENCY_HEADER, n.to_string()); |
| 274 | } | 275 | } |
| 276 | + req = req.header(BUILD_HEADER, forge_ci::build::display()); | ||
| 275 | json_or_error(req.send().await?).await | 277 | json_or_error(req.send().await?).await |
| 276 | } | 278 | } |
| 277 | 279 | ||
crates/forge-runner/src/runner.rsmodified+1 -1
| @@ -255,7 +255,7 @@ impl Runner { | |||
| 255 | &tx, | 255 | &tx, |
| 256 | format!( | 256 | format!( |
| 257 | "forge-runner {}: job {} on runner {}, image {}, commit {}", | 257 | "forge-runner {}: job {} on runner {}, image {}, commit {}", |
| 258 | - env!("CARGO_PKG_VERSION"), | 258 | + forge_ci::build::display(), |
| 259 | job.job_name, | 259 | job.job_name, |
| 260 | self.config.name, | 260 | self.config.name, |
| 261 | job.image, | 261 | job.image, |
crates/forge-web/src/ci/api.rsmodified+9 -2
| @@ -9,8 +9,9 @@ | |||
| 9 | use forge_ci::config::JobSpec; | 9 | use forge_ci::config::JobSpec; |
| 10 | use forge_ci::mask::Masker; | 10 | use forge_ci::mask::Masker; |
| 11 | use forge_ci::proto::{ | 11 | use forge_ci::proto::{ |
| 12 | - CONCURRENCY_HEADER, ClaimRequest, FinishRequest, HeartbeatResponse, JobAssignment, Outcome, | 12 | + BUILD_HEADER, CONCURRENCY_HEADER, ClaimRequest, FinishRequest, HeartbeatResponse, |
| 13 | - RegisterRequest, RegisterResponse, RunnerConfigOverrides, RunnerConfigReport, | 13 | + JobAssignment, Outcome, RegisterRequest, RegisterResponse, RunnerConfigOverrides, |
| 14 | + RunnerConfigReport, | ||
| 14 | }; | 15 | }; |
| 15 | use forge_core::Error as CoreError; | 16 | use forge_core::Error as CoreError; |
| 16 | use forge_core::ci::{CiJob, CiRun, CiRunner, JobState, RunState, RunnerReport}; | 17 | use forge_core::ci::{CiJob, CiRun, CiRunner, JobState, RunState, RunnerReport}; |
| @@ -192,6 +193,7 @@ async fn claim(cx: &Cx, body: Body) -> topcoat::Result<Response> { | |||
| 192 | version: request.version.filter(|v| v.len() <= 64), | 193 | version: request.version.filter(|v| v.len() <= 64), |
| 193 | cpus: request.cpus, | 194 | cpus: request.cpus, |
| 194 | memory_bytes: request.memory_bytes, | 195 | memory_bytes: request.memory_bytes, |
| 196 | + build: request.build.filter(|v| v.len() <= 64), | ||
| 195 | }, | 197 | }, |
| 196 | ) | 198 | ) |
| 197 | .await; | 199 | .await; |
| @@ -515,6 +517,11 @@ async fn heartbeat(cx: &Cx) -> topcoat::Result<Response> { | |||
| 515 | runner_id, | 517 | runner_id, |
| 516 | &RunnerReport { | 518 | &RunnerReport { |
| 517 | concurrency: said, | 519 | concurrency: said, |
| 520 | + build: headers(cx) | ||
| 521 | + .get(BUILD_HEADER) | ||
| 522 | + .and_then(|v| v.to_str().ok()) | ||
| 523 | + .filter(|v| v.len() <= 64) | ||
| 524 | + .map(str::to_owned), | ||
| 518 | ..RunnerReport::default() | 525 | ..RunnerReport::default() |
| 519 | }, | 526 | }, |
| 520 | ) | 527 | ) |
crates/forge-web/src/ci/api_tests.rsmodified+62 -0
| @@ -1173,3 +1173,65 @@ fn cache_scope_needs_a_pull_number_for_pull_requests_and_a_known_trigger() { | |||
| 1173 | ); | 1173 | ); |
| 1174 | assert!(cache_scope("bogus", "refs/heads/main", None, None, "main").is_none()); | 1174 | assert!(cache_scope("bogus", "refs/heads/main", None, None, "main").is_none()); |
| 1175 | } | 1175 | } |
| 1176 | + | ||
| 1177 | +#[tokio::test] | ||
| 1178 | +async fn claim_and_heartbeat_store_the_runner_build() { | ||
| 1179 | + let env = bare(|_| {}).await; | ||
| 1180 | + let (_runner, secret) = runner(&env, &[]).await; | ||
| 1181 | + make_run(&env, "push", None, COMMIT, &[job("a", spec(&[], &[]))]).await; | ||
| 1182 | + | ||
| 1183 | + // An older runner sends no build: nothing is stored. | ||
| 1184 | + let old = claim(&env.router, &secret).await; | ||
| 1185 | + assert_eq!(old.status, 200); | ||
| 1186 | + assert_eq!( | ||
| 1187 | + env.store.list_runners().await.unwrap()[0].reported.build, | ||
| 1188 | + None | ||
| 1189 | + ); | ||
| 1190 | + let assignment = old.json(); | ||
| 1191 | + | ||
| 1192 | + // The claim body carries the build. | ||
| 1193 | + let body = serde_json::json!({ "labels": [], "build": "0.1.0 (cf8e648, 2026-10-20)" }); | ||
| 1194 | + send( | ||
| 1195 | + &env.router, | ||
| 1196 | + "POST", | ||
| 1197 | + "/api/v1/ci/runners/claim", | ||
| 1198 | + &[bearer(&secret)], | ||
| 1199 | + json_body(&body), | ||
| 1200 | + ) | ||
| 1201 | + .await; | ||
| 1202 | + assert_eq!( | ||
| 1203 | + env.store.list_runners().await.unwrap()[0] | ||
| 1204 | + .reported | ||
| 1205 | + .build | ||
| 1206 | + .as_deref(), | ||
| 1207 | + Some("0.1.0 (cf8e648, 2026-10-20)") | ||
| 1208 | + ); | ||
| 1209 | + | ||
| 1210 | + // The heartbeat header updates it, e.g. after the runner restarted on a new binary. | ||
| 1211 | + let uri = format!( | ||
| 1212 | + "/api/v1/ci/jobs/{}/heartbeat", | ||
| 1213 | + assignment["job_id"].as_str().unwrap() | ||
| 1214 | + ); | ||
| 1215 | + let token = assignment["job_token"].as_str().unwrap(); | ||
| 1216 | + send( | ||
| 1217 | + &env.router, | ||
| 1218 | + "POST", | ||
| 1219 | + &uri, | ||
| 1220 | + &[ | ||
| 1221 | + bearer(token), | ||
| 1222 | + ( | ||
| 1223 | + "Forge-Runner-Build", | ||
| 1224 | + "0.1.0 (4d21658, 2026-10-19)".to_owned(), | ||
| 1225 | + ), | ||
| 1226 | + ], | ||
| 1227 | + Vec::new(), | ||
| 1228 | + ) | ||
| 1229 | + .await; | ||
| 1230 | + assert_eq!( | ||
| 1231 | + env.store.list_runners().await.unwrap()[0] | ||
| 1232 | + .reported | ||
| 1233 | + .build | ||
| 1234 | + .as_deref(), | ||
| 1235 | + Some("0.1.0 (4d21658, 2026-10-19)") | ||
| 1236 | + ); | ||
| 1237 | +} | ||
crates/forge-web/src/main.rsmodified+1 -5
| @@ -147,11 +147,7 @@ async fn real_main() -> ExitCode { | |||
| 147 | let outcome: Result<(), BoxError> = match parts.as_slice() { | 147 | let outcome: Result<(), BoxError> = match parts.as_slice() { |
| 148 | [] | ["serve"] => serve(&config_path).await, | 148 | [] | ["serve"] => serve(&config_path).await, |
| 149 | ["--version"] => { | 149 | ["--version"] => { |
| 150 | - println!( | 150 | + println!("forge {}", forge_ci::build::display()); |
| 151 | - "forge {} {}", | ||
| 152 | - env!("CARGO_PKG_VERSION"), | ||
| 153 | - env!("FORGE_BUILD_SHA") | ||
| 154 | - ); | ||
| 155 | return ExitCode::SUCCESS; | 151 | return ExitCode::SUCCESS; |
| 156 | } | 152 | } |
| 157 | ["hook", stage] => hook_cmd::run(stage).await.map_err(Into::into), | 153 | ["hook", stage] => hook_cmd::run(stage).await.map_err(Into::into), |
crates/forge-web/src/pages/admin_health.rsmodified+7 -2
| @@ -271,8 +271,13 @@ async fn tiles(state: &AppState, lang: Lang, tz: &str) -> Result<Vec<Tile>> { | |||
| 271 | )); | 271 | )); |
| 272 | out.push(tile( | 272 | out.push(tile( |
| 273 | at(lang, A::Version), | 273 | at(lang, A::Version), |
| 274 | - env!("CARGO_PKG_VERSION"), | 274 | + forge_ci::build::VERSION, |
| 275 | - env!("FORGE_BUILD_SHA"), | 275 | + format!( |
| 276 | + "{}{}, {}", | ||
| 277 | + forge_ci::build::COMMIT, | ||
| 278 | + if forge_ci::build::DIRTY { "-dirty" } else { "" }, | ||
| 279 | + forge_ci::build::DATE | ||
| 280 | + ), | ||
| 276 | )); | 281 | )); |
| 277 | Ok(out) | 282 | Ok(out) |
| 278 | } | 283 | } |
crates/forge-web/src/pages/admin_runners.rsmodified+33 -0
| @@ -6,6 +6,7 @@ | |||
| 6 | //! only place the token ever appears. The list never shows a token. Creating a token and deleting a | 6 | //! only place the token ever appears. The list never shows a token. Creating a token and deleting a |
| 7 | //! runner are audited; the token itself is never written to the audit log. | 7 | //! runner are audited; the token itself is never written to the audit log. |
| 8 | 8 | ||
| 9 | +use forge_ci::build::{self, Freshness}; | ||
| 9 | use forge_core::AuditAction; | 10 | use forge_core::AuditAction; |
| 10 | use forge_core::ci::{CiRunner, FieldKind, RUNNER_FIELDS, runner_field}; | 11 | use forge_core::ci::{CiRunner, FieldKind, RUNNER_FIELDS, runner_field}; |
| 11 | use serde::Deserialize; | 12 | use serde::Deserialize; |
| @@ -132,6 +133,20 @@ struct RunnerRow { | |||
| 132 | concurrency_source: &'static str, | 133 | concurrency_source: &'static str, |
| 133 | has_override: bool, | 134 | has_override: bool, |
| 134 | running: u32, | 135 | running: u32, |
| 136 | + /// The build the runner reported, or empty for an older runner. | ||
| 137 | + build: String, | ||
| 138 | + /// "up to date", "outdated" or "unknown", with the `.ci-state` class that colours it. | ||
| 139 | + build_label: &'static str, | ||
| 140 | + build_class: &'static str, | ||
| 141 | +} | ||
| 142 | + | ||
| 143 | +/// How the runner's reported build compares with this server's, as a badge label and class. | ||
| 144 | +fn build_badge(lang: Lang, runner: &CiRunner) -> (&'static str, &'static str) { | ||
| 145 | + match build::compare(runner.reported.build.as_deref(), &build::display()) { | ||
| 146 | + Freshness::UpToDate => (s(lang, "up to date", "güncel"), "ci-success"), | ||
| 147 | + Freshness::Outdated => (s(lang, "outdated", "eski"), "ci-queued"), | ||
| 148 | + Freshness::Unknown => (s(lang, "unknown", "bilinmiyor"), "runner-disabled"), | ||
| 149 | + } | ||
| 135 | } | 150 | } |
| 136 | 151 | ||
| 137 | /// The effective concurrency as a number to show, and where it comes from. | 152 | /// The effective concurrency as a number to show, and where it comes from. |
| @@ -169,6 +184,7 @@ fn runner_row(runner: &CiRunner, tz: &str, lang: Lang, now: i64) -> RunnerRow { | |||
| 169 | None => (i18n::t(lang, Key::Never).to_owned(), String::new()), | 184 | None => (i18n::t(lang, Key::Never).to_owned(), String::new()), |
| 170 | }; | 185 | }; |
| 171 | let (concurrency, concurrency_source) = concurrency_of(runner); | 186 | let (concurrency, concurrency_source) = concurrency_of(runner); |
| 187 | + let (build_label, build_class) = build_badge(lang, runner); | ||
| 172 | RunnerRow { | 188 | RunnerRow { |
| 173 | name: runner.name.clone(), | 189 | name: runner.name.clone(), |
| 174 | labels: runner.labels.clone(), | 190 | labels: runner.labels.clone(), |
| @@ -183,6 +199,9 @@ fn runner_row(runner: &CiRunner, tz: &str, lang: Lang, now: i64) -> RunnerRow { | |||
| 183 | concurrency_source, | 199 | concurrency_source, |
| 184 | has_override: runner.concurrency_override.is_some(), | 200 | has_override: runner.concurrency_override.is_some(), |
| 185 | running: runner.running_jobs, | 201 | running: runner.running_jobs, |
| 202 | + build: runner.reported.build.clone().unwrap_or_default(), | ||
| 203 | + build_label, | ||
| 204 | + build_class, | ||
| 186 | } | 205 | } |
| 187 | } | 206 | } |
| 188 | 207 | ||
| @@ -246,6 +265,7 @@ async fn runners_view( | |||
| 246 | <th class="runner-labels">(g::t(lang, K::TableLabels))</th> | 265 | <th class="runner-labels">(g::t(lang, K::TableLabels))</th> |
| 247 | <th class="runner-conc">(s(lang, "Concurrency", "Eşzamanlılık"))</th> | 266 | <th class="runner-conc">(s(lang, "Concurrency", "Eşzamanlılık"))</th> |
| 248 | <th class="runner-running">(s(lang, "Running", "Çalışan"))</th> | 267 | <th class="runner-running">(s(lang, "Running", "Çalışan"))</th> |
| 268 | + <th class="runner-build">(s(lang, "Version", "Sürüm"))</th> | ||
| 249 | <th class="runner-seen">(g::t(lang, K::LastSeen))</th> | 269 | <th class="runner-seen">(g::t(lang, K::LastSeen))</th> |
| 250 | <th class="runner-state">(g::t(lang, K::TableState))</th> | 270 | <th class="runner-state">(g::t(lang, K::TableState))</th> |
| 251 | <th class="runner-actions"></th> | 271 | <th class="runner-actions"></th> |
| @@ -266,6 +286,12 @@ async fn runners_view( | |||
| 266 | concurrency_form(lang: lang, csrf: csrf.as_str(), action: row.config_action.as_str(), key: "concurrency", value: row.concurrency.as_str(), source: row.concurrency_source, has_override: row.has_override, back: "list") | 286 | concurrency_form(lang: lang, csrf: csrf.as_str(), action: row.config_action.as_str(), key: "concurrency", value: row.concurrency.as_str(), source: row.concurrency_source, has_override: row.has_override, back: "list") |
| 267 | </td> | 287 | </td> |
| 268 | <td class="runner-running small">(row.running.to_string())</td> | 288 | <td class="runner-running small">(row.running.to_string())</td> |
| 289 | + <td class="runner-build small"> | ||
| 290 | + if !row.build.is_empty() { | ||
| 291 | + <span>(row.build.as_str())</span> | ||
| 292 | + } | ||
| 293 | + <span class=(format!("ci-state {}", row.build_class))>(row.build_label)</span> | ||
| 294 | + </td> | ||
| 269 | <td class="runner-seen small" title=(row.last_seen_full.as_str())>(row.last_seen.as_str())</td> | 295 | <td class="runner-seen small" title=(row.last_seen_full.as_str())>(row.last_seen.as_str())</td> |
| 270 | <td class="runner-state"> | 296 | <td class="runner-state"> |
| 271 | if row.disabled { | 297 | if row.disabled { |
| @@ -631,6 +657,13 @@ async fn runner_detail_view( | |||
| 631 | <dl class="runner-facts"> | 657 | <dl class="runner-facts"> |
| 632 | <dt>(s(lang, "Running jobs", "Çalışan işler"))</dt><dd>(row.running.to_string())</dd> | 658 | <dt>(s(lang, "Running jobs", "Çalışan işler"))</dt><dd>(row.running.to_string())</dd> |
| 633 | <dt>(g::t(lang, K::LastSeen))</dt><dd title=(row.last_seen_full.as_str())>(row.last_seen.as_str())</dd> | 659 | <dt>(g::t(lang, K::LastSeen))</dt><dd title=(row.last_seen_full.as_str())>(row.last_seen.as_str())</dd> |
| 660 | + <dt>(s(lang, "Build", "Derleme"))</dt> | ||
| 661 | + <dd> | ||
| 662 | + if !row.build.is_empty() { | ||
| 663 | + <span>(row.build.as_str())</span> | ||
| 664 | + } | ||
| 665 | + <span class=(format!("ci-state {}", row.build_class))>(row.build_label)</span> | ||
| 666 | + </dd> | ||
| 634 | if !host_version.is_empty() { | 667 | if !host_version.is_empty() { |
| 635 | <dt>(s(lang, "Runner version", "Çalıştırıcı sürümü"))</dt><dd>(host_version.as_str())</dd> | 668 | <dt>(s(lang, "Runner version", "Çalıştırıcı sürümü"))</dt><dd>(host_version.as_str())</dd> |
| 636 | } | 669 | } |
crates/forge-web/src/pages/admin_server.rsmodified+1 -0
| @@ -177,6 +177,7 @@ async fn server_view( | |||
| 177 | <section class="page-head"> | 177 | <section class="page-head"> |
| 178 | <h1>(g::t(lang, K::ServerSettings))</h1> | 178 | <h1>(g::t(lang, K::ServerSettings))</h1> |
| 179 | <p class="muted">(g::t(lang, K::ServerSettingsIntro))</p> | 179 | <p class="muted">(g::t(lang, K::ServerSettingsIntro))</p> |
| 180 | + <p class="muted small">(match lang { Lang::Tr => "Sürüm", _ => "Version" }) " " (forge_ci::build::display())</p> | ||
| 180 | </section> | 181 | </section> |
| 181 | <nav class="subnav" aria-label=(g::t(lang, K::ServerSettings))> | 182 | <nav class="subnav" aria-label=(g::t(lang, K::ServerSettings))> |
| 182 | for g_tab in Group::ALL.into_iter() { | 183 | for g_tab in Group::ALL.into_iter() { |