From 9ca72e391dec29f7c8f17a58c61befe721a7486d Mon Sep 17 00:00:00 2001 From: Thomas Frans <48214567+ThomasFrans@users.noreply.github.com> Date: Tue, 28 Feb 2023 22:49:32 +0100 Subject: [PATCH] CI/CD: Add clippy and update actions * Add clippy to CI. * Update .github/workflows/ci.yml * Update .github/workflows/ci.yml * Use `cargo check` instead of `cargo build` * Update CD workflow --------- Co-authored-by: Henrik Friedrichsen --- .github/workflows/cd.yml | 23 +++++------- .github/workflows/ci.yml | 75 +++++++++++++++++++++++++++++----------- src/ui/cover.rs | 2 +- 3 files changed, 65 insertions(+), 35 deletions(-) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 734f455..5cad26c 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -49,12 +49,9 @@ jobs: features: '--no-default-features --features rodio_backend,pancurses_backend,share_clipboard,notify' steps: - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 + uses: dtolnay/rust-toolchain@stable with: - toolchain: stable - override: true target: ${{ matrix.target }} - profile: minimal - name: Install macOS dependencies if: matrix.os == 'macos-latest' run: brew install portaudio pkg-config @@ -69,19 +66,17 @@ jobs: run: | apt update apt install -y ${{ matrix.dependencies }} - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 name: Checkout src - - uses: actions/cache@v2 + - uses: actions/cache@v3 with: path: | - ~/.cargo/registry - ~/.cargo/git + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - name: Running cargo build - uses: actions-rs/cargo@v1 - with: - command: build - args: --locked --release --target ${{ matrix.target }} ${{ matrix.features }} + run: cargo build --release --target ${{ matrix.target }} ${{ matrix.features }} - name: Extract git tag shell: bash run: echo "##[set-output name=tag;]$(echo ${GITHUB_REF#refs/tags/})" @@ -91,11 +86,11 @@ jobs: run: | cd target/${{ matrix.target }}/release case ${{ matrix.target }} in - *-pc-windows-*) + *-pc-windows-*) 7z -y a ncspot-${{ steps.extract_tag.outputs.tag }}-${{ matrix.build_target }}.zip ncspot.exe sha256sum ncspot-${{ steps.extract_tag.outputs.tag }}-${{ matrix.build_target }}.zip > ncspot-${{ steps.extract_tag.outputs.tag }}-${{ matrix.build_target }}.sha256 ;; - *) + *) tar czvf ncspot-${{ steps.extract_tag.outputs.tag }}-${{ matrix.build_target }}.tar.gz ncspot shasum -a 256 ncspot-${{ steps.extract_tag.outputs.tag }}-${{ matrix.build_target }}.tar.gz > ncspot-${{ steps.extract_tag.outputs.tag }}-${{ matrix.build_target }}.sha256 ;; diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 08e2284..94ac472 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,8 @@ on: branches: [ main ] jobs: - check-macos: + # Build the Rust code. + build: name: Checking ${{ matrix.build_target }} runs-on: ${{ matrix.os }} strategy: @@ -30,13 +31,22 @@ jobs: target: x86_64-pc-windows-msvc features: '--no-default-features --features rodio_backend,pancurses_backend,share_clipboard,notify' steps: - - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v3 + - uses: actions/cache@v3 + name: Cache build data + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable with: - toolchain: stable - override: true target: ${{ matrix.target }} - profile: minimal + components: clippy, rustfmt - name: Install macOS dependencies if: matrix.os == 'macos-latest' run: brew install portaudio pkg-config @@ -45,23 +55,48 @@ jobs: run: | sudo apt update sudo apt install libpulse-dev libdbus-1-dev libncursesw5-dev libxcb-shape0-dev libxcb-xfixes0-dev - - uses: actions/checkout@v2 - name: Checkout src - - uses: actions/cache@v2 - with: - path: | - ~/.cargo/registry - ~/.cargo/git - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - name: Running cargo check - uses: actions-rs/cargo@v1 - with: - command: check - args: --locked --release --target ${{ matrix.target }} ${{ matrix.features }} + - name: Running cargo build + run: cargo check --locked --target ${{ matrix.target }} ${{ matrix.features }} + # Check Rust code formatting. fmt: + name: Running `cargo fmt` runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + target: x86_64-unknown-linux-gnu + components: clippy, rustfmt - name: cargo fmt run: cargo fmt --all -- --check + + # Run `cargo clippy` on all the targets in all workspace members with all + # features enabled, and return an error if there are any clippy suggestions. + clippy: + name: Running `cargo clippy` + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/cache@v3 + name: Cache build data + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-clippy-${{ hashFiles('**/Cargo.lock') }} + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + target: x86_64-unknown-linux-gnu + components: clippy, rustfmt + - name: Install Linux dependencies + run: | + sudo apt update + sudo apt install portaudio19-dev libasound2-dev libpulse-dev libdbus-1-dev libncursesw5-dev libxcb-shape0-dev libxcb-xfixes0-dev + - name: cargo clippy + run: cargo clippy --locked --no-deps --workspace --all-targets --all-features --verbose -- -D warnings diff --git a/src/ui/cover.rs b/src/ui/cover.rs index b3519ab..4d4f681 100644 --- a/src/ui/cover.rs +++ b/src/ui/cover.rs @@ -151,7 +151,7 @@ impl CoverView { if ueberzug.is_none() { *ueberzug = Some( std::process::Command::new("ueberzug") - .args(&["layer", "--silent"]) + .args(["layer", "--silent"]) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .spawn()?,