From d2a8cd691b0be822b892d88f0b9f8cc1789e3716 Mon Sep 17 00:00:00 2001 From: Hofer-Julian <30049909+Hofer-Julian@users.noreply.github.com> Date: Fri, 6 Sep 2024 11:28:15 +0200 Subject: [PATCH] ci: setup github actions workflows (#24) * ci: setup github actions workflows This adds linting and tests * Formatting * Add concurrency settings * Format * Test only our shell --- .github/workflows/rust-linting.yml | 46 ++++++++++++++++++++++++++++ .github/workflows/rust-tests.yml | 30 ++++++++++++++++++ crates/deno_task_shell/src/parser.rs | 13 ++++---- 3 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/rust-linting.yml create mode 100644 .github/workflows/rust-tests.yml diff --git a/.github/workflows/rust-linting.yml b/.github/workflows/rust-linting.yml new file mode 100644 index 0000000..dc51ad6 --- /dev/null +++ b/.github/workflows/rust-linting.yml @@ -0,0 +1,46 @@ +name: Rust Linting + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + fmt: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + + - name: Run cargo fmt + run: cargo fmt -- --check + + clippy: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + + - name: Run cargo clippy + run: cargo clippy --all-targets --workspace -- -D warnings diff --git a/.github/workflows/rust-tests.yml b/.github/workflows/rust-tests.yml new file mode 100644 index 0000000..1da39b0 --- /dev/null +++ b/.github/workflows/rust-tests.yml @@ -0,0 +1,30 @@ +name: Rust + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + tests: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + + - name: Run tests + run: cargo test --manifest-path crates/shell/Cargo.toml --all-targets diff --git a/crates/deno_task_shell/src/parser.rs b/crates/deno_task_shell/src/parser.rs index 992c99b..27919df 100644 --- a/crates/deno_task_shell/src/parser.rs +++ b/crates/deno_task_shell/src/parser.rs @@ -330,7 +330,7 @@ pub enum RedirectOpOutput { struct ShellParser; pub fn parse(input: &str) -> Result { - let mut pairs = ShellParser::parse(Rule::FILE, input)?; + let mut pairs = ShellParser::parse(Rule::FILE, input)?; // println!("pairs: {:?}", pairs); @@ -410,10 +410,7 @@ fn parse_compound_list( } } _ => { - anyhow::bail!( - "Unexpected rule in compound_list: {:?}", - item.as_rule() - ); + anyhow::bail!("Unexpected rule in compound_list: {:?}", item.as_rule()); } } } @@ -510,7 +507,9 @@ fn parse_pipeline(pair: Pair) -> Result { .ok_or_else(|| anyhow::anyhow!("Expected pipeline content"))?; let (negated, pipe_sequence) = if first.as_rule() == Rule::Bang { // If it's Bang, check for whitespace - if pipeline_str.len() > 1 && !pipeline_str[1..2].chars().next().unwrap().is_whitespace() { + if pipeline_str.len() > 1 + && !pipeline_str[1..2].chars().next().unwrap().is_whitespace() + { anyhow::bail!( "Perhaps you meant to add a space after the exclamation point to negate the command?\n ! {}", pipeline_str @@ -709,7 +708,7 @@ fn parse_word(pair: Pair) -> Result { break; } } - }; + } if let Some(WordPart::Text(ref mut text)) = parts.last_mut() { text.push_str(&escaped_char); } else {