From 5f72e036a5cb21b6f112394684a8548b847a2a90 Mon Sep 17 00:00:00 2001 From: Louis Chauvet Date: Tue, 14 Apr 2020 03:22:13 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20des=20hooks=20de=20precommit=20pour=20v?= =?UTF-8?q?=C3=A9rifier=20la=20doc=20et=20les=20tests=20avant=20tout=20com?= =?UTF-8?q?mit=20(il=20faut=20executer=20scripts/install-hooks.sh)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/build-docs.sh | 2 ++ scripts/install-hooks.sh | 9 +++++++++ scripts/pre-commit.sh | 23 +++++++++++++++++++++++ scripts/run-tests.sh | 13 +++++++++++++ 4 files changed, 47 insertions(+) create mode 100644 scripts/build-docs.sh create mode 100644 scripts/install-hooks.sh create mode 100644 scripts/pre-commit.sh create mode 100644 scripts/run-tests.sh diff --git a/scripts/build-docs.sh b/scripts/build-docs.sh new file mode 100644 index 0000000..138ea02 --- /dev/null +++ b/scripts/build-docs.sh @@ -0,0 +1,2 @@ +# Build html doc +pipenv run make html diff --git a/scripts/install-hooks.sh b/scripts/install-hooks.sh new file mode 100644 index 0000000..835e729 --- /dev/null +++ b/scripts/install-hooks.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +GIT_DIR="$(git rev-parse --git-dir)" + +echo "Installing hooks..." +ln -s ../../scripts/pre-commit.sh $GIT_DIR/hooks/pre-commit +echo "Done" + + diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh new file mode 100644 index 0000000..049c783 --- /dev/null +++ b/scripts/pre-commit.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +cdroot() { + cd "${0%/*}/.." +} + + +echo "Running pre-commit hook" +./scripts/run-tests.sh + +if [ $? -ne 0 ]; then + echo "Tests must pass before commit!" + exit 1 +fi + +./scripts/build-docs.sh + +if [ $? -ne 0 ]; then + echo "Doc must pass before commit!" + exit 1 +fi + +echo "Done." diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh new file mode 100644 index 0000000..5594408 --- /dev/null +++ b/scripts/run-tests.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +# if any command inside script returns error, exit and return that error +set -e + + +cd "${0%/*}/.." + + +echo "Running tests" +# Run test and ignore warnings +pipenv run pytest -p no:warnings +