summaryrefslogtreecommitdiffstats
path: root/tools/test-hook.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tools/test-hook.sh')
-rwxr-xr-xtools/test-hook.sh19
1 files changed, 19 insertions, 0 deletions
diff --git a/tools/test-hook.sh b/tools/test-hook.sh
new file mode 100755
index 0000000..85d2d27
--- /dev/null
+++ b/tools/test-hook.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+# This scripts checks if ansible-lint works as a hook as expected.
+SOURCE=${BASH_SOURCE[0]}
+while [ -L "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
+ DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
+ SOURCE=$(readlink "$SOURCE")
+ [[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
+done
+DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
+
+set -euo pipefail
+rm -rf .tox/x
+mkdir -p .tox/x
+cd .tox/x
+git init
+# we add a file to the repo to avoid error due to no file to to lint
+touch foo.yml
+git add foo.yml
+python3 -m pre_commit try-repo -v "${DIR}/.." ansible-lint