Skip to content

Commit

Permalink
Add ci and clippy fixes (#14)
Browse files Browse the repository at this point in the history
* add ci and clippy fixes

* install alsa and udev
  • Loading branch information
jabuwu authored Nov 12, 2023
1 parent 240b8fd commit f32c1cb
Show file tree
Hide file tree
Showing 11 changed files with 320 additions and 96 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
9 changes: 9 additions & 0 deletions ci/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "ci"
version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0.70"
xshell = "0.2"
bitflags = "2.0"
118 changes: 118 additions & 0 deletions ci/src/main.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
13 changes: 13 additions & 0 deletions ci/src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pub enum Target {
Default,
Wasm,
}

impl Target {
pub fn flags(&self) -> Vec<String> {
match self {
Target::Default => vec![],
Target::Wasm => vec!["--target".to_owned(), "wasm32-unknown-unknown".to_owned()],
}
}
}
4 changes: 2 additions & 2 deletions examples/3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::Material>,
entity: Entity,
renderable_data: SpineMaterialInfo,
params: &StaticSystemParam<Self::Params<'w, 's>>,
params: &StaticSystemParam<Self::Params<'_, '_>>,
) -> Option<Self::Material> {
let spine_settings = params
.spine_settings_query
Expand Down
6 changes: 2 additions & 4 deletions examples/crossfades.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ fn crossfades(mut spine_query: Query<&mut Spine>, time: Res<Time>) {
if current_animation != "walk" {
let _ = spine.animation_state.set_animation_by_name(0, "walk", true);
}
} else {
if current_animation != "idle" {
let _ = spine.animation_state.set_animation_by_name(0, "idle", true);
}
} else if current_animation != "idle" {
let _ = spine.animation_state.set_animation_by_name(0, "idle", true);
}
}
}
20 changes: 10 additions & 10 deletions examples/custom_material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ impl Material2d for MyMaterial {
layout: &MeshVertexBufferLayout,
_key: Material2dKey<Self>,
) -> Result<(), SpecializedMeshPipelineError> {
let mut vertex_attributes = Vec::new();
vertex_attributes.push(Mesh::ATTRIBUTE_POSITION.at_shader_location(0));
vertex_attributes.push(Mesh::ATTRIBUTE_NORMAL.at_shader_location(1));
vertex_attributes.push(Mesh::ATTRIBUTE_UV_0.at_shader_location(2));
vertex_attributes.push(Mesh::ATTRIBUTE_COLOR.at_shader_location(4));
vertex_attributes
.push(DARK_COLOR_ATTRIBUTE.at_shader_location(DARK_COLOR_SHADER_POSITION as u32));
let vertex_attributes = vec![
Mesh::ATTRIBUTE_POSITION.at_shader_location(0),
Mesh::ATTRIBUTE_NORMAL.at_shader_location(1),
Mesh::ATTRIBUTE_UV_0.at_shader_location(2),
Mesh::ATTRIBUTE_COLOR.at_shader_location(4),
DARK_COLOR_ATTRIBUTE.at_shader_location(DARK_COLOR_SHADER_POSITION as u32),
];
let vertex_buffer_layout = layout.get_layout(&vertex_attributes)?;
descriptor.vertex.buffers = vec![vertex_buffer_layout];
descriptor.primitive.cull_mode = None;
Expand All @@ -133,14 +133,14 @@ impl SpineMaterial for MyMaterial {
type Material = Self;
type Params<'w, 's> = MyMaterialParam<'w, 's>;

fn update<'w, 's>(
fn update(
material: Option<Self>,
entity: Entity,
renderable_data: SpineMaterialInfo,
params: &StaticSystemParam<Self::Params<'w, 's>>,
params: &StaticSystemParam<Self::Params<'_, '_>>,
) -> Option<Self> {
if let Ok(spine) = params.my_spine_query.get(entity) {
let mut material = material.unwrap_or_else(|| Self::default());
let mut material = material.unwrap_or_default();
material.image = renderable_data.texture;
material.time = params.time.elapsed_seconds();
if let Some(slot) = spine
Expand Down
Loading

0 comments on commit f32c1cb

Please sign in to comment.