Skip to content

Commit

Permalink
tweak: Rename check.sh to format-check.sh and add check.sh to d…
Browse files Browse the repository at this point in the history
…o a compile check.
  • Loading branch information
dhedey committed Oct 31, 2024
1 parent 1aacdf0 commit af29b41
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ cd "$(dirname "$0")"

echo "[PRE-COMMIT] Formatting assertion"

../../check.sh --quiet || { echo "[PRE-COMMIT] Formatting check FAIL: Committing aborted"; exit 1; }
../../format-check.sh --quiet || { echo "[PRE-COMMIT] Formatting check FAIL: Committing aborted"; exit 1; }

echo "[PRE-COMMIT] Formatting check PASS"
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
- name: Setup environment
uses: ./.github/actions/setup-env
- name: Check format
run: bash ./check.sh
run: bash ./format-check.sh

sbor-unit-tests:
name: Run SBOR unit tests
Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

cd "$(dirname "$0")"

# This should align with format.sh, check.sh, test.sh, clean.sh, update-cargo-locks-minimally.sh
# This should align with format.sh, format-check.sh, check.sh, test.sh, clean.sh, update-cargo-locks-minimally.sh
echo "Building the workspace packages and tests (with all extended features)..."

(set -x; cargo build; cargo test --no-run; cargo bench --no-run)
Expand Down
4 changes: 2 additions & 2 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ packages+="$(find examples -mindepth 2 -maxdepth 2 -type f \( -name Cargo.toml \

for package in $packages; do
folder=$(dirname $package)
(cd $folder; cargo fmt --check $quiet_flag) || { echo "$lf>> Code format check FAILED for $package$lf"; failed=1; }
(cd $folder; cargo check $quiet_flag) || { echo "$lf>> Code compile check FAILED for $package$lf"; failed=1; }
done

[ $failed -eq 0 ] && echo "Code format check passed!"
[ $failed -eq 0 ] && echo "Code compile check passed!"
exit $failed
43 changes: 43 additions & 0 deletions format-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

set -eE

err_report() {
echo "Something went wrong on line $1"
}

quiet_flag=""

if [ "$1" = "--quiet" ]
then quiet_flag="--quiet"
fi

trap 'err_report $LINENO' ERR

failed=0
lf=$'\n'

cd "$(dirname "$0")"

# We use the cd trick to avoid issues like this: https://github.com/rust-lang/rustfmt/issues/4432

# This should align with format.sh, build.sh, test.sh, clean.sh, update-cargo-locks-minimally.sh
# ... and at some point, we should replace all these with a shared
# workspace lister function which returns this list stripped of Cargo.tomls
# and can be used by all these scripts to save duplication.
packages="Cargo.toml$lf"
packages+="radix-engine-tests/assets/blueprints/Cargo.toml$lf"
packages+="radix-clis/tests/blueprints/Cargo.toml$lf"
packages+="scrypto-test/tests/blueprints/Cargo.toml$lf"
packages+="scrypto-test/assets/blueprints/Cargo.toml$lf"
packages+="scrypto-compiler/tests/assets/scenario_1/Cargo.toml$lf"
packages+="scrypto-compiler/tests/assets/scenario_2/Cargo.toml$lf"
packages+="$(find examples -mindepth 2 -maxdepth 2 -type f \( -name Cargo.toml \))$lf"

for package in $packages; do
folder=$(dirname $package)
(cd $folder; cargo fmt --check $quiet_flag) || { echo "$lf>> Code format check FAILED for $package$lf"; failed=1; }
done

[ $failed -eq 0 ] && echo "Code format check passed!"
exit $failed
2 changes: 1 addition & 1 deletion format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

cd "$(dirname "$0")"

# This should align with check.sh, build.sh, test.sh, clean.sh, update-cargo-locks-minimally.sh
# This should align with format-check.sh, check.sh, build.sh, test.sh, clean.sh, update-cargo-locks-minimally.sh

(set -x; cd .; cargo fmt)
(set -x; cd radix-engine-tests/assets/blueprints; cargo fmt)
Expand Down
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if cargo help nextest 2>/dev/null >&2 ; then
doc_test_separately=1
fi

# This should align with check.sh, build.sh, format.sh, clean.sh, update-cargo-locks-minimally.sh
# This should align with format-check.sh, check.sh, build.sh, format.sh, clean.sh, update-cargo-locks-minimally.sh

echo "Running tests..."
(set -x; cd .; cargo $cargo_test_runner)
Expand Down
2 changes: 1 addition & 1 deletion update-cargo-locks-minimally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set -e
# > the lock file [PATH]/Cargo.lock needs to be updated but --locked was passed to prevent this
# > If you want to try to generate the lock file without accessing the network, remove the --locked flag and use --offline instead.

# This should align with format.sh, check.sh, build.sh, test.sh
# This should align with format.sh, format-check.sh, check.sh, build.sh, test.sh

(set -x; cd .; cargo update --workspace)

Expand Down

0 comments on commit af29b41

Please sign in to comment.