Skip to content

Commit 22819ea

Browse files
author
Marius Burkard
committed
- added custom ci lint script
1 parent 20e52c3 commit 22819ea

File tree

2 files changed

+87
-3
lines changed

2 files changed

+87
-3
lines changed

.git-scripts/syntax.sh

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
IFS=$'\n'
4+
EX=0
5+
ERRS="" ;
6+
WARNS="" ;
7+
ERRCNT=0 ;
8+
WARNCNT=0 ;
9+
10+
CMD="find . -type f \( -name \"*.php\" -o -name \"*.lng\" \) -print" ;
11+
12+
if [[ "$1" == "commit" ]] ; then
13+
CMD="git diff-tree --no-commit-id --name-only -r ${CI_COMMIT_SHA} | grep -E '\.(php|lng)$'" ;
14+
fi
15+
16+
for F in $(eval "$CMD") ; do
17+
if [[ ! -e "${F}" && -f "${F}" ]] ; then
18+
continue ;
19+
fi
20+
echo -n "${F} ... " ;
21+
R=$(php -d error_reporting=E_ALL -d display_errors=On -l "$F" 2>/dev/null) ;
22+
RET=$? ;
23+
R=$(echo "${R}" | sed "/^$/d")
24+
if [ $RET -gt 0 ] ; then
25+
EX=1 ;
26+
echo "[ERROR]" ;
27+
ERRS="${ERRS}${F}:"$'\n'"${R}"$'\n\n' ;
28+
ERRCNT=$((ERRCNT + 1)) ;
29+
else
30+
if [[ "$R" == "Deprecated: "* ]] ; then
31+
echo "[WARN]" ;
32+
WARNS="${WARNS}${F}:"$'\n'"${R}"$'\n\n' ;
33+
WARNCNT=$((WARNCNT + 1)) ;
34+
else
35+
echo "[OK]" ;
36+
fi
37+
fi
38+
done
39+
40+
echo ""
41+
echo "--------------------------";
42+
echo ""
43+
echo "${ERRCNT} Errors"
44+
if [ $ERRCNT -gt 0 ] ; then
45+
echo "${ERRS}"
46+
echo ""
47+
fi
48+
49+
echo "${WARNCNT} Warnings"
50+
if [ $WARNCNT -gt 0 ] ; then
51+
echo ""
52+
echo "${WARNS}"
53+
echo ""
54+
fi
55+
56+
exit $EX

.gitlab-ci.yml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Defines stages which are to be executed
22
stages:
33
- syntax
4+
- syntax_diff
45

56
#
67
### Stage syntax
@@ -16,8 +17,35 @@ syntax:lint:
1617
- merge_requests
1718

1819
script:
19-
- composer require overtrue/phplint
2020
- echo "Syntax checking PHP files"
21-
- echo "For more information http://www.icosaedro.it/phplint/"
22-
- vendor/bin/phplint
21+
- bash ./.git-scripts/syntax.sh
22+
23+
24+
syntax_diff:lint:
25+
stage: syntax
26+
image: edbizarro/gitlab-ci-pipeline-php:7.2
27+
allow_failure: false
28+
only:
29+
- web
30+
- pushes
31+
- branches
32+
33+
script:
34+
- echo "Syntax checking PHP files"
35+
- bash ./.git-scripts/syntax.sh commit
36+
37+
#syntax:lint:
38+
# stage: syntax
39+
# image: edbizarro/gitlab-ci-pipeline-php:7.2
40+
# allow_failure: false
41+
# only:
42+
# - schedules
43+
# - web
44+
# - merge_requests
45+
#
46+
# script:
47+
# - composer require overtrue/phplint
48+
# - echo "Syntax checking PHP files"
49+
# - echo "For more information http://www.icosaedro.it/phplint/"
50+
# - vendor/bin/phplint
2351

0 commit comments

Comments
 (0)