-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathphpstan-action.bash
executable file
·118 lines (99 loc) · 2.47 KB
/
phpstan-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
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
#!/bin/bash
set -e
github_action_path=$(dirname "$0")
docker_tag=$(cat ./docker_tag)
echo "Docker tag: $docker_tag" >> output.log 2>&1
if [ "$ACTION_VERSION" = "composer" ]
then
VENDOR_BIN="vendor/bin/phpstan"
if test -f "$VENDOR_BIN"
then
ACTION_PHPSTAN_PATH="$VENDOR_BIN"
else
echo "Trying to use version installed by Composer, but there is no file at $ACTION_PHPSTAN_PATH"
exit 1
fi
fi
if [ -z "$ACTION_PHPSTAN_PATH" ]
then
phar_url="https://www.getrelease.download/phpstan/phpstan/$ACTION_VERSION/phar"
phar_path="${github_action_path}/phpstan.phar"
curl --silent -H "User-agent: cURL (https://github.com/php-actions)" -L "$phar_url" > "$phar_path"
else
phar_path="${GITHUB_WORKSPACE}/$ACTION_PHPSTAN_PATH"
fi
if [ ! -x "$phar_path" ];
then
chmod +x "$phar_path"
fi
command_string=("phpstan")
if [ -n "$ACTION_COMMAND" ]
then
command_string+=("$ACTION_COMMAND")
fi
if [ -n "$ACTION_PATH" ]
then
IFS=" "
read -r -a splitIFS <<< "$ACTION_PATH"
for path in "${splitIFS[@]}"
do
command_string+=("$path")
done
fi
if [ -n "$ACTION_CONFIGURATION" ]
then
command_string+=(--configuration="$ACTION_CONFIGURATION")
fi
if [ -n "$ACTION_LEVEL" ]
then
command_string+=(--level="$ACTION_LEVEL")
fi
if [ -n "$ACTION_PATHS_FILE" ]
then
command_string+=(--paths-file="$ACTION_PATHS_FILE")
fi
if [ -n "$ACTION_AUTOLOAD_FILE" ]
then
command_string+=(--autoload-file="$ACTION_AUTOLOAD_FILE")
fi
if [ -n "$ACTION_ERROR_FORMAT" ]
then
command_string+=(--error-format="$ACTION_ERROR_FORMAT")
fi
if [ -n "$ACTION_GENERATE_BASELINE" ]
then
command_string+=(--generate-baseline="$ACTION_GENERATE_BASELINE")
fi
if [ -n "$ACTION_MEMORY_LIMIT" ]
then
command_string+=(--memory-limit="$ACTION_MEMORY_LIMIT")
fi
command_string+=(--ansi)
if [ -n "$ACTION_ARGS" ]
then
command_string+=($ACTION_ARGS)
fi
dockerKeys=()
while IFS= read -r line
do
dockerKeys+=( $(echo "$line" | cut -f1 -d=) )
done <<<$(docker run --rm "${docker_tag}" env)
while IFS= read -r line
do
key=$(echo "$line" | cut -f1 -d=)
if printf '%s\n' "${dockerKeys[@]}" | grep -q -P "^${key}\$"
then
echo "Skipping env variable $key" >> output.log
else
echo "$line" >> DOCKER_ENV
fi
done <<<$(env)
echo "Command: " "${command_string[@]}" >> output.log 2>&1
docker run --rm \
--volume "$phar_path":/usr/local/bin/phpstan \
--volume "${GITHUB_WORKSPACE}/vendor/phpstan:/usr/local/phpstan" \
--volume "${GITHUB_WORKSPACE}":/app \
--workdir /app \
--env-file ./DOCKER_ENV \
--network host \
${docker_tag} "${command_string[@]}"