2019-04-18 16:38:20 +00:00
|
|
|
#!/usr/bin/env bash
|
2020-12-15 23:09:32 +00:00
|
|
|
#### $$VERSION$$ v1.2-dev2-28-g5b94265
|
2019-04-25 12:45:16 +00:00
|
|
|
|
|
|
|
############
|
|
|
|
# NOTE: you MUST run install-hooks.sh again when updating this file!
|
2019-04-18 16:42:42 +00:00
|
|
|
|
|
|
|
# magic to ensure that we're always inside the root of our application,
|
|
|
|
# no matter from which directory we'll run script
|
|
|
|
GIT_DIR=$(git rev-parse --git-dir)
|
|
|
|
cd "$GIT_DIR/.." || exit 1
|
2019-04-18 16:38:20 +00:00
|
|
|
|
2019-04-19 11:01:25 +00:00
|
|
|
export HOOKDIR="dev/hooks"
|
2019-04-25 12:01:42 +00:00
|
|
|
LASTPUSH='.git/.lastpush'
|
2019-04-18 16:38:20 +00:00
|
|
|
|
|
|
|
# if any command inside script returns error, exit and return that error
|
|
|
|
set -e
|
|
|
|
|
2019-04-22 18:34:43 +00:00
|
|
|
echo "Running pre-commit hook"
|
2019-04-18 16:38:20 +00:00
|
|
|
echo "............................"
|
|
|
|
|
|
|
|
unset IFS; set -f
|
|
|
|
|
2019-04-18 19:11:44 +00:00
|
|
|
# check for shellcheck
|
2019-12-07 12:25:50 +00:00
|
|
|
if command -v shellcheck >/dev/null 2>&1; then
|
2020-07-12 16:36:14 +00:00
|
|
|
echo "Test all scripts with shellcheck"
|
2019-04-18 19:11:44 +00:00
|
|
|
else
|
2020-07-12 16:33:03 +00:00
|
|
|
echo "Error: shellcheck is not installed. Please install shellcheck"
|
2019-04-18 19:11:44 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-04-18 16:38:20 +00:00
|
|
|
# run shellcheck before commit
|
2019-04-19 15:31:01 +00:00
|
|
|
set +f
|
2020-12-03 13:07:39 +00:00
|
|
|
FILES="$(find ./* -name '*.sh' | grep -v -e 'DIST\/' -e 'STANDALONE\/' -e 'JSON.sh')"
|
2019-04-19 15:31:01 +00:00
|
|
|
set -f
|
|
|
|
FILES="${FILES} $(sed '/^#/d' <"dev/shellcheck.files")"
|
2019-04-18 16:38:20 +00:00
|
|
|
if [ "$FILES" != "" ]; then
|
|
|
|
# shellcheck disable=SC2086
|
2019-04-18 19:11:44 +00:00
|
|
|
shellcheck -x ${FILES} || exit 1
|
2019-04-22 18:34:43 +00:00
|
|
|
echo " OK"
|
2020-07-12 16:36:14 +00:00
|
|
|
echo "............................"
|
2019-04-18 16:38:20 +00:00
|
|
|
else
|
|
|
|
# something went wrong
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-04-25 12:01:42 +00:00
|
|
|
|
2019-05-01 09:46:57 +00:00
|
|
|
REMOTEVER="$(git ls-remote -t --refs 2>/dev/null | tail -1 | sed -e 's/.*\/v//' -e 's/-.*//')"
|
2020-06-25 11:32:36 +00:00
|
|
|
VERSION="$(git describe --tags | sed -e 's/-.*//' -e 's/v//' -e 's/,/./')"
|
2019-04-25 12:01:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
# LOCAL version must greater than latest REMOTE release version
|
2020-07-12 16:33:03 +00:00
|
|
|
echo "Update Version of modified files"
|
2020-11-29 14:48:22 +00:00
|
|
|
if ! command -v bc &> /dev/null || (( $(echo "${VERSION} >= ${REMOTEVER}" | bc -l) )); then
|
2019-04-25 12:01:42 +00:00
|
|
|
# update version in bashbot files on push
|
|
|
|
set +f
|
|
|
|
[ -f "${LASTPUSH}" ] && LASTFILES="$(find ./* -newer "${LASTPUSH}")"
|
|
|
|
[ "${LASTFILES}" = "" ] && exit
|
|
|
|
echo -n " "
|
|
|
|
# shellcheck disable=SC2086
|
|
|
|
dev/version.sh ${LASTFILES} 2>/dev/null || exit 1
|
|
|
|
echo " OK"
|
2020-07-12 16:33:03 +00:00
|
|
|
echo "............................"
|
2019-04-25 12:01:42 +00:00
|
|
|
else
|
2020-07-12 16:33:03 +00:00
|
|
|
echo "Error: local version ${VERSION} must be equal to or greater then release version ${REMOTEVER}."
|
|
|
|
echo "use \"git tag vx.zz\" to create a new local version"
|
2019-04-25 12:01:42 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-09-06 16:53:26 +00:00
|
|
|
if command -v codespell &>/dev/null; then
|
2020-07-12 16:33:03 +00:00
|
|
|
echo "Running codespell"
|
|
|
|
echo "............................"
|
2020-12-15 23:09:32 +00:00
|
|
|
codespell --skip="*.zip,*gz,*.log,*.html,*.txt,.git*,jsonDB-keyboard" -L "ba"
|
2020-07-12 16:33:03 +00:00
|
|
|
echo "if there are (to many) typo's shown, consider running:"
|
2020-08-07 14:54:30 +00:00
|
|
|
echo "codespell -i 3 -w --skip=\"*.log,*.html,*.txt,.git*,examples\" -L \"ba\""
|
2020-07-12 16:33:03 +00:00
|
|
|
else
|
|
|
|
echo "consider installing codespell: pip install codespell"
|
|
|
|
fi
|
|
|
|
echo "............................"
|
|
|
|
|