Parcourir la source

refactor: check scripts for justfile

chore: ci run examples
thesimplekid il y a 7 mois
Parent
commit
65163b89bc

+ 30 - 1
.github/workflows/ci.yml

@@ -39,7 +39,6 @@ jobs:
             -p cdk-integration-tests,
             --bin cdk-cli,
             --bin cdk-mintd,
-            --examples
           ]
     steps:
     - name: Checkout
@@ -96,3 +95,33 @@ jobs:
       run: cargo build ${{ matrix.build-args }} --target wasm32-unknown-unknown
     - name: Clippy
       run: cargo clippy ${{ matrix.build-args }} --target wasm32-unknown-unknown -- -D warnings
+
+  run-examples:
+    name: Run Examples
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        rust:
+          - version: stable
+        build-args:
+          [
+          mint-token,
+          p2pk,
+          proof-selection,
+          wallet
+          ]
+    steps:
+    - name: Checkout
+      uses: actions/checkout@v3
+    - name: Cache
+      uses: actions/cache@v3
+      with:
+        path: |
+          ~/.cargo/registry
+          ~/.cargo/git
+          target
+        key: ${{ runner.os }}-cargo-wasm32-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
+    - name: Set default toolchain
+      run: rustup default ${{ matrix.rust.version }}
+    - name: Run
+      run: cargo run --example ${{ matrix.build-args }}

+ 2 - 2
crates/cdk-integration-tests/tests/mint.rs

@@ -26,7 +26,7 @@ pub async fn test_mint_double_receive() -> Result<()> {
     let mnemonic = Mnemonic::generate(12)?;
 
     let wallet = Wallet::new(
-        &MINT_URL,
+        MINT_URL,
         CurrencyUnit::Sat,
         Arc::new(WalletMemoryDatabase::default()),
         &mnemonic.to_seed_normalized(""),
@@ -51,7 +51,7 @@ pub async fn test_mint_double_receive() -> Result<()> {
     let mnemonic = Mnemonic::generate(12)?;
 
     let wallet_two = Wallet::new(
-        &MINT_URL,
+        MINT_URL,
         CurrencyUnit::Sat,
         Arc::new(WalletMemoryDatabase::default()),
         &mnemonic.to_seed_normalized(""),

+ 1 - 1
crates/cdk-integration-tests/tests/p2pk.rs

@@ -22,7 +22,7 @@ pub async fn test_p2pk_swap() -> Result<()> {
     let mnemonic = Mnemonic::generate(12)?;
 
     let wallet = Wallet::new(
-        &MINT_URL,
+        MINT_URL,
         CurrencyUnit::Sat,
         Arc::new(WalletMemoryDatabase::default()),
         &mnemonic.to_seed_normalized(""),

+ 1 - 1
crates/cdk/Cargo.toml

@@ -70,7 +70,7 @@ name = "wallet"
 required-features = ["wallet"]
 
 [[example]]
-name = "proof_selection"
+name = "proof-selection"
 required-features = ["wallet"]
 
 [dev-dependencies]

+ 0 - 0
crates/cdk/examples/proof_selection.rs → crates/cdk/examples/proof-selection.rs


+ 1 - 1
flake.nix

@@ -23,7 +23,7 @@
             name = "cdk";
             path = ./.;
           };
-          paths = [ "crates/cashu" "crates/cashu-sdk" ];
+          paths = [ "crates/*" ];
         };
 
         targetsStd = flakeboxLib.mkStdTargets { };

+ 2 - 13
justfile

@@ -1,4 +1,5 @@
 # THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION
+import "./misc/justfile.custom.just"
 
 alias b := build
 alias c := check
@@ -9,18 +10,6 @@ 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":
   #!/usr/bin/env bash
@@ -42,7 +31,7 @@ check *ARGS="--workspace --all-targets":
 
 
 # run all checks recommended before opening a PR
-final-check: lint clippy
+final-check: lint clippy check-wasm
   #!/usr/bin/env bash
   set -euo pipefail
   if [ ! -f Cargo.toml ]; then

+ 56 - 0
misc/justfile.custom.just

@@ -0,0 +1,56 @@
+check-wasm *ARGS="--target wasm32-unknown-unknown":
+  #!/usr/bin/env bash
+  set -euo pipefail
+
+  if [ ! -f Cargo.toml ]; then
+    cd {{invocation_directory()}}
+  fi
+
+  buildargs=(
+    "-p cdk"
+    "-p cdk --no-default-features"
+    "-p cdk --no-default-features --features wallet"
+    "-p cdk --no-default-features --features mint"
+    "-p cdk-js"
+  )
+
+  for arg in "${buildargs[@]}"; do
+    echo  "Checking '$arg'"
+    cargo check $arg {{ARGS}}
+    echo
+  done
+
+run-examples:
+  cargo r --example p2pk
+  cargo r --example mint-token
+  cargo r --example proof_selection
+  cargo r --example wallet
+
+clippy-each:
+  #!/usr/bin/env bash
+  set -euo pipefail
+  buildargs=(
+  "-p cdk-integration-tests"
+  "-p cdk"
+  "-p cdk --no-default-features"
+  "-p cdk --no-default-features --features wallet"
+  "-p cdk --no-default-features --features mint"
+  "-p cdk-redb"
+  "-p cdk-redb --no-default-features --features wallet"
+  "-p cdk-redb --no-default-features --features mint"
+  "-p cdk-sqlite --no-default-features --features mint"
+  "-p cdk-sqlite --no-default-features --features wallet"
+  "-p cdk-cln"
+  "-p cdk-axum"
+  "-p cdk-fake-wallet"
+  "-p cdk-strike"
+  "--bin cdk-cli"
+  "--bin cdk-mintd"
+  )
+
+  for arg in "${buildargs[@]}"; do
+    echo  "Checking '$arg'"
+    cargo check $arg
+    cargo clippy $arg -- -D warnings
+    echo
+  done

+ 0 - 23
misc/scripts/check-bindings.sh

@@ -1,23 +0,0 @@
-#!/usr/bin/env bash
-
-set -euo pipefail
-
-# Check bindings
-buildargs=(
-    "-p cdk-js --target wasm32-unknown-unknown"
-)
-
-for arg in "${buildargs[@]}"; do
-    echo  "Checking '$arg'"
-
-    cargo build $arg
-
-    if [[ $arg != *"--target wasm32-unknown-unknown"* ]];
-    then
-        cargo test $arg
-    fi
-
-    cargo clippy $arg -- -D warnings
-
-    echo
-done

+ 0 - 57
misc/scripts/check-crates.sh

@@ -1,57 +0,0 @@
-#!/usr/bin/env 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 cdk-integration-tests"
-    "-p cdk"
-    "-p cdk --no-default-features"
-    "-p cdk --no-default-features --features wallet"
-    "-p cdk --no-default-features --features mint"
-    "-p cdk-redb"
-    "-p cdk-redb --no-default-features --features wallet"
-    "-p cdk-redb --no-default-features --features mint"
-    "-p cdk-sqlite --no-default-features --features mint"
-    "-p cdk-sqlite --no-default-features --features wallet"
-    "-p cdk-cln"
-    "-p cdk-axum"
-    "-p cdk-fake-wallet"
-    "-p cdk-strike"
-    "--bin cdk-cli"
-    "--bin cdk-mintd"
-    "--examples"
-)
-
-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

+ 0 - 13
misc/scripts/check-docs.sh

@@ -1,13 +0,0 @@
-#!/usr/bin/env bash
-
-set -euo pipefail
-
-buildargs=(
-    "-p cdk"
-)
-
-for arg in "${buildargs[@]}"; do
-    echo  "Checking '$arg' docs"
-    cargo doc $arg --all-features
-    echo
-done

+ 0 - 14
misc/scripts/check-fmt.sh

@@ -1,14 +0,0 @@
-#!/usr/bin/env bash
-
-set -euo pipefail
-
-flags=""
-
-# Check if "check" is passed as an argument
-if [[ "$#" -gt 0 && "$1" == "check" ]]; then
-    flags="--check"
-fi
-
-
-# Check workspace crates
-cargo fmt --all -- --config format_code_in_doc_comments=true $flags

+ 0 - 11
misc/scripts/check.sh

@@ -1,11 +0,0 @@
-#!/usr/bin/env 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

+ 0 - 11
misc/scripts/precommit.sh

@@ -1,11 +0,0 @@
-#!/usr/bin/env bash
-
-set -exuo pipefail
-
-DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
-
-typos
-"${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

+ 0 - 23
misc/scripts/release.sh

@@ -1,23 +0,0 @@
-#!/usr/bin/env bash
-
-set -euo pipefail
-
-args=(
-    "-p cdk"
-    "-p cdk-redb"
-    "-p cdk-sqlite"
-    "-p cdk-rexie"
-    "-p cdk-cln"
-    "-p cdk-fake-wallet"
-    "-p cdk-strike"
-    "-p cdk-cli"
-    "-p cdk-axum"
-    "-p cdk-mintd"
-)
-
-for arg in "${args[@]}";
-do
-    echo "Publishing '$arg'"
-    cargo publish "$arg"
-    echo
-done