Quellcode durchsuchen

Add `misc/scripts`

Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
Yuki Kishimoto vor 11 Monaten
Ursprung
Commit
02fd33225c
6 geänderte Dateien mit 109 neuen und 0 gelöschten Zeilen
  1. 11 0
      justfile
  2. 46 0
      misc/scripts/check-crates.sh
  3. 14 0
      misc/scripts/check-docs.sh
  4. 17 0
      misc/scripts/check-fmt.sh
  5. 11 0
      misc/scripts/check.sh
  6. 10 0
      misc/scripts/precommit.sh

+ 11 - 0
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":

+ 46 - 0
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

+ 14 - 0
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

+ 17 - 0
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

+ 11 - 0
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

+ 10 - 0
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