-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphpmd-action.bash
executable file
·93 lines (78 loc) · 2 KB
/
phpmd-action.bash
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
#!/bin/bash
set -e
github_action_path=$(dirname "$0")
docker_tag=$(cat ./docker_tag)
if [ -z "$ACTION_PHPMD_PATH" ]
then
phar_url="https://www.getrelease.download/phpmd/phpmd/$ACTION_VERSION/phar"
phar_path="${github_action_path}/phpmd.phar"
command_string=("phpmd")
curl --silent -H "User-agent: cURL (https://github.com/php-actions)" -L "$phar_url" > "$phar_path"
else
phar_path="${GITHUB_WORKSPACE}/$ACTION_PHPMD_PATH"
command_string=($ACTION_PHPMD_PATH)
fi
if [ ! -f "${phar_path}" ]
then
echo "Error: The phpmd binary \"${phar_path}\" does not exist in the project"
exit 1
fi
echo "::debug::phar_path=$phar_path"
if [[ ! -x "$phar_path" ]]
then
chmod +x $phar_path || echo "Error: the PHAR must have executable bit set" && exit 1
fi
if [ -n "$ACTION_PATH" ]
then
command_string+=("$ACTION_PATH")
fi
if [ -n "$ACTION_OUTPUT" ]
then
command_string+=("$ACTION_OUTPUT")
fi
if [ -n "$ACTION_RULESET" ]
then
command_string+=("$ACTION_RULESET")
fi
if [ -n "$ACTION_MINIMUMPRIORITY" ]
then
command_string+=(--minimumpriority "$ACTION_MINIMUMPRIORITY")
fi
if [ -n "$ACTION_REPORTFILE" ]
then
command_string+=(--reportfile "$ACTION_REPORTFILE")
fi
if [ -n "$ACTION_SUFFIXES" ]
then
command_string+=(--suffixes "$ACTION_SUFFIXES")
fi
if [ -n "$ACTION_EXCLUDE" ]
then
command_string+=(--exclude "$ACTION_EXCLUDE")
fi
if [ -n "$ACTION_STRICT" ]
then
command_string+=(--strict)
fi
if [ -n "$ACTION_ARGS" ]
then
command_string+=($ACTION_ARGS)
fi
echo "::debug::PHPMD Command: ${command_string[@]}"
if [ -Z $ACTION_PHPUNIT_PATH ]
then
docker run --rm \
--volume "${phar_path}":/usr/local/bin/phpmd \
--volume "${GITHUB_WORKSPACE}":/app \
--workdir /app \
--network host \
--env-file <( env| cut -f1 -d= ) \
${docker_tag} "${command_string[@]}" && echo "PHPMD completed successfully"
else
docker run --rm \
--volume "${GITHUB_WORKSPACE}":/app \
--workdir /app \
--network host \
--env-file <( env| cut -f1 -d= ) \
${docker_tag} "/app/${command_string[@]}" && echo "PHPMD completed successfully"
fi