refactor: check scripts for justfile

chore: ci run examples
This commit is contained in:
thesimplekid
2024-08-19 01:02:45 +02:00
parent 9eff00bcaf
commit 65163b89bc
15 changed files with 93 additions and 171 deletions

View File

@@ -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 }}

View File

@@ -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(""),

View File

@@ -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(""),

View File

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

View File

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

View File

@@ -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
misc/justfile.custom.just Normal file
View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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