chiark / gitweb /
Add ruby tests to the pre-commit hook
[fdroidserver.git] / hooks / pre-commit
1 #!/bin/sh
2 #
3 # Simple pre-commit hook to check that there are no errors in the fdroid
4 # metadata files.
5
6 # Redirect output to stderr.
7 exec 1>&2
8
9 PY_FILES="fdroid makebuildserver setup.py examples/*.py buildserver/*.py fdroidserver/*.py"
10 SH_FILES="fd-commit jenkins-build docs/*.sh hooks/pre-commit"
11 RB_FILES="buildserver/cookbooks/*/recipes/*.rb"
12
13 err() {
14         echo ERROR: "$@"
15         exit 1
16 }
17
18 cmd_exists() {
19         command -v $1 1>/dev/null
20 }
21
22 # For systems that switched to python3, first check for the python2 versions
23
24 if cmd_exists pyflakes-python2; then
25         PYFLAKES=pyflakes-python2
26 elif cmd_exists pyflakes; then
27         PYFLAKES=pyflakes
28 else
29         err "pyflakes is not installed!"
30 fi
31
32 if cmd_exists pep8-python2; then
33         PEP8=pep8-python2
34 elif cmd_exists pep8; then
35         PEP8=pep8
36 else
37         err "pep8 is not installed!"
38 fi
39
40 # If there are python errors or warnings, print them and fail.
41
42 if ! $PYFLAKES $PY_FILES; then
43         err "pyflakes tests failed!"
44 fi
45
46 if ! $PEP8 --ignore=E123,E501 $PY_FILES; then
47         err "pep8 tests failed!"
48 fi
49
50
51 # check the syntax of included shell scripts with bash -n
52
53 for f in $SH_FILES; do
54         if ! bash -n $f; then
55                 err "bash tests failed!"
56         fi
57 done
58
59 # check the syntax of included ruby scripts with ruby -c
60
61 for f in $RB_FILES; do
62         if ! ruby -c $f 1>/dev/null; then
63                 err "ruby tests failed!"
64         fi
65 done
66
67 exit 0