From 391dc5ef915028b8cf56952165a80117a5c90330 Mon Sep 17 00:00:00 2001 From: Nicola Papale Date: Fri, 13 Oct 2023 10:09:13 +0200 Subject: [PATCH] Add CI and pre-hook script This makes PRs easier to manage, as the tests are automatically ran. It also makes it safer to commit, as the `pre-hook` rule can be used as a pre-commit hook to prevent commiting code that doesn't work. I also marked the Menu action example as no_run, since it doesn't really help to run it, and it makes tests a lot slower. --- .github/workflows/ci.yml | 34 ++++++++++++++++++++++++++++++++++ Cargo.toml | 10 +++++----- Makefile | 9 +++++++++ Readme.md | 2 +- src/lib.rs | 2 +- src/systems.rs | 12 ++++++------ 6 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..9a62fc0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,34 @@ +name: Continous Integration + +on: + push: + branches: [master] + pull_request: + branches: [master] + +env: + CARGO_TERM_COLORS: always + +jobs: + clippy_fmt_docs_check: + name: Check clippy lints, formatting and docs + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable + with: + components: clippy,rustfmt + - name: Check formatting + run: cargo fmt --all -- --check + + - name: Check without any feature + run: cargo clippy --no-default-features -- --deny clippy::all -D warnings + + - name: Verify that docs compile + run: RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features + + - name: Check with all features enabled + run: cargo clippy --all-features -- --deny clippy::all -D warnings + + - name: Run tests + run: cargo test --all-features diff --git a/Cargo.toml b/Cargo.toml index c2774a7..d8d0bd1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,16 +23,16 @@ cuicui_chirp = ["cuicui_dsl", "dep:cuicui_chirp"] [dependencies] bevy = { version = "0.11", default-features = false, features = ["bevy_asset"] } bevy_mod_picking = { version = "0.15.0", optional = true, default-features = false } -cuicui_chirp = { version = "0.10.0", optional = true } +cuicui_chirp = { version = "0.10.0", optional = true, default-features = false, features = ["macros"] } cuicui_dsl = { version = "0.10.0", optional = true } non-empty-vec = { version = "0.2.2", default-features = false } [dev-dependencies] fastrand = "1.7" -cuicui_layout_bevy_ui = "0.10.0" -cuicui_layout = "0.10.0" -bevy = { version = "0.11", default-features = true } +cuicui_layout_bevy_ui = { version = "0.10.0", default-features = false } +cuicui_layout = { version = "0.10.0", default-features = false } +bevy = { version = "0.11", default-features = false, features = ["bevy_asset", "png", "x11", "default_font"] } [[example]] name = "ultimate_menu_navigation" -required-features = ["cuicui_chirp"] +required-features = ["cuicui_chirp", "bevy/filesystem_watcher", "cuicui_layout_bevy_ui/chirp", "cuicui_layout/reflect"] diff --git a/Makefile b/Makefile index a03dfcc..bbf6ec0 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,13 @@ check: cargo clippy --examples + run: cargo run --example ultimate_menu_navigation --features cuicui_dsl + +pre-hook: + cargo fmt --all -- --check + cargo clippy --no-default-features -- --deny clippy::all -D warnings + RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features + cargo clippy --all-features -- --deny clippy::all -D warnings + cargo test --all-features + cargo clippy --all-features --features="cuicui_chirp bevy/filesystem_watcher cuicui_layout_bevy_ui/chirp cuicui_layout/reflect" --example ultimate_menu_navigation diff --git a/Readme.md b/Readme.md index 026c492..a35a889 100644 --- a/Readme.md +++ b/Readme.md @@ -374,7 +374,7 @@ To use the return key, change the `key_action` attribute. Otherwise, if you are not using default input handling, add this system: -```rust +```rust, no_run use bevy::prelude::*; use bevy_ui_navigation::prelude::{NavRequest, NavRequestSystem}; diff --git a/src/lib.rs b/src/lib.rs index d05a9d7..50034c1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -33,8 +33,8 @@ [`NavRequest::ScopeMove`]: events::NavRequest::ScopeMove [`NavRequestSystem`]: NavRequestSystem */ -#![forbid(missing_docs)] #![doc = include_str!("../Readme.md")] +#![forbid(missing_docs)] #![allow(clippy::unnecessary_lazy_evaluations)] mod commands; diff --git a/src/systems.rs b/src/systems.rs index a70b207..ca84691 100644 --- a/src/systems.rs +++ b/src/systems.rs @@ -1,7 +1,7 @@ //! System for the navigation tree and default input systems to get started. use crate::{ events::{Direction, NavRequest, ScopeDirection}, - resolve::{Focusable, Focused}, + resolve::Focused, }; #[cfg(feature = "bevy_ui")] @@ -72,7 +72,7 @@ pub struct InputMapping { pub key_previous: KeyCode, /// Keyboard key for [`NavRequest::Unlock`] pub key_free: KeyCode, - /// Whether mouse hover gives focus to [`Focusable`] elements. + /// Whether mouse hover gives focus to [`Focusable`](crate::resolve::Focusable) elements. pub focus_follows_mouse: bool, } impl Default for InputMapping { @@ -124,7 +124,7 @@ macro_rules! mapping { /// The button mapping may be controlled through the [`InputMapping`] resource. /// You may however need to customize the behavior of this system (typically /// when integrating in the game) in this case, you should write your own -/// system that sends [`NavRequest`](crate::events::NavRequest) events +/// system that sends [`NavRequest`] events pub fn default_gamepad_input( mut nav_cmds: EventWriter, has_focused: Query<(), With>, @@ -195,7 +195,7 @@ pub fn default_gamepad_input( /// The button mapping may be controlled through the [`InputMapping`] resource. /// You may however need to customize the behavior of this system (typically /// when integrating in the game) in this case, you should write your own -/// system that sends [`NavRequest`](crate::events::NavRequest) events. +/// system that sends [`NavRequest`] events. pub fn default_keyboard_input( has_focused: Query<(), With>, keyboard: Res>, @@ -277,7 +277,7 @@ pub fn update_boundaries( #[cfg(feature = "pointer_focus")] fn send_request( - f: impl Fn(Query<&Focusable>, Res>, EventWriter) + f: impl Fn(Query<&crate::resolve::Focusable>, Res>, EventWriter) + Send + Sync + Copy @@ -310,7 +310,7 @@ fn send_request( #[allow(clippy::type_complexity)] pub fn enable_click_request( input_mapping: Res, - to_add: Query, Without>>)>, + to_add: Query, Without>>)>, mut commands: Commands, ) { use crate::prelude::FocusState::Blocked;