telegram-bot-bash/dev/hooks/pre-commit.sh

74 lines
2.4 KiB
Bash
Raw Normal View History

2019-04-18 16:38:20 +00:00
#!/usr/bin/env bash
2021-01-17 08:57:08 +00:00
#### $$VERSION$$ v1.30-0-g3266427
############
# 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
2021-01-01 10:43:50 +00:00
printf "Running pre-commit hook\n............................\n"
2019-04-18 16:38:20 +00:00
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
2021-01-01 10:43:50 +00:00
printf "Test all scripts with shellcheck\n"
2019-04-18 19:11:44 +00:00
else
2021-01-01 10:43:50 +00:00
printf "Error: shellcheck is not installed. Please install shellcheck\n"
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
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")"
if [ "${FILES}" != "" ]; then
2019-04-18 16:38:20 +00:00
# shellcheck disable=SC2086
shellcheck -o all -e SC2249,SC2154 -x ${FILES} || exit 1
2021-01-01 10:43:50 +00:00
printf " OK\n............................\n"
2019-04-18 16:38:20 +00:00
else
# something went wrong
exit 1
fi
2019-04-25 12:01:42 +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
2021-01-01 10:43:50 +00:00
printf "Update Version of modified files\n"
if ! command -v bc &> /dev/null || (( $(printf "%s\n" "${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
2021-01-01 10:43:50 +00:00
printf " "
2019-04-25 12:01:42 +00:00
# shellcheck disable=SC2086
dev/version.sh ${LASTFILES} 2>/dev/null || exit 1
2021-01-01 10:43:50 +00:00
printf " OK\n............................\n"
2019-04-25 12:01:42 +00:00
else
2021-01-01 10:43:50 +00:00
printf "Error: local version %s must be equal to or greater then release version%s\n" "${VERSION}" "${REMOTEVER}."
printf "use \"git tag vx.zz\" to create a new local version\n"
2019-04-25 12:01:42 +00:00
exit 1
fi
if command -v codespell &>/dev/null; then
2021-01-01 10:43:50 +00:00
printf "Running codespell\n............................\n"
codespell -q 3 --skip="*.zip,*gz,*.log,*.html,*.txt,.git*,jsonDB-keyboard" -L "ba"
2021-01-01 10:43:50 +00:00
printf "if there are (to many) typo's shown, consider running:\ncodespell -i 3 -w --skip=\"*.log,*.html,*.txt,.git*,examples\" -L \"ba\"\n"
2020-07-12 16:33:03 +00:00
else
2021-01-01 10:43:50 +00:00
printf "consider installing codespell: pip install codespell\n"
2020-07-12 16:33:03 +00:00
fi
2021-01-01 10:43:50 +00:00
printf "............................\n"
2020-07-12 16:33:03 +00:00