diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6d38120 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,87 @@ +name: Check and Lint +on: + pull_request: + push: + branches: + - main + +jobs: + check: + name: check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable + - name: Install alsa and udev + run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev + - run: cargo run -p ci -- check + + wasm-check: + name: wasm-check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable + with: + targets: wasm32-unknown-unknown + - run: cargo run -p ci -- wasm-check + + example-check: + name: example-check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable + - name: Install alsa and udev + run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev + - run: cargo run -p ci -- example-check + + fmt: + name: fmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable + - name: Install alsa and udev + run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev + - run: cargo run -p ci -- fmt + + test: + name: test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable + - name: Install alsa and udev + run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev + - run: cargo run -p ci -- test + + doc-test: + name: doc-test + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable + - name: Install alsa and udev + run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev + - run: cargo run -p ci -- doc-test + + doc-check: + name: doc-check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable + - name: Install alsa and udev + run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev + - run: cargo run -p ci -- doc-check + + clippy: + name: clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable + - name: Install alsa and udev + run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev + - run: cargo run -p ci -- clippy \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index d46cd4e..f5c05a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,3 +20,9 @@ thiserror = "1.0.50" [dev-dependencies] lerp = "0.4" bevy = { version = "0.12", default-features = true } + +[workspace] +resolver = "2" +members = [ + "ci" +] diff --git a/ci/Cargo.toml b/ci/Cargo.toml new file mode 100644 index 0000000..4843560 --- /dev/null +++ b/ci/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "ci" +version = "0.1.0" +edition = "2021" + +[dependencies] +anyhow = "1.0.70" +xshell = "0.2" +bitflags = "2.0" diff --git a/ci/src/main.rs b/ci/src/main.rs new file mode 100644 index 0000000..138baea --- /dev/null +++ b/ci/src/main.rs @@ -0,0 +1,118 @@ +use anyhow::bail; +use bitflags::bitflags; +use xshell::{cmd, Shell}; + +mod utils; +use utils::*; + +bitflags! { + #[derive(Clone, Copy)] + struct Check: u32 { + const CHECK = 0b00000001; + const WASM_CHECK = 0b00000010; + const EXAMPLE_CHECK = 0b00000100; + const FMT = 0b00001000; + const TEST = 0b00010000; + const DOC_TEST = 0b00100000; + const DOC_CHECK = 0b01000000; + const CLIPPY = 0b10000000; + } +} + +fn main() -> anyhow::Result<()> { + std::env::set_var("RUSTFLAGS", "-D warnings"); + + let arguments = [ + ("check", Check::CHECK), + ("wasm-check", Check::WASM_CHECK), + ("example-check", Check::EXAMPLE_CHECK), + ("fmt", Check::FMT), + ("test", Check::TEST), + ("doc-test", Check::DOC_TEST), + ("doc-check", Check::DOC_CHECK), + ("clippy", Check::CLIPPY), + ]; + + let what_to_run = if let Some(arg) = std::env::args().nth(1).as_deref() { + if let Some((_, check)) = arguments.iter().find(|(str, _)| *str == arg) { + *check + } else { + bail!( + "Invalid argument: {arg:?}.\nEnter one of: {}.", + arguments[1..] + .iter() + .map(|(s, _)| s) + .fold(arguments[0].0.to_owned(), |c, v| c + ", " + v) + ); + } + } else { + Check::all() + }; + + let sh = Shell::new()?; + if what_to_run.contains(Check::CHECK) { + check(&sh, Target::Default)?; + } + if what_to_run.contains(Check::WASM_CHECK) { + check(&sh, Target::Wasm)?; + } + if what_to_run.contains(Check::EXAMPLE_CHECK) { + example_check(&sh)?; + } + if what_to_run.contains(Check::FMT) { + fmt(&sh)?; + } + if what_to_run.contains(Check::TEST) { + test(&sh)?; + } + if what_to_run.contains(Check::DOC_TEST) { + doc_test(&sh)?; + } + if what_to_run.contains(Check::DOC_CHECK) { + doc_check(&sh)?; + } + if what_to_run.contains(Check::CLIPPY) { + clippy(&sh)?; + } + Ok(()) +} + +fn check(sh: &Shell, target: Target) -> anyhow::Result<()> { + let target_flags = &target.flags(); + cmd!(sh, "cargo check {target_flags...} --features bevy/webgl2").run()?; + Ok(()) +} + +fn example_check(sh: &Shell) -> anyhow::Result<()> { + cmd!(sh, "cargo check --examples").run()?; + Ok(()) +} + +fn fmt(sh: &Shell) -> anyhow::Result<()> { + cmd!(sh, "cargo fmt --all -- --check").run()?; + Ok(()) +} + +fn test(sh: &Shell) -> anyhow::Result<()> { + cmd!(sh, "cargo test --workspace --lib --bins --tests").run()?; + Ok(()) +} + +fn doc_test(sh: &Shell) -> anyhow::Result<()> { + cmd!(sh, "cargo test --workspace --doc").run()?; + Ok(()) +} + +fn doc_check(sh: &Shell) -> anyhow::Result<()> { + cmd!( + sh, + "cargo doc --workspace --all-features --no-deps --document-private-items" + ) + .run()?; + Ok(()) +} + +fn clippy(sh: &Shell) -> anyhow::Result<()> { + cmd!(sh, "cargo clippy --workspace --all-targets").run()?; + Ok(()) +} diff --git a/ci/src/utils.rs b/ci/src/utils.rs new file mode 100644 index 0000000..763cd26 --- /dev/null +++ b/ci/src/utils.rs @@ -0,0 +1,13 @@ +pub enum Target { + Default, + Wasm, +} + +impl Target { + pub fn flags(&self) -> Vec { + match self { + Target::Default => vec![], + Target::Wasm => vec!["--target".to_owned(), "wasm32-unknown-unknown".to_owned()], + } + } +} diff --git a/examples/3d.rs b/examples/3d.rs index ebd96e9..e8560c7 100644 --- a/examples/3d.rs +++ b/examples/3d.rs @@ -142,11 +142,11 @@ impl SpineMaterial for Spine3DMaterial { type Material = StandardMaterial; type Params<'w, 's> = SpineSettingsQuery<'w, 's>; - fn update<'w, 's>( + fn update( material: Option, entity: Entity, renderable_data: SpineMaterialInfo, - params: &StaticSystemParam>, + params: &StaticSystemParam>, ) -> Option { let spine_settings = params .spine_settings_query diff --git a/examples/crossfades.rs b/examples/crossfades.rs index 14eb077..0500984 100644 --- a/examples/crossfades.rs +++ b/examples/crossfades.rs @@ -72,10 +72,8 @@ fn crossfades(mut spine_query: Query<&mut Spine>, time: Res