diff options
Diffstat (limited to 'dev_tools/src/bin')
| -rw-r--r-- | dev_tools/src/bin/ci.rs | 95 | ||||
| -rw-r--r-- | dev_tools/src/bin/docs-code-box-fix.rs | 13 | ||||
| -rw-r--r-- | dev_tools/src/bin/docsify-sidebar-gen.rs | 8 | ||||
| -rw-r--r-- | dev_tools/src/bin/refresh-docs.rs | 30 |
4 files changed, 133 insertions, 13 deletions
diff --git a/dev_tools/src/bin/ci.rs b/dev_tools/src/bin/ci.rs new file mode 100644 index 0000000..d5a108e --- /dev/null +++ b/dev_tools/src/bin/ci.rs @@ -0,0 +1,95 @@ +use std::process::exit; + +use tools::{cargo_tomls, eprintln_cargo_style, println_cargo_style, run_cmd}; + +fn main() { + #[cfg(windows)] + let _ = colored::control::set_virtual_terminal(true); + println!("{}", include_str!("../../../docs/res/ci_banner.txt")); + + let needs_commit_temp = !{ run_cmd!("git diff-index --quiet HEAD --").is_ok() }; + + if needs_commit_temp { + run_cmd!("git add .").unwrap(); + run_cmd!("git commit -m \"CI Temp\"").unwrap(); + } + + if ci().is_ok() { + println_cargo_style!("Done: All check passed!") + } + + let is_worktree_clean = run_cmd!("git diff-index --quiet HEAD --").is_ok(); + if !is_worktree_clean { + eprintln_cargo_style!("Documents needs refresh!"); + if needs_commit_temp { + run_cmd!("git restore .").unwrap(); + run_cmd!("git reset --soft HEAD~1").unwrap(); + } + exit(1) + } + + if needs_commit_temp { + run_cmd!("git restore .").unwrap(); + run_cmd!("git reset --soft HEAD~1").unwrap(); + } +} + +fn ci() -> Result<(), i32> { + build_all()?; + clippy_all()?; + test_all()?; + docs_refresh()?; + + run_cmd!("git add --renormalize .")?; + + Ok(()) +} + +fn build_all() -> Result<(), i32> { + let cargo_tomls = cargo_tomls(); + for cargo_toml in cargo_tomls { + println_cargo_style!("Build: {}", cargo_toml.to_string_lossy()); + run_cmd!( + "cargo check --manifest-path {}", + cargo_toml.to_string_lossy() + )?; + } + + Ok(()) +} + +fn clippy_all() -> Result<(), i32> { + let cargo_tomls = cargo_tomls(); + for cargo_toml in cargo_tomls { + println_cargo_style!("Clippy: {}", cargo_toml.to_string_lossy()); + run_cmd!( + "cargo clippy --manifest-path {} -- -D warnings", + cargo_toml.to_string_lossy() + )?; + } + + Ok(()) +} + +fn test_all() -> Result<(), i32> { + let cargo_tomls = cargo_tomls(); + for cargo_toml in cargo_tomls { + println_cargo_style!("Testing: {}", cargo_toml.to_string_lossy()); + run_cmd!( + "cargo test --manifest-path {}", + cargo_toml.to_string_lossy() + )?; + } + + Ok(()) +} + +fn docs_refresh() -> Result<(), i32> { + println_cargo_style!("Refresh: document at `./docs/`"); + + run_cmd!("cargo run --manifest-path dev_tools/Cargo.toml --bin docs-code-box-fix")?; + run_cmd!("cargo run --manifest-path dev_tools/Cargo.toml --bin docsify-sidebar-gen")?; + run_cmd!("cargo run --manifest-path dev_tools/Cargo.toml --bin refresh-docs")?; + + Ok(()) +} diff --git a/dev_tools/src/bin/docs-code-box-fix.rs b/dev_tools/src/bin/docs-code-box-fix.rs index db97592..21d2cce 100644 --- a/dev_tools/src/bin/docs-code-box-fix.rs +++ b/dev_tools/src/bin/docs-code-box-fix.rs @@ -1,6 +1,8 @@ use std::fs; use std::path::Path; +use tools::println_cargo_style; + /// Docsify code blocks require that blank lines before and after code blocks are not completely empty, /// but must contain at least one space, otherwise code block rendering will have issues. /// @@ -9,7 +11,7 @@ use std::path::Path; const DOCS_DIR: &str = "./docs"; fn main() { - println!("Fixing code box empty lines in docs/**/*.md ..."); + println_cargo_style!("Fixing: code box empty lines in docs/**/*.md ..."); let repo_root = find_git_repo().expect("Cannot find git repo root"); let docs_dir = repo_root.join(DOCS_DIR); @@ -32,15 +34,16 @@ fn main() { let new_content = fix_code_box_empty_lines(&content); if new_content != content { fs::write(path, &new_content).unwrap(); - println!(" Fixed: {}", path.display()); + println_cargo_style!("Fixed: {}", path.display()); fixed_count += 1; } file_count += 1; }); - println!( - "Done. Scanned {} files, fixed {} files.", - file_count, fixed_count + println_cargo_style!( + "Done: Scanned {} files, fixed {} files.", + file_count, + fixed_count ); } diff --git a/dev_tools/src/bin/docsify-sidebar-gen.rs b/dev_tools/src/bin/docsify-sidebar-gen.rs index ed9e9f0..e0f9370 100644 --- a/dev_tools/src/bin/docsify-sidebar-gen.rs +++ b/dev_tools/src/bin/docsify-sidebar-gen.rs @@ -1,13 +1,15 @@ use std::collections::BTreeMap; use std::path::Path; +use tools::println_cargo_style; + const PAGES_ROOT: &str = "./docs/pages"; const SIDEBAR_PATH: &str = "./docs/_sidebar.md"; const SIDEBAR_HEAD: &str = "- [Welcome!](README)\n"; fn main() { - println!("Refreshing _sidebar.md"); + println_cargo_style!("Refresh: _sidebar.md"); gen_sidebar(); gen_translation_sidebars(); } @@ -21,7 +23,7 @@ fn gen_sidebar() { let sidebar_path = repo_root.join(SIDEBAR_PATH); std::fs::write(&sidebar_path, lines).unwrap(); - println!(" Generated: {}", sidebar_path.display()); + println_cargo_style!("Generated: {}", sidebar_path.display()); } /// Generate _sidebar.md inside translation directories @@ -48,7 +50,7 @@ fn gen_translation_sidebars() { let sidebar_path = path.join("_sidebar.md"); std::fs::write(&sidebar_path, lines).unwrap(); - println!(" Generated: {}", sidebar_path.display()); + println_cargo_style!("Generated: {}", sidebar_path.display()); } } } diff --git a/dev_tools/src/bin/refresh-docs.rs b/dev_tools/src/bin/refresh-docs.rs index 32821ed..ffa80a2 100644 --- a/dev_tools/src/bin/refresh-docs.rs +++ b/dev_tools/src/bin/refresh-docs.rs @@ -2,6 +2,7 @@ use std::path::Path; use just_fmt::snake_case; use just_template::{Template, tmpl}; +use tools::println_cargo_style; const EXAMPLE_ROOT: &str = "./examples/"; const OUTPUT_PATH: &str = "./mingling/src/example_docs.rs"; @@ -9,10 +10,7 @@ const OUTPUT_PATH: &str = "./mingling/src/example_docs.rs"; const TEMPLATE_CONTENT: &str = include_str!("../../../mingling/src/example_docs.rs.tmpl"); fn main() { - { - println!("Refreshing Examples"); - gen_example_doc_module(); - } + gen_example_doc_module(); } fn gen_example_doc_module() { @@ -32,6 +30,8 @@ fn gen_example_doc_module() { } } + examples.sort(); + for example in examples { tmpl!(template += { examples { @@ -43,7 +43,7 @@ fn gen_example_doc_module() { ) } }); - println!(" Refresh: {}", example.name); + println_cargo_style!("Refresh: {}", example.name); } let template_str = template.to_string(); @@ -63,6 +63,26 @@ struct ExampleContent { cargo_toml: String, } +impl PartialOrd for ExampleContent { + fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { + Some(self.cmp(other)) + } +} + +impl Ord for ExampleContent { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.name.cmp(&other.name) + } +} + +impl PartialEq for ExampleContent { + fn eq(&self, other: &Self) -> bool { + self.name == other.name + } +} + +impl Eq for ExampleContent {} + impl ExampleContent { pub fn read(name: &str) -> Self { let repo = find_git_repo().unwrap(); |
