From 7f1702bc287be76df9b1090a8edead1abb6484a5 Mon Sep 17 00:00:00 2001 From: Noratrieb <48135649+Noratrieb@users.noreply.github.com> Date: Fri, 4 Jul 2025 22:47:06 +0200 Subject: [PATCH] Store more metadata And other various improvements --- build.rs | 6 ++++++ .../20250704201048_more-build-metadata.sql | 10 +++++++++ src/build.rs | 14 ++++++++++++- src/db.rs | 11 ++++++++-- src/main.rs | 1 + src/web.rs | 16 ++++++++++++++ static/index.js | 9 ++++++++ templates/build.html | 21 +++++++------------ templates/index.html | 14 +------------ templates/nightly.html | 14 +------------ templates/target.html | 14 +------------ 11 files changed, 75 insertions(+), 55 deletions(-) create mode 100644 migrations/20250704201048_more-build-metadata.sql diff --git a/build.rs b/build.rs index ba68507..945d25a 100644 --- a/build.rs +++ b/build.rs @@ -12,6 +12,12 @@ fn main() { }; println!("cargo:rustc-env=GIT_COMMIT={version}"); + let version_short = if version.len() > 16 { + &version[..16] + } else { + &version + }; + println!("cargo:rustc-env=GIT_COMMIT_SHORT={version_short}"); } fn try_get_commit() -> color_eyre::Result { diff --git a/migrations/20250704201048_more-build-metadata.sql b/migrations/20250704201048_more-build-metadata.sql new file mode 100644 index 0000000..d690276 --- /dev/null +++ b/migrations/20250704201048_more-build-metadata.sql @@ -0,0 +1,10 @@ +-- Add migration script here + +ALTER TABLE "build_info" + ADD COLUMN "build_date" INTEGER NULL; + +ALTER TABLE "build_info" + ADD COLUMN "build_duration_ms" INTEGER NULL; + +ALTER TABLE "build_info" + ADD COLUMN "does_it_build_version" VARCHAR NULL; diff --git a/src/build.rs b/src/build.rs index e2d35f2..e5e4949 100644 --- a/src/build.rs +++ b/src/build.rs @@ -2,7 +2,7 @@ use std::{ fmt::{Debug, Display}, num::NonZeroUsize, path::Path, - time::Duration, + time::{Duration, Instant, SystemTime}, }; use color_eyre::{ @@ -242,6 +242,8 @@ async fn build_single_target(db: &Db, nightly: &str, target: &str, mode: BuildMo let tmpdir = tempfile::tempdir().wrap_err("creating temporary directory")?; + let start_time = Instant::now(); + let result = build_target( tmpdir.path(), &Toolchain::from_nightly(nightly), @@ -258,6 +260,16 @@ async fn build_single_target(db: &Db, nightly: &str, target: &str, mode: BuildMo stderr: result.stderr, mode, rustflags: result.rustflags, + build_date: Some( + SystemTime::now() + .duration_since(SystemTime::UNIX_EPOCH) + .unwrap() + .as_millis() + .try_into() + .unwrap(), + ), + does_it_build_version: Some(crate::VERSION_SHORT.into()), + build_duration_ms: Some(start_time.elapsed().as_millis().try_into().unwrap()), }) .await?; diff --git a/src/db.rs b/src/db.rs index ad7990c..4bc3b58 100644 --- a/src/db.rs +++ b/src/db.rs @@ -49,6 +49,9 @@ pub struct FullBuildInfo { pub stderr: String, pub mode: BuildMode, pub rustflags: Option, + pub build_date: Option, + pub does_it_build_version: Option, + pub build_duration_ms: Option, } #[derive(Debug, PartialEq, Clone, Copy, sqlx::Type, Serialize, Deserialize)] @@ -107,7 +110,8 @@ impl Db { pub async fn insert(&self, info: FullBuildInfo) -> Result<()> { sqlx::query( - "INSERT INTO build_info (nightly, target, status, stderr, mode, rustflags) VALUES (?, ?, ?, ?, ?, ?);", + "INSERT INTO build_info (nightly, target, status, stderr, mode, rustflags, build_date, does_it_build_version, build_duration_ms) \ + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);", ) .bind(info.nightly) .bind(info.target) @@ -115,6 +119,9 @@ impl Db { .bind(info.stderr) .bind(info.mode) .bind(info.rustflags) + .bind(info.build_date) + .bind(info.does_it_build_version) + .bind(info.build_duration_ms) .execute(&self.conn) .await .wrap_err("inserting build info into database")?; @@ -214,7 +221,7 @@ impl Db { mode: BuildMode, ) -> Result> { let result = sqlx::query_as::<_, FullBuildInfo>( - "SELECT nightly, target, status, stderr, mode, rustflags FROM build_info + "SELECT nightly, target, status, stderr, mode, rustflags, build_date, does_it_build_version, build_duration_ms FROM build_info WHERE nightly = ? AND target = ? AND mode = ?", ) .bind(nightly) diff --git a/src/main.rs b/src/main.rs index 5a46bc3..0619c77 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,7 @@ use db::Db; use tracing_subscriber::EnvFilter; const VERSION: &str = env!("GIT_COMMIT"); +const VERSION_SHORT: &str = env!("GIT_COMMIT_SHORT"); #[tokio::main] async fn main() -> Result<()> { diff --git a/src/web.rs b/src/web.rs index e32c047..f52fdeb 100644 --- a/src/web.rs +++ b/src/web.rs @@ -53,6 +53,9 @@ async fn web_build(State(state): State, Query(query): Query, version: &'static str, status: Status, + build_date: Option, + build_duration_s: Option, + does_it_build_version: Option, } match state @@ -73,6 +76,19 @@ async fn web_build(State(state): State, Query(query): Query { elem.textContent = new Intl.NumberFormat().format(Number(elem.textContent)); }); + +// Do some fancy date formatting in your locale, so you can't blame me if the numbers look ass. +document.querySelectorAll(".date").forEach((elem) => { + console.log("run") + elem.textContent = new Intl.DateTimeFormat(undefined, { + dateStyle: "short", + timeStyle: "short", + }).format(new Date(elem.textContent)); +}); diff --git a/templates/build.html b/templates/build.html index 4e28ced..fb90738 100644 --- a/templates/build.html +++ b/templates/build.html @@ -5,6 +5,7 @@ Build {{nightly}} {{target}} +