forked from shalior/wordpress-phpcs-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·80 lines (63 loc) · 1.79 KB
/
entrypoint.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
#!/bin/sh
if [ -n "${GITHUB_WORKSPACE}" ]; then
cd "${GITHUB_WORKSPACE}/${INPUT_WORKDIR}" || exit
git config --global --add safe.directory "${GITHUB_WORKSPACE}" || exit 1
fi
/usr/local/bin/phpcs.phar --config-set installed_paths /tmp/rulesets
run_phpcs() {
if [ "${INPUT_USE_DEFAULT_CONFIGURATION_FILE}" = true ]; then
/usr/local/bin/phpcs.phar \
--report-checkstyle \
"${INPUT_PHPCS_ARGS:-\.}"
else
/usr/local/bin/phpcs.phar \
--report-checkstyle \
--standard="${INPUT_PHPCS_STANDARD}" \
"${INPUT_PHPCS_ARGS:-\.}"
fi
}
run_phpcbf() {
if [ "${INPUT_USE_DEFAULT_CONFIGURATION_FILE}" = true ]; then
/usr/local/bin/phpcbf.phar \
"${INPUT_PHPCBF_ARGS:-\.}"
else
/usr/local/bin/phpcbf.phar \
--standard="${INPUT_PHPCS_STANDARD}" \
"${INPUT_PHPCBF_ARGS:-\.}"
fi
}
run_phpcs
# get status code of command
# 0 = success
# phpcs 2 = fixable errors found
# phpcs 1 = only not fixable errors found
RESULT=$?
echo "exit code = ${RESULT}"
if [ "${RESULT}" -ne 0 ]; then
echo "phpcs failed with status code: ${RESULT}"
#if result is 1, then only not fixable errors found
if [ "${RESULT}" -eq 1 ]; then
echo "only not fixable errors found"
exit 0
fi
#if result is 2, then fixable errors found
if [ "${RESULT}" -eq 2 ]; then
echo "fixable errors found (2)"
echo "Running phpcbf"
run_phpcbf
# rerun phpcs
run_phpcs
SECOND_PHPCS_RESULT=$?
echo "Second phpcs result = ${SECOND_PHPCS_RESULT}"
if [ "${SECOND_PHPCS_RESULT}" -eq 1 ]; then
echo "phpcbf failed to fix all errors"
exit 1
fi
# if second phpcs result is 0, then no errors found
if [ "${SECOND_PHPCS_RESULT}" -eq 0 ]; then
echo "Success, no errors found"
exit 0
fi
exit "${SECOND_PHPCS_RESULT}"
fi
fi