From 94c7af7709fbe76fe1a0041cc5f7ea0f6a612c6c Mon Sep 17 00:00:00 2001 From: eljamm Date: Sun, 9 Jun 2024 12:09:02 +0100 Subject: [PATCH] Add github actions workflows - Check, format and lint code when committing - Check pull requests for formatting --- .github/workflows/check-and-lint.yaml | 54 +++++++++++++++++++++++++++ .github/workflows/check-pr.yaml | 21 +++++++++++ 2 files changed, 75 insertions(+) create mode 100644 .github/workflows/check-and-lint.yaml create mode 100644 .github/workflows/check-pr.yaml diff --git a/.github/workflows/check-and-lint.yaml b/.github/workflows/check-and-lint.yaml new file mode 100644 index 0000000..2fada22 --- /dev/null +++ b/.github/workflows/check-and-lint.yaml @@ -0,0 +1,54 @@ +on: + push: + branches: + - main + +name: Check and Lint + +jobs: + check: + name: Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y libudev-dev + - uses: Swatinem/rust-cache@v2 + - name: "cargo check" + run: cargo check + + format: + name: Format + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + - uses: Swatinem/rust-cache@v2 + - name: "cargo fmt" + uses: mbrobbel/rustfmt-check@master + with: + token: ${{ secrets.GITHUB_TOKEN }} + + clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + components: clippy + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y libudev-dev + - uses: Swatinem/rust-cache@v2 + - name: "cargo clippy" + run: cargo clippy --all-features --workspace --tests --no-deps diff --git a/.github/workflows/check-pr.yaml b/.github/workflows/check-pr.yaml new file mode 100644 index 0000000..1822c2d --- /dev/null +++ b/.github/workflows/check-pr.yaml @@ -0,0 +1,21 @@ +on: pull_request + +name: Check Pull Request + +jobs: + format: + name: Format + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - uses: actions/checkout@v4 + - name: Install Rust + uses: dtolnay/rust-toolchain@nightly + with: + components: rustfmt + - name: "cargo fmt" + uses: mbrobbel/rustfmt-check@master + with: + token: ${{ secrets.GITHUB_TOKEN }} + mode: review