Skip to content

Commit

Permalink
Reworks supported tasks and public API
Browse files Browse the repository at this point in the history
  • Loading branch information
ubiratansoares committed Sep 3, 2024
1 parent 38f941e commit 61bd9aa
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 40 deletions.
92 changes: 54 additions & 38 deletions callinectes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions cargo-plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 7 additions & 2 deletions component-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 61bd9aa

Please sign in to comment.