From df764591b928105b4023145351caa91d8d017b29 Mon Sep 17 00:00:00 2001 From: Cleboost Date: Mon, 25 May 2026 15:06:13 +0200 Subject: [PATCH 1/6] build(dashboard): implement caching for dashboard downloads --- src/dashboard/build.rs | 134 ++++++++++++++++++++++++++--------------- 1 file changed, 84 insertions(+), 50 deletions(-) diff --git a/src/dashboard/build.rs b/src/dashboard/build.rs index fa2e0d0c..c0b61ffb 100644 --- a/src/dashboard/build.rs +++ b/src/dashboard/build.rs @@ -3,6 +3,7 @@ use std::env; use std::fs; use std::io::{Cursor, Write}; use std::path::Path; +use std::time::SystemTime; use zip::ZipArchive; // CONFIGURATION @@ -16,6 +17,9 @@ fn main() -> Result<()> { println!("cargo::rustc-check-cfg=cfg(dashboard_in_manifest_dir)"); println!("cargo::rustc-check-cfg=cfg(dashboard_build)"); + // Rerun if the force download environment variable changes + println!("cargo:rerun-if-env-changed=TEMPER_FORCE_DASHBOARD_DOWNLOAD"); + // 1. Determine where to put the files. let (dest_dir, use_out_dir) = if let Ok(out_dir) = env::var("OUT_DIR") { let out_path = Path::new(&out_dir); @@ -38,67 +42,97 @@ fn main() -> Result<()> { println!("cargo:rustc-cfg=dashboard_in_manifest_dir"); } - // 2. Always attempt to download the dashboard - println!( - "cargo:warning=Downloading Dashboard artifact from {}", - DASHBOARD_URL - ); - - let client = reqwest::blocking::Client::new(); - let download_result = client - .get(DASHBOARD_URL) - .header("User-Agent", "temper-build-script") - .send(); - - match download_result { - Ok(response) if response.status().is_success() => { - // Delete existing directory if it exists - if dest_dir.exists() { - fs::remove_dir_all(&dest_dir)?; + // 2. Check cache age to avoid downloading on every single compile. + let force_download = env::var("TEMPER_FORCE_DASHBOARD_DOWNLOAD").is_ok(); + let index_html = dest_dir.join("index.html"); + + let has_recent_dashboard = if index_html.exists() { + if let Ok(metadata) = fs::metadata(&index_html) { + if let Ok(modified) = metadata.modified() { + if let Ok(elapsed) = SystemTime::now().duration_since(modified) { + // Cache threshold: 24 hours (86,400 seconds) + elapsed.as_secs() < 86400 + } else { + false + } + } else { + false } + } else { + false + } + } else { + false + }; + + let should_download = force_download || !has_recent_dashboard; - let content = response.bytes()?; + if should_download { + println!( + "Downloading Dashboard artifact from {}", + DASHBOARD_URL + ); - // Extract the zip file - let cursor = Cursor::new(content); - let mut archive = ZipArchive::new(cursor)?; + let client = reqwest::blocking::Client::new(); + let download_result = client + .get(DASHBOARD_URL) + .header("User-Agent", "temper-build-script") + .send(); - // Create the destination directory - fs::create_dir_all(&dest_dir)?; + match download_result { + Ok(response) if response.status().is_success() => { + // Delete existing directory if it exists + if dest_dir.exists() { + fs::remove_dir_all(&dest_dir)?; + } - // Extract all files - for i in 0..archive.len() { - let mut file = archive.by_index(i)?; - let outpath = dest_dir.join(file.mangled_name()?); + let content = response.bytes()?; - if file.is_dir() { - fs::create_dir_all(&outpath)?; - } else { - if let Some(parent) = outpath.parent() { - fs::create_dir_all(parent)?; + // Extract the zip file + let cursor = Cursor::new(content); + let mut archive = ZipArchive::new(cursor)?; + + // Create the destination directory + fs::create_dir_all(&dest_dir)?; + + // Extract all files + for i in 0..archive.len() { + let mut file = archive.by_index(i)?; + let outpath = dest_dir.join(file.mangled_name()?); + + if file.is_dir() { + fs::create_dir_all(&outpath)?; + } else { + if let Some(parent) = outpath.parent() { + fs::create_dir_all(parent)?; + } + let mut outfile = fs::File::create(&outpath)?; + std::io::copy(&mut file, &mut outfile)?; } - let mut outfile = fs::File::create(&outpath)?; - std::io::copy(&mut file, &mut outfile)?; } - } - println!("cargo:warning=Dashboard extracted to {:?}", dest_dir); - } - _ => { - // Download failed (no internet, request error, non-success status) - if dest_dir.exists() { - // Use existing dashboard files - println!("cargo:warning=Download failed, using existing dashboard files."); - } else { - // Create fallback HTML - println!( - "cargo:warning=Download failed and no existing dashboard. Creating fallback." - ); - fs::create_dir_all(&dest_dir)?; - let mut file = fs::File::create(dest_dir.join("index.html"))?; - file.write_all(b"

Dashboard Offline (Build failed to fetch)

")?; + println!("Dashboard extracted to {:?}", dest_dir); + } + _ => { + // Download failed (no internet, request error, non-success status) + if dest_dir.exists() { + // Use existing dashboard files + println!("cargo:warning=Download failed, using existing dashboard files."); + } else { + // Create fallback HTML + println!( + "cargo:warning=Download failed and no existing dashboard. Creating fallback." + ); + fs::create_dir_all(&dest_dir)?; + let mut file = fs::File::create(dest_dir.join("index.html"))?; + file.write_all(b"

Dashboard Offline (Build failed to fetch)

")?; + } } } + } else { + println!( + "Using cached Dashboard (last downloaded <24h ago). Set TEMPER_FORCE_DASHBOARD_DOWNLOAD=1 to force update." + ); } // Emit a cfg flag so the main code knows build.rs ran From 34a0d19e971708c7eab63f319716a18a664ade62 Mon Sep 17 00:00:00 2001 From: Cleboost Date: Mon, 25 May 2026 15:16:05 +0200 Subject: [PATCH 2/6] perf(dashboard): add 24h caching and force-download override to build.rs --- src/dashboard/build.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/dashboard/build.rs b/src/dashboard/build.rs index c0b61ffb..a1dd2165 100644 --- a/src/dashboard/build.rs +++ b/src/dashboard/build.rs @@ -45,7 +45,7 @@ fn main() -> Result<()> { // 2. Check cache age to avoid downloading on every single compile. let force_download = env::var("TEMPER_FORCE_DASHBOARD_DOWNLOAD").is_ok(); let index_html = dest_dir.join("index.html"); - + let has_recent_dashboard = if index_html.exists() { if let Ok(metadata) = fs::metadata(&index_html) { if let Ok(modified) = metadata.modified() { @@ -69,7 +69,7 @@ fn main() -> Result<()> { if should_download { println!( - "Downloading Dashboard artifact from {}", + "cargo:warning=Downloading Dashboard artifact from {}", DASHBOARD_URL ); @@ -111,7 +111,7 @@ fn main() -> Result<()> { } } - println!("Dashboard extracted to {:?}", dest_dir); + println!("cargo:warning=Dashboard extracted to {:?}", dest_dir); } _ => { // Download failed (no internet, request error, non-success status) @@ -131,7 +131,7 @@ fn main() -> Result<()> { } } else { println!( - "Using cached Dashboard (last downloaded <24h ago). Set TEMPER_FORCE_DASHBOARD_DOWNLOAD=1 to force update." + "cargo:warning=Using cached Dashboard (last downloaded <24h ago). Set TEMPER_FORCE_DASHBOARD_DOWNLOAD=1 to force update." ); } From c7cfb1ba42a04e04da697cadb1889b1e3937f865 Mon Sep 17 00:00:00 2001 From: Cleboost Date: Tue, 26 May 2026 18:59:15 +0200 Subject: [PATCH 3/6] ci: force dashboard download in all workflows --- .github/workflows/release.yml | 1 + .github/workflows/rust.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 79f03617..25494030 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,6 +10,7 @@ permissions: env: CARGO_TERM_COLOR: always + TEMPER_FORCE_DASHBOARD_DOWNLOAD: "1" defaults: run: diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 3e612319..0b07556c 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -13,6 +13,7 @@ concurrency: env: CARGO_TERM_COLOR: always + TEMPER_FORCE_DASHBOARD_DOWNLOAD: "1" defaults: run: From a5f2653622baa058774a9db2a92a474e24a23bd5 Mon Sep 17 00:00:00 2001 From: Cleboost Date: Tue, 26 May 2026 19:08:15 +0200 Subject: [PATCH 4/6] refactor(dashboard): flatten nested if-else in build.rs --- src/dashboard/build.rs | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/src/dashboard/build.rs b/src/dashboard/build.rs index a1dd2165..2c6736f3 100644 --- a/src/dashboard/build.rs +++ b/src/dashboard/build.rs @@ -46,23 +46,11 @@ fn main() -> Result<()> { let force_download = env::var("TEMPER_FORCE_DASHBOARD_DOWNLOAD").is_ok(); let index_html = dest_dir.join("index.html"); - let has_recent_dashboard = if index_html.exists() { - if let Ok(metadata) = fs::metadata(&index_html) { - if let Ok(modified) = metadata.modified() { - if let Ok(elapsed) = SystemTime::now().duration_since(modified) { - // Cache threshold: 24 hours (86,400 seconds) - elapsed.as_secs() < 86400 - } else { - false - } - } else { - false - } - } else { - false - } - } else { - false + let has_recent_dashboard = 'check: { + let Ok(metadata) = fs::metadata(&index_html) else { break 'check false }; + let Ok(modified) = metadata.modified() else { break 'check false }; + let Ok(elapsed) = SystemTime::now().duration_since(modified) else { break 'check false }; + elapsed.as_secs() < 86_400 }; let should_download = force_download || !has_recent_dashboard; @@ -102,13 +90,13 @@ fn main() -> Result<()> { if file.is_dir() { fs::create_dir_all(&outpath)?; - } else { - if let Some(parent) = outpath.parent() { - fs::create_dir_all(parent)?; - } - let mut outfile = fs::File::create(&outpath)?; - std::io::copy(&mut file, &mut outfile)?; + continue; + } + if let Some(parent) = outpath.parent() { + fs::create_dir_all(parent)?; } + let mut outfile = fs::File::create(&outpath)?; + std::io::copy(&mut file, &mut outfile)?; } println!("cargo:warning=Dashboard extracted to {:?}", dest_dir); From ff979c1ffec7130610c9f49f1329d51f9b6f54ba Mon Sep 17 00:00:00 2001 From: Cleboost Date: Tue, 26 May 2026 19:14:47 +0200 Subject: [PATCH 5/6] style(dashboard): cargo fmt --- src/dashboard/build.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/dashboard/build.rs b/src/dashboard/build.rs index 2c6736f3..d8df8b0a 100644 --- a/src/dashboard/build.rs +++ b/src/dashboard/build.rs @@ -47,9 +47,15 @@ fn main() -> Result<()> { let index_html = dest_dir.join("index.html"); let has_recent_dashboard = 'check: { - let Ok(metadata) = fs::metadata(&index_html) else { break 'check false }; - let Ok(modified) = metadata.modified() else { break 'check false }; - let Ok(elapsed) = SystemTime::now().duration_since(modified) else { break 'check false }; + let Ok(metadata) = fs::metadata(&index_html) else { + break 'check false; + }; + let Ok(modified) = metadata.modified() else { + break 'check false; + }; + let Ok(elapsed) = SystemTime::now().duration_since(modified) else { + break 'check false; + }; elapsed.as_secs() < 86_400 }; From 8a2b6d6e3bf36cfc9cdefe31c7886eb4825a1c7f Mon Sep 17 00:00:00 2001 From: Cleboost Date: Wed, 27 May 2026 11:28:04 +0200 Subject: [PATCH 6/6] build(dashboard): follow force download convention and add request timeout --- src/dashboard/build.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/dashboard/build.rs b/src/dashboard/build.rs index d8df8b0a..fa74d6e8 100644 --- a/src/dashboard/build.rs +++ b/src/dashboard/build.rs @@ -43,7 +43,9 @@ fn main() -> Result<()> { } // 2. Check cache age to avoid downloading on every single compile. - let force_download = env::var("TEMPER_FORCE_DASHBOARD_DOWNLOAD").is_ok(); + let force_download = env::var("TEMPER_FORCE_DASHBOARD_DOWNLOAD") + .map(|v| v == "1") + .unwrap_or(false); let index_html = dest_dir.join("index.html"); let has_recent_dashboard = 'check: { @@ -67,7 +69,9 @@ fn main() -> Result<()> { DASHBOARD_URL ); - let client = reqwest::blocking::Client::new(); + let client = reqwest::blocking::Client::builder() + .timeout(std::time::Duration::from_secs(10)) + .build()?; let download_result = client .get(DASHBOARD_URL) .header("User-Agent", "temper-build-script")