From 02fd33225c9caa82faf717021ab2410ede03582a Mon Sep 17 00:00:00 2001 From: Yuki Kishimoto Date: Tue, 9 Apr 2024 20:01:05 +0200 Subject: [PATCH] Add `misc/scripts` Signed-off-by: Yuki Kishimoto --- justfile | 11 +++++++++ misc/scripts/check-crates.sh | 46 ++++++++++++++++++++++++++++++++++++ misc/scripts/check-docs.sh | 14 +++++++++++ misc/scripts/check-fmt.sh | 17 +++++++++++++ misc/scripts/check.sh | 11 +++++++++ misc/scripts/precommit.sh | 10 ++++++++ 6 files changed, 109 insertions(+) create mode 100755 misc/scripts/check-crates.sh create mode 100755 misc/scripts/check-docs.sh create mode 100755 misc/scripts/check-fmt.sh create mode 100755 misc/scripts/check.sh create mode 100755 misc/scripts/precommit.sh diff --git a/justfile b/justfile index 022c1f68..5203eb71 100644 --- a/justfile +++ b/justfile @@ -9,6 +9,17 @@ alias t := test default: @just --list +# Execute a partial check (MSRV is not checked) +precommit: + @bash misc/scripts/precommit.sh + +# Format the entire Rust code +fmt: + @bash misc/scripts/check-fmt.sh + +# Check if the Rust code is formatted +check-fmt: + @bash misc/scripts/check-fmt.sh check # run `cargo build` on everything build *ARGS="--workspace --all-targets": diff --git a/misc/scripts/check-crates.sh b/misc/scripts/check-crates.sh new file mode 100755 index 00000000..2bd8d5ea --- /dev/null +++ b/misc/scripts/check-crates.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +set -euo pipefail + +# MSRV +msrv="1.70.0" + +is_msrv=false +version="" + +# Check if "msrv" is passed as an argument +if [[ "$#" -gt 0 && "$1" == "msrv" ]]; then + is_msrv=true + version="+$msrv" +fi + +# Check if MSRV +if [ "$is_msrv" == true ]; then + # Install MSRV + rustup install $msrv + rustup component add clippy --toolchain $msrv + rustup target add wasm32-unknown-unknown --toolchain $msrv +fi + +buildargs=( + "-p cashu" + "-p cashu --no-default-features" + "-p cashu --no-default-features --features wallet" + "-p cashu --no-default-features --features mint" + "-p cashu-sdk" + "-p cashu-sdk --no-default-features" +) + +for arg in "${buildargs[@]}"; do + if [[ $version == "" ]]; then + echo "Checking '$arg' [default]" + else + echo "Checking '$arg' [$version]" + fi + cargo $version check $arg + if [[ $arg != *"--target wasm32-unknown-unknown"* ]]; then + cargo $version test $arg + fi + cargo $version clippy $arg -- -D warnings + echo +done diff --git a/misc/scripts/check-docs.sh b/misc/scripts/check-docs.sh new file mode 100755 index 00000000..085e4d2f --- /dev/null +++ b/misc/scripts/check-docs.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -euo pipefail + +buildargs=( + "-p cashu" + "-p cashu-sdk" +) + +for arg in "${buildargs[@]}"; do + echo "Checking '$arg' docs" + cargo doc $arg --all-features + echo +done diff --git a/misc/scripts/check-fmt.sh b/misc/scripts/check-fmt.sh new file mode 100755 index 00000000..480f1bab --- /dev/null +++ b/misc/scripts/check-fmt.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -euo pipefail + +flags="" + +# Check if "check" is passed as an argument +if [[ "$#" -gt 0 && "$1" == "check" ]]; then + flags="--check" +fi + +# Install toolchain +rustup install nightly-2024-01-11 +rustup component add rustfmt --toolchain nightly-2024-01-11 + +# Check workspace crates +cargo +nightly-2024-01-11 fmt --all -- --config format_code_in_doc_comments=true $flags diff --git a/misc/scripts/check.sh b/misc/scripts/check.sh new file mode 100755 index 00000000..df9ec5de --- /dev/null +++ b/misc/scripts/check.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -exuo pipefail + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +"${DIR}/check-fmt.sh" check # Check if Rust code is formatted +"${DIR}/check-crates.sh" # Check all crates +"${DIR}/check-crates.sh" msrv # Check all crates MSRV +#"${DIR}/check-bindings.sh" # Check all bindings +"${DIR}/check-docs.sh" # Check Rust docs diff --git a/misc/scripts/precommit.sh b/misc/scripts/precommit.sh new file mode 100755 index 00000000..ac15b262 --- /dev/null +++ b/misc/scripts/precommit.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -exuo pipefail + +DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +"${DIR}/check-fmt.sh" # Format the code +"${DIR}/check-crates.sh" # Check all crates +#"${DIR}/check-bindings.sh" # Check all bindings +"${DIR}/check-docs.sh" # Check Rust docs