Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: validation of bundled themes in build workflow #11627

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install stable toolchain
uses: dtolnay/rust-toolchain@1.70

Expand Down Expand Up @@ -107,6 +108,9 @@ jobs:
- name: Validate queries
run: cargo xtask query-check

- name: Validate themes
run: cargo xtask theme-check

- name: Generate docs
run: cargo xtask docgen

Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ helix-core = { path = "../helix-core" }
helix-view = { path = "../helix-view" }
helix-loader = { path = "../helix-loader" }
toml = "0.8"
log = "~0.4"
once_cell = "1.19"
7 changes: 7 additions & 0 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod docgen;
mod helpers;
mod path;
mod querycheck;
mod theme_check;

use std::{env, error::Error};

Expand All @@ -11,6 +12,7 @@ pub mod tasks {
use crate::docgen::{lang_features, typable_commands, write};
use crate::docgen::{LANG_SUPPORT_MD_OUTPUT, TYPABLE_COMMANDS_MD_OUTPUT};
use crate::querycheck::query_check;
use crate::theme_check::theme_check;
use crate::DynError;

pub fn docgen() -> Result<(), DynError> {
Expand All @@ -23,6 +25,10 @@ pub mod tasks {
query_check()
}

pub fn themecheck() -> Result<(), DynError> {
theme_check()
}

pub fn print_help() {
println!(
"
Expand All @@ -43,6 +49,7 @@ fn main() -> Result<(), DynError> {
Some(t) => match t.as_str() {
"docgen" => tasks::docgen()?,
"query-check" => tasks::querycheck()?,
"theme-check" => tasks::themecheck()?,
invalid => return Err(format!("Invalid task name: {}", invalid).into()),
},
};
Expand Down
10 changes: 9 additions & 1 deletion xtask/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ pub fn book_gen() -> PathBuf {
project_root().join("book/src/generated/")
}

pub fn runtime() -> PathBuf {
project_root().join("runtime")
}

pub fn ts_queries() -> PathBuf {
project_root().join("runtime/queries")
runtime().join("queries")
}

pub fn themes() -> PathBuf {
runtime().join("themes")
}

pub fn lang_config() -> PathBuf {
Expand Down
70 changes: 70 additions & 0 deletions xtask/src/theme_check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
use std::sync::{Arc, Mutex};

use helix_view::theme::Loader;

use crate::{path, DynError};
use once_cell::sync::Lazy;

static LOGGER: Lazy<MockLog> = Lazy::new(MockLog::new);

pub fn theme_check() -> Result<(), DynError> {
log::set_logger(&*LOGGER).unwrap();
log::set_max_level(log::LevelFilter::Warn);

let theme_names = Loader::read_names(&path::themes());
let loader = Loader::new(&[path::runtime()]);

let mut issues_found = false;
for name in theme_names {
let _ = loader.load(&name).unwrap();

{
let warnings = LOGGER.warnings.lock().unwrap();
if !warnings.is_empty() {
issues_found = true;

println!("Theme '{name}' loaded with warnings:");
for warning in warnings.iter() {
println!("{warning}");
}
}
}

LOGGER.clear();
}
match issues_found {
true => Err("Issues found in bundled themes".to_string().into()),
false => Ok(()),
}
}

struct MockLog {
warnings: Arc<Mutex<Vec<String>>>,
}

impl MockLog {
pub fn new() -> Self {
MockLog {
warnings: Arc::new(Mutex::new(Vec::new())),
}
}

pub fn clear(&self) {
let mut warnings = self.warnings.lock().unwrap();
warnings.clear();
}
}

impl log::Log for MockLog {
fn enabled(&self, _metadata: &log::Metadata) -> bool {
true
}

fn log(&self, record: &log::Record) {
let mut warnings = self.warnings.lock().unwrap();
warnings.push(record.args().to_string());
}

fn flush(&self) { // Do nothing
}
}