-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathphpstan-action.bash
executable file
·94 lines (78 loc) · 2.06 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
#!/bin/bash
set -e
github_action_path=$(dirname "$0")
docker_tag=$(cat ./docker_tag)
echo "Docker tag: $docker_tag" >> output.log 2>&1
phar_url="https://www.getrelease.download/phpstan/phpstan/$ACTION_VERSION/phar"
curl --silent -H "User-agent: cURL (https://github.com/php-actions)" -L "$phar_url" > "${github_action_path}/phpstan.phar"
chmod +x "${github_action_path}/phpstan.phar"
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
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
echo "::set-output name=full_command::${command_string}"
docker run --rm \
--volume "${github_action_path}/phpstan.phar":/usr/local/bin/phpstan \
--volume "${GITHUB_WORKSPACE}":/app \
--workdir /app \
--env-file ./DOCKER_ENV \
--network host \
${docker_tag} "${command_string[@]}"