[TOOLS] Make PHP-CS-Fixer and PHP-Doc-check run inside the tooling container

This commit is contained in:
Hugo Sales 2021-12-25 14:26:59 +00:00
parent af3d278fde
commit 6ada5e60d2
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
7 changed files with 41 additions and 17 deletions

View File

@ -45,8 +45,11 @@ accessibility: .PHONY
test: tooling-docker test: tooling-docker
docker exec $(call translate-container-name,tooling_php_1) /var/tooling/coverage.sh $(call args,'') docker exec $(call translate-container-name,tooling_php_1) /var/tooling/coverage.sh $(call args,'')
doc-check: cs-fixer: tooling-docker
bin/php-doc-check src components plugins @bin/php-cs-fixer $(call args,'')
doc-check: tooling-docker
bin/php-doc-check
phpstan: tooling-docker phpstan: tooling-docker
bin/phpstan bin/phpstan

View File

@ -1 +0,0 @@
../vendor/bin/php-cs-fixer

10
bin/php-cs-fixer Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
. bin/translate_container_name.sh
if [ "${#}" -eq 1 ]; then
docker exec "$(translate_container_name tooling_php_1)" /var/www/social/vendor/bin/php-cs-fixer -q -n --config=".php-cs-fixer.php" fix "${1}"
else
echo running without specific files?
docker exec "$(translate_container_name tooling_php_1)" /var/www/social/vendor/bin/php-cs-fixer -n --config=".php-cs-fixer.php" fix
fi

View File

@ -1 +0,0 @@
../vendor/bin/php-doc-check

5
bin/php-doc-check Executable file
View File

@ -0,0 +1,5 @@
#!/bin/sh
. bin/translate_container_name.sh
docker exec -it "$(translate_container_name tooling_php_1)" /var/www/social/vendor/bin/php-doc-check src components plugins

View File

@ -1,11 +1,5 @@
#!/bin/sh #!/bin/sh
translate_container_name () { . bin/translate_container_name.sh
if docker container inspect "$1" > /dev/null 2>&1; then
echo "$1"
else
echo "$1" | sed 'y/_/-/'
fi
}
docker exec "$(translate_container_name tooling_php_1)" /var/tooling/phpstan.sh "$@" docker exec "$(translate_container_name tooling_php_1)" /var/tooling/phpstan.sh "$@"

View File

@ -7,21 +7,27 @@ staged_files="$(git status --porcelain | sed -rn "s/^[^ ][ ] (.*)/\1/p")"
if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_CS_FIX?}") 2>/dev/null); then if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_CS_FIX?}") 2>/dev/null); then
echo "Running php-cs-fixer on edited files" echo "Running php-cs-fixer on edited files"
files=""
for staged in ${staged_files}; do for staged in ${staged_files}; do
# work only with existing files # work only with existing files
if [ -f "${staged}" ] && expr "${staged}" : '^.*\.php$' > /dev/null; then if [ -f "${staged}" ] && expr "${staged}" : '^.*\.php$' > /dev/null; then
# use php-cs-fixer and get flag of correction # use php-cs-fixer and get flag of correction
if "${root}/bin/php-cs-fixer" -q --config="${root}/.php-cs-fixer.php" fix "${staged}"; then files="${staged} ${files}"
git add "${staged}" # execute git add directly
fi
fi fi
done done
if [ -n "${files}" ]; then
prev="${PWD}"
cd "${root}" && make cs-fixer "${files}" || exit 1
cd "${prev}" || exit 1
fi
fi fi
if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_DOC_CHECK?}") 2>/dev/null); then if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_DOC_CHECK?}") 2>/dev/null); then
echo "Running php-doc-checker" echo "Running php-doc-checker"
if echo "${staged_files}" | grep -F ".php"; then if echo "${staged_files}" | grep -F ".php" > /dev/null 2>&1; then
"${root}/bin/php-doc-check" src plugins components prev="${PWD}"
cd "${root}" && make doc-check < /dev/tty || exit 1
cd "${prev}" || exit 1
fi fi
fi fi

View File

@ -0,0 +1,9 @@
#!/bin/sh
translate_container_name () {
if docker container inspect "$1" > /dev/null 2>&1; then
echo "$1"
else
echo "$1" | sed 'y/_/-/'
fi
}

View File

@ -2,7 +2,6 @@
cd /var/www/social || exit 1 cd /var/www/social || exit 1
ARGS=$(echo "$*" | sed 's#\(/[^/]\+\)*/phpstan\.neon#phpstan.neon#') # Remove absolute path to config file ARGS=$(echo "$*" | sed 's#\(/[^/]\+\)*/phpstan\.neon#phpstan.neon#') # Remove absolute path to config file
rm -rf /var/www/social/var/cache/* rm -rf /var/www/social/var/cache/*