From 68746208e12d19e4654d5e52409beabc74084491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Tue, 5 Mar 2024 00:36:35 +0100 Subject: [PATCH] simplify website --- src/main.rs | 14 +++++++------- src/percy.rs | 45 ++++++++++++++++++++++++++++++++++--------- templates/index.html | 17 ++++------------ templates/macros.html | 7 +++---- 4 files changed, 50 insertions(+), 33 deletions(-) diff --git a/src/main.rs b/src/main.rs index fe500f87..132bb9a4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,7 @@ use std::{ }; use tera::{Context, Tera}; -use crate::percy::ScreenshotData; +use crate::percy::{ScreenshotData, ScreenshotState}; mod percy; @@ -39,7 +39,7 @@ struct Run { date: String, commit: String, results: HashMap>, - screenshots: HashMap>, + screenshots: HashMap>, logs: HashMap>, } @@ -58,7 +58,7 @@ fn main() { folders.sort(); folders.reverse(); - for (i, run_path) in folders.iter().take(40).enumerate() { + for (i, run_path) in folders.iter().take(30).enumerate() { let file_name = run_path.file_name().unwrap().to_str().unwrap(); if file_name.starts_with(".") { continue; @@ -110,7 +110,7 @@ fn main() { let screenshots = read_percy_results(fs::read_to_string(file.as_ref().unwrap().path()).unwrap()); // sleep to limit how hard Percy API are used - thread::sleep(Duration::from_secs(3)); + thread::sleep(Duration::from_secs(1)); for ScreenshotData { example, screenshot, @@ -137,19 +137,19 @@ fn main() { name, flaky: false, }; - if changed != "no_diffs" { + if changed == ScreenshotState::Changed { let previous = all_examples.take(&example).unwrap_or(example.clone()); all_examples.insert(Example { flaky: true, ..previous }); } - if diff_ratio == 0.0 && changed != "no_diffs" { + if diff_ratio == 0.0 && changed == ScreenshotState::Changed { println!( " - setting {} / {} ({:?}) as unchanged", example.category, example.name, tag ); - changed = "no_diffs".to_string(); + changed = ScreenshotState::Similar; } // If there is a screenshot but no results, mark as success run.results diff --git a/src/percy.rs b/src/percy.rs index ab258ecd..383176b4 100644 --- a/src/percy.rs +++ b/src/percy.rs @@ -1,6 +1,6 @@ use std::{thread, time::Duration}; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; #[derive(Deserialize, Debug)] #[serde(rename_all = "kebab-case")] @@ -99,7 +99,7 @@ fn snapshots_to_images(snapshots: SnapshotsData, build_url: &str) -> Vec Vec Vec Vec, pub diff_ratio: f32, pub snapshot_url: String, } + +impl From<&ReviewStateReason> for ScreenshotState { + fn from(reason: &ReviewStateReason) -> Self { + match reason { + ReviewStateReason::NoDiffs => ScreenshotState::Similar, + _ => ScreenshotState::Changed, + } + } +} + +#[derive(Debug, Deserialize, PartialEq, Eq, Clone, Copy, Serialize)] +pub enum ScreenshotState { + Similar, + Changed, +} diff --git a/templates/index.html b/templates/index.html index 5e880987..5779b510 100644 --- a/templates/index.html +++ b/templates/index.html @@ -94,13 +94,7 @@ color: var(--bs-success-text-emphasis); } - .changed-approved::before { - content: '\f005'; - font: var(--fa-font-regular); - color: var(--bs-info-text-emphasis); - } - - .changed-new::before { + .changed::before { content: '\f005'; font: var(--fa-font-solid); color: var(--bs-warning-text-emphasis); @@ -244,20 +238,17 @@
- Example ran successfully, screenshot available -
-
- Error running the example + Example ran successfully, screenshot didn't change
Example ran successfully, but couldn't capture a screenshot
- Screenshot changed and has been approved + Example ran successfully, screenshot changed
- Screenshot changed and has not been approved yet + Error running the example