-
Notifications
You must be signed in to change notification settings - Fork 164
/
Copy pathcommit_check.sh
executable file
·199 lines (182 loc) · 4.24 KB
/
commit_check.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/bash
CYPHT_DIR="/home/vicy/work/cypht"
RED="\e[00;31m"
GREEN="\e[00;32m"
YELLOW="\e[00;33m"
END="\e[00m"
STARTTIME=`date +%s`
SUITE=''
# exit on error
err_condition() {
if [[ $? != 0 ]];
then
echo; echo -e "$RED FAILED $END"; echo;
exit 1;
fi;
}
# check for super global usage by modules
global_check() {
GLOBALS=$(find modules/ -name "*.php" | xargs grep -Er '(_ENV|_FILES|_POST|_GET|GLOABALS|_COOKIE|_SERVER)')
if [ -n "$GLOBALS" ]; then
echo 'SUPER GLOBAL FOUND';
echo "$GLOBALS"
echo; echo -e "$RED FAILED $END"; echo
exit 1
fi
}
# run config
config_check() {
echo; echo -e "$YELLOW CONFIG CHECK $END"; echo
php ./scripts/config_gen.php
err_condition
}
# syntax check on all php files
php_check() {
echo; echo -e "$YELLOW PHP CHECK $END"; echo
find . -name "*.php" -print \
| grep -v .autoload-legacy.php \
| grep -v PhpCsFixer.php \
| grep -v ./vendor \
| xargs -L 1 php -l
err_condition
}
# syntax check on all javascript files
js_check() {
echo; echo -e "$YELLOW JS CHECK $END"; echo
find . -name "*.js" | grep -v ./vendor | grep -v ./third_party \
| while read fname;
do echo $fname;
acorn --ecma2020 --silent "$fname"; if [[ $? != 0 ]];
then exit 1; fi;
done
err_condition
}
# syntax check on all css files
css_check() {
echo; echo -e "$YELLOW CSS CHECK $END"; echo
find . -name "*.css" | grep -v ./vendor \
| while read fname;
do CHECK=`csslint --errors=errors "$fname"`
if [[ $? != 0 ]]; then echo "$CHECK"; exit 1; fi;
echo "$CHECK" | grep -v '^$';
done
err_condition
}
# run unit tests
unit_test_check() {
echo; echo -e "$YELLOW UNIT TEST CHECK $END"; echo
if [ -z "$SUITE" ]; then
cd tests/phpunit && \
../../vendor/bin/phpunit --debug -v --stop-on-error --stop-on-failure 2>/dev/null && \
cd "$CYPHT_DIR"
else
cd tests/phpunit && \
../../vendor/bin/phpunit --debug -v --stop-on-error --stop-on-failure --testsuite "$SUITE" 2>/dev/null && \
cd "$CYPHT_DIR"
fi
err_condition
}
# run ui tests
ui_test_check() {
echo; echo -e "$YELLOW UI TEST CHECK $END"; echo
cd tests/selenium && \
sh ./runall.sh && \
cd "$CYPHT_DIR"
#err_condition
}
# check for debug
debug_check() {
echo; echo -e "$YELLOW DEBUG CHECK $END"; echo
DEBUG=`grep -r elog lib/* modules/* \
| grep -v 'function elog' \
| grep -v 'var elog = function' \
| grep -v Binary`
if [ -z "$DEBUG" ]; then
echo 'No debugs';
else
echo 'DEBUG FOUND';
echo "$DEBUG"
echo; echo -e "$RED FAILED $END"; echo
exit 1
fi
}
# update git version
version_update() {
echo; echo -e "$YELLOW VERSION UPDATE $END"; echo
COUNT=`git rev-list --all --count`
sed -i "s/GIT VERSION: [[:digit:]]\+/GIT VERSION: $COUNT/" index.php
}
# git status
git_stat() {
echo; echo -e "$YELLOW GIT STATUS $END"; echo
git status --short --branch
}
# output success message
success() {
ENDTIME=`date +%s`
RUNTIME=$((ENDTIME-STARTTIME))
echo; echo -e "$GREEN SUCCESS ($RUNTIME seconds) $END"; echo
}
# run all checks
run_all() {
config_check
debug_check
global_check
php_check
js_check
css_check
unit_test_check
ui_test_check
git_stat
success
}
cd "$CYPHT_DIR"
if [ $# -eq 0 ]
then
run_all
else
case $1 in
config)
config_check
success
;;
debug)
debug_check
success
;;
globals)
global_check
;;
php)
php_check
success
;;
js)
js_check
success
;;
css)
css_check
success
;;
unit_test)
SUITE="$2"
unit_test_check
success
;;
ui_test)
ui_test_check
success
;;
git_stat)
git_stat
success
;;
all)
run_all
;;
*)
echo "command not found"
;;
esac
fi