diff --git a/.cargo/audit.toml b/.cargo/audit.toml new file mode 100644 index 0000000..0c7f7dc --- /dev/null +++ b/.cargo/audit.toml @@ -0,0 +1,10 @@ +[advisories] +ignore = [ + # Warning: unmaintained + # Title: paste - no longer maintained + "RUSTSEC-2024-0436", +] + +[output] +quiet = false +deny = ["warnings", "unmaintained"] diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml new file mode 100644 index 0000000..bed6659 --- /dev/null +++ b/.github/workflows/audit.yml @@ -0,0 +1,47 @@ +name: Security audit + +on: + push: + paths: + - "**/Cargo.lock" + - "**/Cargo.toml" + - "**/deny.toml" + pull_request: + types: [ opened, reopened, synchronize ] + branches: + - main + # schedule: + # - cron: "0 0 * * *" + +jobs: + + audit-check: + name: Audit check + runs-on: ubuntu-latest + permissions: + issues: write + checks: write + steps: + - uses: actions/checkout@v5 + - uses: rustsec/audit-check@v2.0.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + + cargo-deny: + name: Cargo deny + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: EmbarkStudios/cargo-deny-action@v2 + with: + rust-version: "1.89.0" + log-level: warn + command: check + arguments: --all-features + + audit-success: + name: Audit success + runs-on: ubuntu-latest + needs: [audit-check, cargo-deny] + steps: + - run: echo "All audit jobs successfully finished." diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 98e8be0..f54723f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,8 @@ name: CI on: push: + branches: + - "*" pull_request: types: [ opened, reopened, synchronize ] branches: @@ -18,26 +20,18 @@ permissions: # Each job runs in a runner environment specified by `runs-on`. jobs: - test: - name: Test + clippy: + name: Clippy runs-on: ubuntu-latest steps: + - uses: actions/checkout@v5 - uses: ilammy/setup-nasm@v1 - - - name: Check out repository code - uses: actions/checkout@v5 - - # This GitHub Action installs a Rust toolchain using "rustup". - # It is designed for one-line concise usage and good defaults. - - name: Install the Rust toolchain - uses: dtolnay/rust-toolchain@stable - - # A GitHub Action that implements smart caching for rust/cargo projects with sensible defaults. - - name: Rust Cache Action - uses: Swatinem/rust-cache@v2 - - - name: Run tests - run: cargo test + - uses: dtolnay/rust-toolchain@stable + with: + components: clippy + - uses: Swatinem/rust-cache@v2 + - name: Linting + run: cargo clippy --all-targets --all-features -- -D warnings fmt: name: Format @@ -47,18 +41,60 @@ jobs: - uses: dtolnay/rust-toolchain@stable with: components: rustfmt + - uses: Swatinem/rust-cache@v2 - name: Enforce formatting - run: cargo fmt --check + run: cargo fmt --all -- --check --color always - clippy: - name: Clippy + msrv: + name: MSRV check runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 - uses: ilammy/setup-nasm@v1 - - uses: dtolnay/rust-toolchain@stable + - uses: dtolnay/rust-toolchain@master with: + toolchain: 1.89.0 components: clippy + - run: cargo fetch + - name: MSRV check with cargo clippy + run: cargo clippy --all-targets --all-features -- -D warnings + + publish-check: + name: Publish check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - uses: ilammy/setup-nasm@v1 + - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - - name: Linting - run: cargo clippy -- -D warnings + - run: cargo fetch + - name: cargo publish dry run + run: cargo publish --dry-run + + test: + name: Test + runs-on: ubuntu-latest + steps: + - name: Check out repository code + uses: actions/checkout@v5 + + - uses: ilammy/setup-nasm@v1 + + # This GitHub Action installs a Rust toolchain using "rustup". + # It is designed for one-line concise usage and good defaults. + - name: Install the Rust toolchain + uses: dtolnay/rust-toolchain@stable + + # A GitHub Action that implements smart caching for rust/cargo projects with sensible defaults. + - name: Rust Cache Action + uses: Swatinem/rust-cache@v2 + + - name: Run tests + run: cargo test --all --all-targets + + ci-success: + name: CI success + runs-on: ubuntu-latest + needs: [clippy, fmt, msrv, publish-check, test] + steps: + - run: echo "All CI jobs successfully finished." diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..f8e306e --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,47 @@ +repos: + + - repo: local + hooks: + - id: check + name: check + description: Standard check + entry: cargo check + language: system + types: [ rust ] + pass_filenames: false + + - id: clippy + name: clippy + description: More rigorous check + entry: cargo clippy --all-targets --all-features -- -D warnings + language: rust + pass_filenames: false + + - id: rustfmt + name: rustfmt + description: Check if all files follow the rustfmt style + entry: cargo fmt --all -- --check --color always + language: rust + types: [ rust ] + pass_filenames: false + + - id: test + name: test + description: Run tests + entry: cargo test --all --all-targets + language: rust + types: [ rust ] + pass_filenames: false + + - repo: https://github.com/EmbarkStudios/cargo-deny + rev: 0.18.5 + hooks: + - id: cargo-deny + args: ["--all-features", "check"] + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 + hooks: + - id: check-added-large-files + - id: check-yaml + - id: end-of-file-fixer diff --git a/CHANGELOG.md b/CHANGELOG.md index fbb1e28..18e46d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,11 +10,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Some form of concurrent execution, but this might not be necessary as some dependencies already use `rayon` and `crossbeam`. -## [0.2.4] - 2025-09-08 +## [0.2.4] - 2025-09-30 + +### Added + +- GitHub action `audit.yml`, with `audit-check` and `cargo-deny-action` actions + - `audit.toml` for local and CI `cargo audit` configuration + - `deny.toml` for local and CI `cargo deny` configuration +- Pre-commit hooks, `.pre-commit-config.yaml` ### Changed - Updated several dependencies to newer versions. - `cargo audit` found a security vulnerability in a dependency (that version has been yanked). +- The build process for the release profile now uses the LTO optimization. ## [0.2.3] - 2024-07-10 diff --git a/Cargo.lock b/Cargo.lock index 16c56a6..e735216 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -209,9 +209,9 @@ checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" [[package]] name = "clap" -version = "4.5.47" +version = "4.5.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eac00902d9d136acd712710d71823fb8ac8004ca445a89e73a41d45aa712931" +checksum = "e2134bb3ea021b78629caa971416385309e0131b351b25e01dc16fb54e1b5fae" dependencies = [ "clap_builder", "clap_derive", @@ -219,9 +219,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.47" +version = "4.5.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ad9bbf750e73b5884fb8a211a9424a1906c1e156724260fdae972f31d70e1d6" +checksum = "c2ba64afa3c0a6df7fa517765e31314e983f51dda798ffba27b988194fb65dc9" dependencies = [ "anstream", "anstyle", diff --git a/Cargo.toml b/Cargo.toml index 65a238e..698336c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,16 +1,15 @@ [package] name = "reduce_image_size" +description = "Reduces size of images in a folder (and optionally sub-folders, recursively)." version = "0.2.4" -edition = "2024" authors = ["Ivan Lazarević"] -description = "Reduces size of images in a folder (and optionally sub-folders, recursively)." repository = "https://github.com/ivanbgd/reduce-image-size-rust" license = "MIT" -keywords = ["image", "images", "photo", "jpeg", "png"] +readme = "README.md" categories = ["computer-vision", "multimedia", "multimedia::images", "command-line-utilities"] - -[profile.release] -strip = "symbols" +keywords = ["image", "images", "photo", "jpeg", "png"] +edition = "2024" +rust-version = "1.89.0" [lib] path = "src/lib.rs" @@ -20,10 +19,18 @@ name = "reduce_image_size" path = "src/main.rs" [dependencies] -clap = { version = "4.5.9", features = ["derive"] } +clap = { version = "4.5.48", features = ["derive"] } fast_image_resize = { version = "5.3.0" } image = "0.25.8" -oxipng = { version = "9.1.1", default-features = false, features = ["parallel"] } -pathdiff = { version = "0.2.1" } -turbojpeg = { version = "1.1.0", features = ["image"] } +oxipng = { version = "9.1.5", default-features = false, features = ["parallel"] } +pathdiff = { version = "0.2.3" } +turbojpeg = { version = "1.3.3", features = ["image"] } walkdir = "2.5.0" + +[profile.dev.package.oxipng] +opt-level = 3 + +[profile.release] +strip = "symbols" +lto = "fat" +codegen-units = 1 diff --git a/README.md b/README.md index ea82f1e..4f7ac30 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,11 @@ # Reduce Image Size -[![CI](https://github.com/ivanbgd/reduce-image-size-rust/actions/workflows/ci.yml/badge.svg)](https://github.com/ivanbgd/reduce-image-size-rust/actions/workflows/ci.yml) +[![license](https://img.shields.io/badge/License-MIT-blue.svg?style=flat)](LICENSE) [![Crates.io](https://img.shields.io/crates/v/reduce_image_size.svg)](https://crates.io/crates/reduce_image_size) [![docs.rs](https://docs.rs/reduce_image_size/badge.svg)](https://docs.rs/reduce_image_size/) +[![CI](https://github.com/ivanbgd/reduce-image-size-rust/actions/workflows/ci.yml/badge.svg)](https://github.com/ivanbgd/reduce-image-size-rust/actions/workflows/ci.yml) +[![Security audit](https://github.com/ivanbgd/reduce-image-size-rust/actions/workflows/audit.yml/badge.svg)](https://github.com/ivanbgd/reduce-image-size-rust/actions/workflows/audit.yml) +[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit) ## Description Reduces size of images in a folder (and optionally sub-folders, recursively). @@ -57,13 +60,37 @@ The file paths in the examples are for Windows. - `reduce_image_size D:\img_src D:\img_dst --recursive --resize --quality 60 --size L` ## Notes -- Updated and tested in Rust 1.89.0 on Apple silicon with macOS Sequoia 15.3. +- Updated and tested in Rust 1.89.0 and 1.90.0 on Apple silicon with macOS Sequoia 15.3.2. - First developed in Rust 1.74.1, but also tested later with Rust 1.79.0. - Tested on x86-64 CPUs on Windows 10 and Windows 11. - Tested on Apple silicon, M2 Pro, on macOS Sonoma 14.5. - Also tested on WSL - Ubuntu 22.04.2 LTS (GNU/Linux 5.15.133.1-microsoft-standard-WSL2 x86_64) on Windows 11 @ x86-64. - Linux wasn't tested directly, but should work, at least on x86-64 CPUs. +## Security + +- [cargo audit](https://github.com/rustsec/rustsec/blob/main/cargo-audit/README.md) is supported, + as well as its GitHub action, [audit-check](https://github.com/rustsec/audit-check). +- [cargo deny](https://embarkstudios.github.io/cargo-deny/) is supported, + as well as its GitHub action, [cargo-deny-action](https://github.com/EmbarkStudios/cargo-deny-action). + +## Development + +### Pre-commit + +[pre-commit](https://pre-commit.com/) hooks are supported. + +```shell +$ pip install pre-commit # If you don't already have pre-commit installed on your machine. Run once. +$ pre-commit autoupdate # Update hook repositories to the latest versions. +$ pre-commit install # Sets up the pre-commit git hook script for the repository. Run once. +$ pre-commit install --hook-type pre-push # Sets up the pre-push git hook script for the repository. Run once. +$ pre-commit run # For manual running; considers only modified files. +$ pre-commit run --all-files # For manual running; considers all files. +``` + +After installing it, the provided [pre-commit hook(s)](.pre-commit-config.yaml) will run automatically on `git commit`. + ## Running the Application Executable files for Windows, macOS and Linux can be downloaded from the [Releases](https://github.com/ivanbgd/reduce-image-size-rust/releases) page of the repository. diff --git a/deny.toml b/deny.toml new file mode 100644 index 0000000..8748802 --- /dev/null +++ b/deny.toml @@ -0,0 +1,250 @@ +# This template contains all of the possible sections and their default values + +# Note that all fields that take a lint level have these possible values: +# * deny - An error will be produced and the check will fail +# * warn - A warning will be produced, but the check will not fail +# * allow - No warning or error will be produced, though in some cases a note +# will be + +# The values provided in this template are the default values that will be used +# when any section or field is not specified in your own configuration + +# Root options + +# The graph table configures how the dependency graph is constructed and thus +# which crates the checks are performed against +[graph] +# If 1 or more target triples (and optionally, target_features) are specified, +# only the specified targets will be checked when running `cargo deny check`. +# This means, if a particular package is only ever used as a target specific +# dependency, such as, for example, the `nix` crate only being used via the +# `target_family = "unix"` configuration, that only having windows targets in +# this list would mean the nix crate, as well as any of its exclusive +# dependencies not shared by any other crates, would be ignored, as the target +# list here is effectively saying which targets you are building for. +targets = [ + # The triple can be any string, but only the target triples built in to + # rustc (as of 1.40) can be checked against actual config expressions + #"x86_64-unknown-linux-musl", + # You can also specify which target_features you promise are enabled for a + # particular target. target_features are currently not validated against + # the actual valid features supported by the target architecture. + #{ triple = "wasm32-unknown-unknown", features = ["atomics"] }, + "aarch64-unknown-linux-gnu", + "x86_64-unknown-linux-gnu", + "aarch64-apple-darwin", + "x86_64-apple-darwin", + "universal-apple-darwin", + "x86_64-pc-windows-msvc", + "x86_64-unknown-linux-musl", +] +# When creating the dependency graph used as the source of truth when checks are +# executed, this field can be used to prune crates from the graph, removing them +# from the view of cargo-deny. This is an extremely heavy hammer, as if a crate +# is pruned from the graph, all of its dependencies will also be pruned unless +# they are connected to another crate in the graph that hasn't been pruned, +# so it should be used with care. The identifiers are [Package ID Specifications] +# (https://doc.rust-lang.org/cargo/reference/pkgid-spec.html) +#exclude = [] +# If true, metadata will be collected with `--all-features`. Note that this can't +# be toggled off if true, if you want to conditionally enable `--all-features` it +# is recommended to pass `--all-features` on the cmd line instead +all-features = true # Was false by default. +# If true, metadata will be collected with `--no-default-features`. The same +# caveat with `all-features` applies +no-default-features = false +# If set, these feature will be enabled when collecting metadata. If `--features` +# is specified on the cmd line they will take precedence over this option. +#features = [] + +# The output table provides options for how/if diagnostics are outputted +[output] +# When outputting inclusion graphs in diagnostics that include features, this +# option can be used to specify the depth at which feature edges will be added. +# This option is included since the graphs can be quite large and the addition +# of features from the crate(s) to all of the graph roots can be far too verbose. +# This option can be overridden via `--feature-depth` on the cmd line +feature-depth = 1 + +# This section is considered when running `cargo deny check advisories` +# More documentation for the advisories section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/advisories/cfg.html +[advisories] +unmaintained = "workspace" +# The path where the advisory databases are cloned/fetched into +#db-path = "$CARGO_HOME/advisory-dbs" +# The url(s) of the advisory databases to use +#db-urls = ["https://github.com/rustsec/advisory-db"] +# A list of advisory IDs to ignore. Note that ignored advisories will still +# output a note when they are encountered. +ignore = [ + #"RUSTSEC-0000-0000", + #{ id = "RUSTSEC-0000-0000", reason = "you can specify a reason the advisory is ignored" }, + #"a-crate-that-is-yanked@0.1.1", # you can also ignore yanked crate versions if you wish + #{ crate = "a-crate-that-is-yanked@0.1.1", reason = "you can specify why you are ignoring the yanked crate" }, +] +# If this is true, then cargo deny will use the git executable to fetch advisory database. +# If this is false, then it uses a built-in git library. +# Setting this to true can be helpful if you have special authentication requirements that cargo-deny does not support. +# See Git Authentication for more information about setting up git authentication. +#git-fetch-with-cli = true + +# This section is considered when running `cargo deny check licenses` +# More documentation for the licenses section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/licenses/cfg.html +[licenses] +# List of explicitly allowed licenses +# See https://spdx.org/licenses/ for list of possible licenses +# [possible values: any SPDX 3.11 short identifier (+ optional exception)]. +allow = [ + "MIT", + "Apache-2.0", + #"Apache-2.0 WITH LLVM-exception", + #"BSD-2-Clause", + "BSD-3-Clause", + "Unicode-3.0", +] +# The confidence threshold for detecting a license from license text. +# The higher the value, the more closely the license text must be to the +# canonical license text of a valid SPDX license file. +# [possible values: any between 0.0 and 1.0]. +confidence-threshold = 0.93 +# Allow 1 or more licenses on a per-crate basis, so that particular licenses +# aren't accepted for every possible crate as with the normal allow list +exceptions = [ + # Each entry is the crate and version constraint, and its specific allow + # list + #{ allow = ["Zlib"], crate = "adler32" }, + { allow = ["BSD-2-Clause"], crate = "av1-grain" }, + { allow = ["BSD-2-Clause"], crate = "rav1e" }, + { allow = ["BSD-2-Clause"], crate = "v_frame" }, +] + +# Some crates don't have (easily) machine readable licensing information, +# adding a clarification entry for it allows you to manually specify the +# licensing information +#[[licenses.clarify]] +# The package spec the clarification applies to +#crate = "ring" +# The SPDX expression for the license requirements of the crate +#expression = "MIT AND ISC AND OpenSSL" +# One or more files in the crate's source used as the "source of truth" for +# the license expression. If the contents match, the clarification will be used +# when running the license check, otherwise the clarification will be ignored +# and the crate will be checked normally, which may produce warnings or errors +# depending on the rest of your configuration +#license-files = [ +# Each entry is a crate relative path, and the (opaque) hash of its contents +#{ path = "LICENSE", hash = 0xbd0eed23 } +#] + +[licenses.private] +# If true, ignores workspace crates that aren't published, or are only +# published to private registries. +# To see how to mark a crate as unpublished (to the official registry), +# visit https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish-field. +ignore = false +# One or more private registries that you might publish crates to, if a crate +# is only published to private registries, and ignore is true, the crate will +# not have its license(s) checked +registries = [ + #"https://sekretz.com/registry +] + +# This section is considered when running `cargo deny check bans`. +# More documentation about the 'bans' section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/bans/cfg.html +[bans] +# Lint level for when multiple versions of the same crate are detected +multiple-versions = "warn" +# Lint level for when a crate version requirement is `*` +wildcards = "allow" +# The graph highlighting used when creating dotgraphs for crates +# with multiple versions +# * lowest-version - The path to the lowest versioned duplicate is highlighted +# * simplest-path - The path to the version with the fewest edges is highlighted +# * all - Both lowest-version and simplest-path are used +highlight = "all" +# The default lint level for `default` features for crates that are members of +# the workspace that is being checked. This can be overridden by allowing/denying +# `default` on a crate-by-crate basis if desired. +workspace-default-features = "allow" +# The default lint level for `default` features for external crates that are not +# members of the workspace. This can be overridden by allowing/denying `default` +# on a crate-by-crate basis if desired. +external-default-features = "allow" +# List of crates that are allowed. Use with care! +allow = [ + #"ansi_term@0.11.0", + #{ crate = "ansi_term@0.11.0", reason = "you can specify a reason it is allowed" }, +] +# List of crates to deny +deny = [ + #"ansi_term@0.11.0", + #{ crate = "ansi_term@0.11.0", reason = "you can specify a reason it is banned" }, + # Wrapper crates can optionally be specified to allow the crate when it + # is a direct dependency of the otherwise banned crate + #{ crate = "ansi_term@0.11.0", wrappers = ["this-crate-directly-depends-on-ansi_term"] }, + { crate = "openssl", use-instead = "rustls"}, +] + +# List of features to allow/deny +# Each entry the name of a crate and a version range. If version is +# not specified, all versions will be matched. +#[[bans.features]] +#crate = "reqwest" +# Features to not allow +#deny = ["json"] +# Features to allow +#allow = [ +# "rustls", +# "__rustls", +# "__tls", +# "hyper-rustls", +# "rustls", +# "rustls-pemfile", +# "rustls-tls-webpki-roots", +# "tokio-rustls", +# "webpki-roots", +#] +# If true, the allowed features must exactly match the enabled feature set. If +# this is set there is no point setting `deny` +#exact = true + +# Certain crates/versions that will be skipped when doing duplicate detection. +skip = [ + #"ansi_term@0.11.0", + #{ crate = "ansi_term@0.11.0", reason = "you can specify a reason why it can't be updated/removed" }, +] +# Similarly to `skip` allows you to skip certain crates during duplicate +# detection. Unlike skip, it also includes the entire tree of transitive +# dependencies starting at the specified crate, up to a certain depth, which is +# by default infinite. +skip-tree = [ + #"ansi_term@0.11.0", # will be skipped along with _all_ of its direct and transitive dependencies + #{ crate = "ansi_term@0.11.0", depth = 20 }, +] + +# This section is considered when running `cargo deny check sources`. +# More documentation about the 'sources' section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/sources/cfg.html +[sources] +# Lint level for what to happen when a crate from a crate registry that is not +# in the allow list is encountered +unknown-registry = "warn" +# Lint level for what to happen when a crate from a git repository that is not +# in the allow list is encountered +unknown-git = "warn" +# List of URLs for allowed crate registries. Defaults to the crates.io index +# if not specified. If it is specified but empty, no registries are allowed. +allow-registry = ["https://github.com/rust-lang/crates.io-index"] +# List of URLs for allowed Git repositories +allow-git = [] + +[sources.allow-org] +# github.com organizations to allow git sources for +github = [] +# gitlab.com organizations to allow git sources for +gitlab = [] +# bitbucket.org organizations to allow git sources for +bitbucket = []