Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make CI Clippy static analysis checks more robust #635

Merged
merged 3 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 28 additions & 12 deletions .github/workflows/oxipng.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,33 @@ jobs:
- name: Install nextest
uses: taiki-e/install-action@nextest

- name: Run rustfmt
- name: Install cargo-hack
if: matrix.target == 'x86_64-unknown-linux-gnu'
run: cargo fmt --check
uses: taiki-e/install-action@cargo-hack

- name: Run Clippy (no default features)
- name: Install clippy-sarif
if: matrix.target == 'x86_64-unknown-linux-gnu'
uses: giraffate/clippy-action@v1
uses: taiki-e/install-action@v2
with:
clippy_flags: --no-deps --all-targets --no-default-features -- -D warnings
reporter: github-check
fail_on_error: true
tool: clippy-sarif

- name: Run Clippy (all features)
- name: Install sarif-fmt
if: matrix.target == 'x86_64-unknown-linux-gnu'
uses: giraffate/clippy-action@v1
uses: taiki-e/install-action@v2
with:
clippy_flags: --no-deps --all-targets --all-features -- -D warnings
reporter: github-check
fail_on_error: true
tool: sarif-fmt

- name: Run rustfmt
if: matrix.target == 'x86_64-unknown-linux-gnu'
run: cargo fmt --check

- name: Run Clippy for all feature combinations
if: matrix.target == 'x86_64-unknown-linux-gnu'
run: >
cargo hack clippy --no-deps --all-targets --feature-powerset --exclude-features sanity-checks --message-format=json -- -D warnings
| clippy-sarif
| tee clippy-results.sarif
| sarif-fmt

- name: Run tests
run: |
Expand All @@ -145,6 +153,14 @@ jobs:
target/${{ env.CARGO_BUILD_TARGET }}/release/oxipng
target/${{ env.CARGO_BUILD_TARGET }}/release/oxipng.exe

- name: Upload analysis results to GitHub
uses: github/codeql-action/upload-sarif@v3
if: always() && matrix.target == 'x86_64-unknown-linux-gnu'
continue-on-error: true
with:
sarif_file: clippy-results.sarif
category: clippy

msrv-check:
name: MSRV check

Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,10 @@ fn parse_opts_into_struct(
if let Some(iterations) = NonZeroU8::new(15) {
opts.deflate = Deflaters::Zopfli { iterations };
}
} else if let Deflaters::Libdeflater { compression } = &mut opts.deflate {
if let Some(x) = matches.get_one::<i64>("compression") {
*compression = *x as u8;
}
} else if let (Deflaters::Libdeflater { compression }, Some(x)) =
(&mut opts.deflate, matches.get_one::<i64>("compression"))
{
*compression = *x as u8;
}

#[cfg(feature = "parallel")]
Expand Down
4 changes: 2 additions & 2 deletions src/rayon.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(dead_code)]

pub mod prelude {
pub use super::*;
}
Expand Down Expand Up @@ -70,12 +72,10 @@ where

impl<I: Iterator> ParallelIterator for I {}

#[allow(dead_code)]
pub fn join<A, B>(a: impl FnOnce() -> A, b: impl FnOnce() -> B) -> (A, B) {
(a(), b())
}

#[allow(dead_code)]
pub fn spawn<A>(a: impl FnOnce() -> A) -> A {
a()
}