From ab610055791f192bcf3fced87e8c5986493d4fa5 Mon Sep 17 00:00:00 2001 From: "kody.low" Date: Mon, 8 Apr 2024 16:27:31 -0700 Subject: [PATCH] chore: bump flakebox --- .config/flakebox/id | 2 +- .config/flakebox/shellHook.sh | 12 --- JUSTFILE | 12 ++- misc/git-hooks/pre-commit | 196 ++++++++++++++++------------------ 4 files changed, 106 insertions(+), 116 deletions(-) diff --git a/.config/flakebox/id b/.config/flakebox/id index 665453f..c248762 100644 --- a/.config/flakebox/id +++ b/.config/flakebox/id @@ -1 +1 @@ -3df12aefd7925a90e8a0e09b721df7d8435ed993774832d5aca2cba090b3d23e11f68bd4826bbf10ca7944dcfa82165dcd5285634f9fcf76e00308bb314664bb +4554d31c5e79420d5b097aad56a49a1c61bb89f32d6b93fb5ff4d0677bc9b587e3426e881d01f5551ff816cfcec2941d0529130f491f6098abb64e6c28592c94 diff --git a/.config/flakebox/shellHook.sh b/.config/flakebox/shellHook.sh index 0a15c65..136ed52 100644 --- a/.config/flakebox/shellHook.sh +++ b/.config/flakebox/shellHook.sh @@ -1,16 +1,4 @@ #!/usr/bin/env bash -yesterday=$(date -d "yesterday" +%s) -motd_ts_path=".config/flakebox/tmp/motd" - -if [ ! -e "$motd_ts_path" ] || [ "$motd_ts_path" -ot "$yesterday" ]; then -mkdir -p "$(dirname "$motd_ts_path")" -touch "$motd_ts_path" ->&2 echo "🚧 In an enfort to improve documentation, we now require all structs and" ->&2 echo "🚧 and public methods to be documented with a docstring." ->&2 echo "🚧 See https://github.com/fedimint/fedimint/issues/3807" - -fi - root="$(git rev-parse --show-toplevel)" dot_git="$(git rev-parse --git-common-dir)" if [[ ! -d "${dot_git}/hooks" ]]; then mkdir -p "${dot_git}/hooks"; fi diff --git a/JUSTFILE b/JUSTFILE index d0f429c..022c1f6 100644 --- a/JUSTFILE +++ b/JUSTFILE @@ -1,5 +1,4 @@ # THIS FILE IS AUTOGENERATED FROM FLAKEBOX CONFIGURATION -import "justfile.local.just" alias b := build alias c := check @@ -31,6 +30,17 @@ check *ARGS="--workspace --all-targets": cargo check {{ARGS}} +# run all checks recommended before opening a PR +final-check: lint clippy + #!/usr/bin/env bash + set -euo pipefail + if [ ! -f Cargo.toml ]; then + cd {{invocation_directory()}} + fi + cargo test --doc + just test + + # run code formatters format: #!/usr/bin/env bash diff --git a/misc/git-hooks/pre-commit b/misc/git-hooks/pre-commit index 0b6a19f..7959e97 100755 --- a/misc/git-hooks/pre-commit +++ b/misc/git-hooks/pre-commit @@ -9,13 +9,13 @@ set -e # Revert `git stash` on exit function revert_git_stash { - echo >&2 "Unstashing uncommitted changes..." + >&2 echo "Unstashing uncommitted changes..." git stash pop -q } # Stash pending changes and revert them when script ends if [ -z "${NO_STASH:-}" ] && [ $is_unclean -ne 0 ]; then - echo >&2 "Stashing uncommitted changes..." + >&2 echo "Stashing uncommitted changes..." GIT_LITERAL_PATHSPECS=0 git stash -q --keep-index trap revert_git_stash EXIT fi @@ -25,154 +25,146 @@ FLAKEBOX_GIT_LS="$(git ls-files)" export FLAKEBOX_GIT_LS_TEXT FLAKEBOX_GIT_LS_TEXT="$(echo "$FLAKEBOX_GIT_LS" | grep -v -E "\.(png|ods|jpg|jpeg|woff2|keystore|wasm|ttf|jar|ico|gif)\$")" + function check_nothing() { true } export -f check_nothing function check_cargo_fmt() { - set -euo pipefail + set -euo pipefail - flakebox-in-each-cargo-workspace cargo fmt --all --check + flakebox-in-each-cargo-workspace cargo fmt --all --check } export -f check_cargo_fmt function check_cargo_lock() { - set -euo pipefail + set -euo pipefail - # https://users.rust-lang.org/t/check-if-the-cargo-lock-is-up-to-date-without-building-anything/91048/5 - flakebox-in-each-cargo-workspace cargo update --workspace --locked + # https://users.rust-lang.org/t/check-if-the-cargo-lock-is-up-to-date-without-building-anything/91048/5 + flakebox-in-each-cargo-workspace cargo update --workspace --locked } export -f check_cargo_lock -function check_check_forbidden_dependencies() { - set -euo pipefail - - #!/usr/bin/env bash - - set -eo pipefail - - if grep -E "(fedimint-mint|fedimint-wallet|fedimint-ln)" fedimint-server/Cargo.toml >&2; then - echo >&2 "fedimint-server/Cargo.toml must not depend on modules" - return 1 - fi - if grep -E "(fedimint-mint|fedimint-wallet|fedimint-ln-(server|common|client))" fedimint-testing/Cargo.toml >&2; then - echo >&2 "fedimint-testing/Cargo.toml must not depend on modules" - return 1 - fi - find gateway/ -name Cargo.toml | while read -r cargo_toml; do - if grep -E "fedimint-server" "$cargo_toml" >&2; then - echo >&2 "$cargo_toml must not depend on fedimint-server" - return 1 - fi - done - find fedimint-client/ -name Cargo.toml | while read -r cargo_toml; do - if grep -E "fedimint-server" "$cargo_toml" >&2; then - echo >&2 "$cargo_toml must not depend on fedimint-server" - return 1 - fi - done - find ./ -name Cargo.lock | while read -r cargo_lock; do - if grep -E "openssl" "$cargo_lock" >&2; then - echo >&2 "$cargo_lock must not depend on openssl" - return 1 - fi - done - -} -export -f check_check_forbidden_dependencies - function check_leftover_dbg() { - set -euo pipefail - - errors="" - for path in $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep '.*\.rs'); do - if grep 'dbg!(' "$path" >/dev/null; then - echo >&2 "$path contains dbg! macro" - errors="true" + set -euo pipefail + + errors="" + for path in $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep '.*\.rs'); do + if grep 'dbg!(' "$path" > /dev/null; then + >&2 echo "$path contains dbg! macro" + errors="true" + fi + done + + if [ -n "$errors" ]; then + >&2 echo "Fix the problems above or use --no-verify" 1>&2 + return 1 fi - done - - if [ -n "$errors" ]; then - echo >&2 "Fix the problems above or use --no-verify" 1>&2 - return 1 - fi } export -f check_leftover_dbg function check_semgrep() { - set -euo pipefail + set -euo pipefail - # semgrep is not available on MacOS - if ! command -v semgrep >/dev/null; then - echo >&2 "Skipping semgrep check: not available" - return 0 - fi + # semgrep is not available on MacOS + if ! command -v semgrep > /dev/null ; then + >&2 echo "Skipping semgrep check: not available" + return 0 + fi - if [ ! -f .config/semgrep.yaml ]; then - echo >&2 "Skipping semgrep check: .config/semgrep.yaml doesn't exist" - return 0 - fi + if [ ! -f .config/semgrep.yaml ] ; then + >&2 echo "Skipping semgrep check: .config/semgrep.yaml doesn't exist" + return 0 + fi - if [ ! -s .config/semgrep.yaml ]; then - echo >&2 "Skipping semgrep check: .config/semgrep.yaml empty" - return 0 - fi + if [ ! -s .config/semgrep.yaml ] ; then + >&2 echo "Skipping semgrep check: .config/semgrep.yaml empty" + return 0 + fi - env SEMGREP_ENABLE_VERSION_CHECK=0 \ - semgrep -q --error --no-rewrite-rule-ids --config .config/semgrep.yaml + env SEMGREP_ENABLE_VERSION_CHECK=0 \ + semgrep -q --error --no-rewrite-rule-ids --config .config/semgrep.yaml } export -f check_semgrep function check_shellcheck() { - set -euo pipefail + set -euo pipefail - for path in $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep -E '.*\.sh$'); do - shellcheck --severity=warning "$path" - done + for path in $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep -E '.*\.sh$'); do + shellcheck --severity=warning "$path" + done } export -f check_shellcheck +function check_trailing_newline() { + set -euo pipefail + + errors="" + for path in $(echo "$FLAKEBOX_GIT_LS_TEXT"); do + + # extra branches for clarity + if [ ! -s "$path" ]; then + # echo "$path is empty" + true + elif [ -z "$(tail -c 1 < "$path")" ]; then + # echo "$path ends with a newline or with a null byte" + true + else + >&2 echo "$path doesn't end with a newline" 1>&2 + errors="true" + fi + done + + if [ -n "$errors" ]; then + >&2 echo "Fix the problems above or use --no-verify" 1>&2 + return 1 + fi + +} +export -f check_trailing_newline + function check_trailing_whitespace() { - set -euo pipefail - - rev="HEAD" - if ! git rev-parse -q HEAD 1>/dev/null 2>/dev/null; then - echo >&2 "Warning: no commits yet, checking against --root" - rev="--root" - fi - if ! git diff --check $rev; then - echo >&2 "Trailing whitespace detected. Please remove them before committing." - return 1 - fi + set -euo pipefail + + rev="HEAD" + if ! git rev-parse -q 1>/dev/null HEAD 2>/dev/null ; then + >&2 echo "Warning: no commits yet, checking against --root" + rev="--root" + fi + if ! git diff --check $rev ; then + >&2 echo "Trailing whitespace detected. Please remove them before committing." + return 1 + fi } export -f check_trailing_whitespace function check_typos() { - set -euo pipefail + set -euo pipefail - if ! echo "$FLAKEBOX_GIT_LS_TEXT" | typos --file-list - --force-exclude; then - echo >&2 "Typos found: Valid new words can be added to '.typos.toml'" - return 1 - fi + if ! echo "$FLAKEBOX_GIT_LS_TEXT" | typos --file-list - --force-exclude ; then + >&2 echo "Typos found: Valid new words can be added to '.typos.toml'" + return 1 + fi } export -f check_typos parallel \ --nonotice \ - ::: \ - check_cargo_fmt \ - check_cargo_lock \ - check_leftover_dbg \ - check_semgrep \ - check_shellcheck \ - check_trailing_whitespace \ - check_typos \ - check_nothing # check_check_forbidden_dependencies \ +::: \ + check_cargo_fmt \ + check_cargo_lock \ + check_leftover_dbg \ + check_semgrep \ + check_shellcheck \ + check_trailing_newline \ + check_trailing_whitespace \ + check_typos \ + check_nothing