39 lines
1.3 KiB
Shell
39 lines
1.3 KiB
Shell
|
|
#!/usr/bin/env bash
|
||
|
|
# The checks every push has to pass: formatting, static analysis (infos are fatal too) and
|
||
|
|
# the server tests. The pre-push hook runs this script, and a CI runner can run it later.
|
||
|
|
#
|
||
|
|
# Install the hook in a fresh clone: ln -s ../../tool/check.sh .git/hooks/pre-push
|
||
|
|
# Skip it for one push: git push --no-verify
|
||
|
|
#
|
||
|
|
# It checks the working tree, so uncommitted changes count as well.
|
||
|
|
set -euo pipefail
|
||
|
|
cd "$(git rev-parse --show-toplevel)"
|
||
|
|
|
||
|
|
if ! git diff --quiet HEAD; then
|
||
|
|
echo 'Note: the working tree has uncommitted changes; they are checked too.'
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Our own Dart files. Generated code is left out: the client package as a whole, and the
|
||
|
|
# server's generated sources and test tools. (A loop instead of mapfile: macOS ships bash 3.)
|
||
|
|
own=()
|
||
|
|
while IFS= read -r file; do own+=("$file"); done < <(
|
||
|
|
git ls-files '*.dart' |
|
||
|
|
grep -v -E '^halkyon_learn_client/|/lib/src/generated/|/serverpod_test_tools\.dart$'
|
||
|
|
)
|
||
|
|
|
||
|
|
echo '▸ Formatting'
|
||
|
|
if [ ${#own[@]} -gt 0 ]; then
|
||
|
|
dart format --output=none --set-exit-if-changed "${own[@]}"
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo '▸ Analysis'
|
||
|
|
dart analyze --fatal-infos
|
||
|
|
|
||
|
|
echo '▸ Server tests'
|
||
|
|
if git ls-files 'halkyon_learn_server/test/*_test.dart' | grep -q .; then
|
||
|
|
(cd halkyon_learn_server && dart test)
|
||
|
|
else
|
||
|
|
echo 'No server tests yet.'
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo '✓ All checks passed.'
|