diff --git a/callinectes.sh b/callinectes.sh index 6d778ca..727c6a9 100755 --- a/callinectes.sh +++ b/callinectes.sh @@ -6,74 +6,90 @@ set -e usage() { echo - echo "Available checks:" + echo "Available tasks:" echo - echo "code # Runs static analysers against Rust sources" - echo "deps # Inspects dependencies and drive SCA checks" + echo "fmt # Checks formatting on Rust source files" + echo "clippy # Runs Clippy lints against Rust source files" + echo "deny # Checks vulnerabilities and compliance of project dependencies" + echo "udeps # Checks unused dependencies declared in Cargo.toml files" + echo "msrv # Checks the Minimal Supported Rust Version for the project" + echo "cyclonedx # Generates a CycloneDx SBOM file from project dependencies" echo } -check_code_smells() { +check_sources_formatting() { echo echo "🦀 Checking code formatting (rustfmt)" echo - rustup component add rustfmt cargo fmt --check +} +lint_source_files() { echo echo "🦀 Checking code smells (clippy)" echo - rustup component add clippy cargo clippy --all-targets --all-features -- -D warnings +} +check_vulnerable_dependencies() { echo - echo "✅ Code quality checked with success" + echo "🦀 Checking supply chain issues (cargo-deny)" echo + cargo deny check } -check_supply_chain() { +check_unused_dependencies() { echo - echo "🦀 Running cargo-msrv" + echo "🦀 Checking declared and unused dependencies (cargo-udeps)" echo - cargo msrv verify + # rustup default nightly + cargo +nightly udeps +} +check_msrv() { echo - echo "🦀 Running cargo-deny" + echo "🦀 Checking Minimal Supported Rust Version (cargo-msrv)" echo - cargo deny check + cargo msrv verify +} +generate_cyclonedx_sbom() { echo - echo "🦀 Running cargo-cyclonedx" + echo "🦀 Generating CycloneDX SBOM (cargo-cyclonedx)" echo cargo cyclonedx --format json - - echo - echo "🦀 Running cargo-udeps" - rustup default nightly - cargo +nightly udeps - - echo - echo "✅ Supply-chain checked with success" - echo } -readonly what="$1" - -if [[ -z "$what" ]]; then +if test "$#" -eq 0; then usage exit 0 fi -case "$what" in -"code") - check_code_smells - ;; -"deps") - check_supply_chain - ;; -*) - echo "Error: unsupported check → $what" - usage - exit 1 - ;; -esac +while test "$#" -gt 0; do + case "$1" in + "fmt") + check_sources_formatting + ;; + "clippy") + lint_source_files + ;; + "deny") + check_vulnerable_dependencies + ;; + "udeps") + check_unused_dependencies + ;; + "msrv") + check_msrv + ;; + "cyclonedx") + generate_cyclonedx_sbom + ;; + *) + echo "Error: unsupported task → $1" + usage + exit 1 + ;; + esac + shift +done diff --git a/cargo-plugins.sh b/cargo-plugins.sh index 867c382..ccbb3f6 100755 --- a/cargo-plugins.sh +++ b/cargo-plugins.sh @@ -8,6 +8,8 @@ echo echo "🦀 Installing Rust toolchains" rustup target add aarch64-unknown-linux-gnu rustup target add x86_64-unknown-linux-gnu +rustup component add rustfmt +rustup component add clippy echo echo "🦀 Installing cargo-deny" diff --git a/component-tests.sh b/component-tests.sh index 40934af..dbbcf05 100755 --- a/component-tests.sh +++ b/component-tests.sh @@ -19,12 +19,17 @@ docker build . -t dotanuki-labs/callinectes echo echo "🔥 Checking code smells" echo -docker run --rm -v "$temp_folder:/usr/src" dotanuki-labs/callinectes code +docker run --rm -v "$temp_folder:/usr/src" dotanuki-labs/callinectes fmt clippy + +echo +echo "🔥 Checking MSRV" +echo +docker run --rm -v "$temp_folder:/usr/src" dotanuki-labs/callinectes msrv echo echo "🔥 Checking dependencies" echo -docker run --rm -v "$temp_folder:/usr/src" dotanuki-labs/callinectes deps +docker run --rm -v "$temp_folder:/usr/src" dotanuki-labs/callinectes deny sbom udeps echo echo "✅ Done"