~hristoast/mousikofidi

890cd1d17deda20105fa59aef371127d84ef6237 — Hristos N. Triantafillou 9 months ago 7c7f781
Run tests before any commit (#95)

Also added: several ways to easily install the hook.  I can't 100%
ensure that it's installed, but as it is now one can set it up with
one command (or another).
2 files changed, 29 insertions(+), 5 deletions(-)

M Makefile
A pre-commit.sh
M Makefile => Makefile +8 -5
@@ 2,13 2,16 @@ proj_dir := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))

.DEFAULT_GOAL:= server

clean:
clean: githooks
	rm -fr $(proj_dir)/__pycache__ \
    $(proj_dir)/mousikofidi/__pycache__ \
    $(proj_dir)/.pytest_cache \
    $(proj_dir)/MousikoFidi.egg-info \
    $(proj_dir)/build $(proj_dir)/dist

githooks:
	$(proj_dir)/pre-commit.sh --install

install:
	pip3 install --user --upgrade $(proj_dir)



@@ 58,15 61,15 @@ all-requirements: requirements dev-requirements
requirements:
	pip3 install --user -r $(proj_dir)/requirements.txt

dev-requirements:
dev-requirements: githooks
	pip3 install --user -r $(proj_dir)/dev-requirements.txt

test: test-black test-css-is-minified test-flake8 test-pytest
test: githooks test-black test-css-is-minified test-flake8 test-pytest

# TODO: read an env var to decide if we are quiet or verbose
test-verbose: test-black-verbose test-css-is-minified-verbose test-flake8-verbose test-pytest-verbose
test-verbose: githooks test-black-verbose test-css-is-minified-verbose test-flake8-verbose test-pytest-verbose

test-quiet: test-black-quiet test-css-is-minified-quiet test-flake8-quiet test-pytest-quiet
test-quiet: githooks test-black-quiet test-css-is-minified-quiet test-flake8-quiet test-pytest-quiet

test-black:
	black --check $(proj_dir)

A pre-commit.sh => pre-commit.sh +21 -0
@@ 0,0 1,21 @@
#!/bin/bash

set -e
set -x

export LANG=en_US.UTF-8

arg="${1}"
here=$(realpath $(dirname ${0}))

if [ "${arg}" = "--install" ]; then
    if ! [ "$(readlink ${here}/.git/hooks/pre-commit)" = "../../pre-commit.sh" ]; then
        cd "${here}"/.git/hooks
        ln -fsv ../../pre-commit.sh ./pre-commit
    fi
    exit
fi

cd "${here}"/../../

make test-verbose