-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add ci and clippy fixes * install alsa and udev
- Loading branch information
Showing
11 changed files
with
320 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()], | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.