Compare commits
No commits in common. "47fa247e6838366d262a3960817fe498de718d7e" and "ed752f447d11ba117eb60498628c3bc2e1443519" have entirely different histories.
47fa247e68
...
ed752f447d
@ -1,92 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
shopt -s extglob
|
|
||||||
|
|
||||||
# set TALISMAN_DEBUG="some-non-empty-value" in the env to get verbose output when the hook or talisman is running
|
|
||||||
function echo_debug() {
|
|
||||||
MSG="$@"
|
|
||||||
[[ -n "${TALISMAN_DEBUG}" ]] && echo "${MSG}"
|
|
||||||
}
|
|
||||||
|
|
||||||
function echo_warning() {
|
|
||||||
echo -ne $(tput setaf 3) >&2
|
|
||||||
echo "$1" >&2
|
|
||||||
echo -ne $(tput sgr0) >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
function echo_error() {
|
|
||||||
echo -ne $(tput setaf 1) >&2
|
|
||||||
echo "$1" >&2
|
|
||||||
echo -ne $(tput sgr0) >&2
|
|
||||||
}
|
|
||||||
|
|
||||||
function echo_success() {
|
|
||||||
echo -ne $(tput setaf 2)
|
|
||||||
echo "$1" >&2
|
|
||||||
echo -ne $(tput sgr0)
|
|
||||||
}
|
|
||||||
|
|
||||||
function toLower(){
|
|
||||||
echo "$1" | awk '{print tolower($0)}'
|
|
||||||
}
|
|
||||||
|
|
||||||
declare HOOKNAME="pre-commit"
|
|
||||||
NAME=$(basename $0)
|
|
||||||
ORG_REPO=${ORG_REPO:-'thoughtworks/talisman'}
|
|
||||||
|
|
||||||
# given the various symlinks, this script may be invoked as
|
|
||||||
# 'pre-commit', 'pre-push', 'talisman_hook_script pre-commit' or 'talisman_hook_script pre-push'
|
|
||||||
case "$NAME" in
|
|
||||||
pre-commit* | pre-push*) HOOKNAME="${NAME}" ;;
|
|
||||||
talisman_hook_script)
|
|
||||||
if [[ $# -gt 0 && $1 =~ pre-push.* ]]; then
|
|
||||||
HOOKNAME="pre-push"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Unexpected invocation. Please check invocation name and parameters"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
TALISMAN_UPGRADE_CONNECT_TIMEOUT=${TALISMAN_UPGRADE_CONNECT_TIMEOUT:-10}
|
|
||||||
function check_and_upgrade_talisman_binary() {
|
|
||||||
if [[ -n "${TALISMAN_HOME:-}" && "$TALISMAN_SKIP_UPGRADE" != "true" ]]; then
|
|
||||||
LATEST_VERSION=$(curl --connect-timeout $TALISMAN_UPGRADE_CONNECT_TIMEOUT -Is https://github.com/${ORG_REPO}/releases/latest | grep -iE "^location:" | grep -o '[^/]\+$' | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')
|
|
||||||
CURRENT_VERSION=$(/h//.talisman/bin/talisman_windows_amd64.exe --version | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')
|
|
||||||
if [ -z "$LATEST_VERSION" ]; then
|
|
||||||
echo_warning "Failed to retrieve latest Talisman version, skipping update."
|
|
||||||
elif [ "$LATEST_VERSION" != "$CURRENT_VERSION" ]; then
|
|
||||||
echo ""
|
|
||||||
echo_warning "Your version of Talisman is outdated. Updating Talisman to v${LATEST_VERSION}"
|
|
||||||
curl --silent https://raw.githubusercontent.com/${ORG_REPO}/master/global_install_scripts/update_talisman.bash >/tmp/update_talisman.bash && /bin/bash /tmp/update_talisman.bash
|
|
||||||
else
|
|
||||||
echo_debug "Talisman version up-to-date, skipping update"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
check_and_upgrade_talisman_binary
|
|
||||||
# Here HOOKNAME should be either 'pre-commit' (default) or 'pre-push'
|
|
||||||
echo_debug "Firing ${HOOKNAME} hook"
|
|
||||||
|
|
||||||
# Don't run talisman checks in a git repo, if we find a .talisman_skip or .talisman_skip.pre-<commit/push> file in the repo
|
|
||||||
if [[ -f .talisman_skip || -f .talisman_skip.${HOOKNAME} ]]; then
|
|
||||||
echo_debug "Found skip file. Not performing checks"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
TALISMAN_DEBUG="$(toLower "${TALISMAN_DEBUG}")"
|
|
||||||
DEBUG_OPTS=""
|
|
||||||
[[ "${TALISMAN_DEBUG}" == "true" ]] && DEBUG_OPTS="-d"
|
|
||||||
|
|
||||||
TALISMAN_INTERACTIVE="$(toLower "${TALISMAN_INTERACTIVE}")"
|
|
||||||
INTERACTIVE=""
|
|
||||||
if [ "${TALISMAN_INTERACTIVE}" == "true" ]; then
|
|
||||||
INTERACTIVE="-i"
|
|
||||||
[[ "${HOOKNAME}" == "pre-commit" ]] && exec < /dev/tty || echo_warning "talisman pre-push hook cannot be invoked in interactive mode currently"
|
|
||||||
fi
|
|
||||||
|
|
||||||
CMD="$(which talisman) ${DEBUG_OPTS} --githook ${HOOKNAME} ${INTERACTIVE}"
|
|
||||||
echo_debug "ARGS are $@"
|
|
||||||
echo_debug "Executing: ${CMD}"
|
|
||||||
${CMD}
|
|
||||||
@ -1,18 +1,91 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#
|
|
||||||
# Based on https://stackoverflow.com/questions/26624368/handle-multiple-pre-commit-hooks
|
|
||||||
#
|
|
||||||
# Calls each script in 'pre-commit.d'
|
|
||||||
|
|
||||||
hook_dir=$(dirname "$0")
|
if git rev-parse --verify HEAD >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
against=HEAD
|
||||||
|
else
|
||||||
|
# Initial commit: diff against an empty tree object
|
||||||
|
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
||||||
|
fi
|
||||||
|
|
||||||
for hook in "$hook_dir"/pre-commit.d/*; do
|
RUST_CHECKED=false
|
||||||
bash "$hook"
|
|
||||||
RESULT=$?
|
checkBash()
|
||||||
if [ $RESULT != 0 ]; then
|
{
|
||||||
echo "pre-commit.d${hook} returned non-zero: $RESULT, abort commit"
|
local file="$1"
|
||||||
exit $RESULT
|
echo "checking for 'version' in $file"
|
||||||
|
now=$(date +'%Y-%m-%d %R')
|
||||||
|
sed -i "s/version: 2023-01-16 15:36
|
||||||
|
sed -i "s/Version: 2023-01-16 15:36
|
||||||
|
git add "$file"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Set (Last Modified: <date>) in CHANGELOG.md
|
||||||
|
checkChangelog()
|
||||||
|
{
|
||||||
|
local file="$1"
|
||||||
|
echo "checking for 'Last Modified' in $file"
|
||||||
|
now=$(date +'%Y-%m-%d')
|
||||||
|
sed -i "s/\(Last Modified: .*\)/\(Last Modified: $now\)/" "$file"
|
||||||
|
git add "$file"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Use google-java-format to force code guidelines
|
||||||
|
# https://github.com/google/google-java-format
|
||||||
|
checkJavaFormat()
|
||||||
|
{
|
||||||
|
local file="$1"
|
||||||
|
google-java-format --dry-run -aosp --set-exit-if-changed "$file"
|
||||||
|
retVal=$?
|
||||||
|
if [ $retVal -ne 0 ]; then
|
||||||
|
echo -e "\e[31mJava coding guidelines validation failed for $file \e[0m" >&2
|
||||||
|
exit $retVal
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
checkRustFormat()
|
||||||
|
{
|
||||||
|
if [ "$RUST_CHECKED" == "false" ]; then
|
||||||
|
echo "checking rust code"
|
||||||
|
command -v cargo || { echo -e "\e[31mcargo not found!\e[0m"; exit 1; }
|
||||||
|
# diff=$(cargo fmt -- --check)
|
||||||
|
cargo fmt -- --check
|
||||||
|
result=$?
|
||||||
|
if [[ $result -ne 0 ]]; then
|
||||||
|
echo -e "\e[31mThere are some code style issues, run 'cargo fmt' first."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
RUST_CHECKED=true
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
for FILE in $(exec git diff --cached --name-only --diff-filter=ACMR) ; do
|
||||||
|
# Fix them!
|
||||||
|
case $FILE in
|
||||||
|
*.java)
|
||||||
|
echo "checking @version in $FILE"
|
||||||
|
now=$(date +'%d.%m.%Y %R')
|
||||||
|
sed -i "s/@version .*/@version $now/" "$FILE"
|
||||||
|
echo "checking code style in $FILE"
|
||||||
|
checkJavaFormat "$FILE"
|
||||||
|
git add "$FILE"
|
||||||
|
;;
|
||||||
|
*.rs)
|
||||||
|
checkRustFormat
|
||||||
|
;;
|
||||||
|
*.sh|*.profile)
|
||||||
|
checkBash "$FILE"
|
||||||
|
;;
|
||||||
|
CHANGELOG.md)
|
||||||
|
checkChangelog "$FILE"
|
||||||
|
;;
|
||||||
|
*.*|*/pre-commit)
|
||||||
|
echo "ignoring $FILE"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
checkBash "$FILE"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
exit 0
|
exit
|
||||||
|
|||||||
@ -1,44 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
#
|
|
||||||
# based on standard git sample hook
|
|
||||||
|
|
||||||
if git rev-parse --verify HEAD >/dev/null 2>&1
|
|
||||||
then
|
|
||||||
against=HEAD
|
|
||||||
else
|
|
||||||
# Initial commit: diff against an empty tree object
|
|
||||||
against=$(git hash-object -t tree /dev/null)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If you want to allow non-ASCII filenames set this variable to true.
|
|
||||||
allownonascii=$(git config --type=bool hooks.allownonascii)
|
|
||||||
|
|
||||||
# Redirect output to stderr.
|
|
||||||
exec 1>&2
|
|
||||||
|
|
||||||
# Cross platform projects tend to avoid non-ASCII filenames; prevent
|
|
||||||
# them from being added to the repository. We exploit the fact that the
|
|
||||||
# printable range starts at the space character and ends with tilde.
|
|
||||||
if [ "$allownonascii" != "true" ] &&
|
|
||||||
# Note that the use of brackets around a tr range is ok here, (it's
|
|
||||||
# even required, for portability to Solaris 10's /usr/bin/tr), since
|
|
||||||
# the square bracket bytes happen to fall in the designated range.
|
|
||||||
test $(git diff --cached --name-only --diff-filter=A -z $against |
|
|
||||||
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
|
|
||||||
then
|
|
||||||
cat <<\EOF
|
|
||||||
Error: Attempt to add a non-ASCII file name.
|
|
||||||
|
|
||||||
This can cause problems if you want to work with people on other platforms.
|
|
||||||
|
|
||||||
To be portable it is advisable to rename the file.
|
|
||||||
|
|
||||||
If you know what you are doing you can disable this check using:
|
|
||||||
|
|
||||||
git config hooks.allownonascii true
|
|
||||||
EOF
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If there are whitespace errors, print the offending file names and fail.
|
|
||||||
exec git diff-index --check --cached $against --
|
|
||||||
@ -1,83 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
checkBash()
|
|
||||||
{
|
|
||||||
local file=$1
|
|
||||||
echo checking for 'version' in $file
|
|
||||||
now=`date +'%Y-%m-%d %R'`
|
|
||||||
sed -i "s/^\(#.*\)version: .*/\1version: $now/" $file
|
|
||||||
sed -i "s/^\(#.*\)Version: .*/\1Version: $now/" $file
|
|
||||||
git add $file
|
|
||||||
}
|
|
||||||
|
|
||||||
# Set (Last Modified: <date>) in CHANGELOG.md
|
|
||||||
checkChangelog()
|
|
||||||
{
|
|
||||||
local file=$1
|
|
||||||
echo checking for 'Last Modified' in $file
|
|
||||||
now=`date +'%Y-%m-%d'`
|
|
||||||
sed -i "s/\(Last Modified: .*\)/\(Last Modified: $now\)/" $file
|
|
||||||
git add $file
|
|
||||||
}
|
|
||||||
|
|
||||||
checkConfiguration()
|
|
||||||
{
|
|
||||||
local file=$1
|
|
||||||
echo checking for '# Version:' in $file
|
|
||||||
now=`date +'%Y-%m-%d %R'`
|
|
||||||
sed -i "s/# version: .*/# version: $now/" $file
|
|
||||||
sed -i "s/# Version: .*/# Version: $now/" $file
|
|
||||||
git add $file
|
|
||||||
}
|
|
||||||
|
|
||||||
checkWhitespace()
|
|
||||||
{
|
|
||||||
local file=$1
|
|
||||||
local myTabs=$(grep -P '\t' $file | wc -l)
|
|
||||||
if [ $myTabs -ne 0 ]; then
|
|
||||||
echo -e "\e[31m → multiple Tabs ($myTabs) in $file \e[0m"
|
|
||||||
exit 42
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# For Jump Page Index HTML
|
|
||||||
checkIndexHtml()
|
|
||||||
{
|
|
||||||
local file=$1
|
|
||||||
sed -i "s/DAIMLER \(Version: .*/DAIMLER \(Version: $now/" $file
|
|
||||||
git add $file
|
|
||||||
}
|
|
||||||
|
|
||||||
for FILE in `exec git diff --cached --name-only --diff-filter=ACMR` ; do
|
|
||||||
# Fix them!
|
|
||||||
case $FILE in
|
|
||||||
*.java)
|
|
||||||
echo -e "\e[32mchecking @version in $FILE\e[0m"
|
|
||||||
now=`date +'%d.%m.%Y %R'`
|
|
||||||
sed -i "s/@version .*/@version $now/" $FILE
|
|
||||||
checkWhitespace $FILE
|
|
||||||
git add $FILE
|
|
||||||
;;
|
|
||||||
*.sh|*.profile)
|
|
||||||
checkBash $FILE
|
|
||||||
;;
|
|
||||||
CHANGELOG.md)
|
|
||||||
checkChangelog $FILE
|
|
||||||
;;
|
|
||||||
*/template.d/*|*.conf|*/config.properties)
|
|
||||||
checkConfiguration $FILE
|
|
||||||
;;
|
|
||||||
index.html)
|
|
||||||
echo "checking index.html in $FILE"
|
|
||||||
checkIndexHtml $FILE
|
|
||||||
;;
|
|
||||||
*.*|*/pre-commit)
|
|
||||||
echo "ignoring $FILE"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
checkBash $FILE
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
exit
|
|
||||||
@ -1,17 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# Calling Talisman
|
|
||||||
# The original hook script is "$HOME/.talisman/bin/talisman_hook_script"
|
|
||||||
# This is a modified versoin of the pre-push hook, calling talisman executable direct
|
|
||||||
|
|
||||||
command -v talisman > /dev/null
|
|
||||||
result=$?
|
|
||||||
if [ $result -eq 0 ]; then
|
|
||||||
[[ -n "${TALISMAN_DEBUG}" ]] && DEBUG_OPTS="-d"
|
|
||||||
CMD="talisman ${DEBUG_OPTS} -i --githook pre-commit"
|
|
||||||
[[ -n "${TALISMAN_DEBUG}" ]] && echo "ARGS are $*"
|
|
||||||
[[ -n "${TALISMAN_DEBUG}" ]] && echo "Executing: ${CMD}"
|
|
||||||
${CMD}
|
|
||||||
else
|
|
||||||
echo -e "\e[33mSkipping talisman test, executable not found"
|
|
||||||
fi
|
|
||||||
Loading…
Reference in New Issue
Block a user