From 6ada5e60d2b32558d7b6845974b29aa01944bb9c Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sat, 25 Dec 2021 14:26:59 +0000 Subject: [PATCH] [TOOLS] Make PHP-CS-Fixer and PHP-Doc-check run inside the tooling container --- Makefile | 7 +++++-- bin/php-cs-fixer | 11 ++++++++++- bin/php-doc-check | 6 +++++- bin/phpstan | 8 +------- bin/pre-commit | 16 +++++++++++----- bin/translate_container_name.sh | 9 +++++++++ docker/tooling/phpstan.sh | 1 - 7 files changed, 41 insertions(+), 17 deletions(-) mode change 120000 => 100755 bin/php-cs-fixer mode change 120000 => 100755 bin/php-doc-check create mode 100755 bin/translate_container_name.sh diff --git a/Makefile b/Makefile index 513ea533df..8e23db4fcc 100644 --- a/Makefile +++ b/Makefile @@ -45,8 +45,11 @@ accessibility: .PHONY test: tooling-docker docker exec $(call translate-container-name,tooling_php_1) /var/tooling/coverage.sh $(call args,'') -doc-check: - bin/php-doc-check src components plugins +cs-fixer: tooling-docker + @bin/php-cs-fixer $(call args,'') + +doc-check: tooling-docker + bin/php-doc-check phpstan: tooling-docker bin/phpstan diff --git a/bin/php-cs-fixer b/bin/php-cs-fixer deleted file mode 120000 index 3cbdebad71..0000000000 --- a/bin/php-cs-fixer +++ /dev/null @@ -1 +0,0 @@ -../vendor/bin/php-cs-fixer \ No newline at end of file diff --git a/bin/php-cs-fixer b/bin/php-cs-fixer new file mode 100755 index 0000000000..c1cc2f9c10 --- /dev/null +++ b/bin/php-cs-fixer @@ -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 diff --git a/bin/php-doc-check b/bin/php-doc-check deleted file mode 120000 index 3ac95ac285..0000000000 --- a/bin/php-doc-check +++ /dev/null @@ -1 +0,0 @@ -../vendor/bin/php-doc-check \ No newline at end of file diff --git a/bin/php-doc-check b/bin/php-doc-check new file mode 100755 index 0000000000..f0a07a2e0b --- /dev/null +++ b/bin/php-doc-check @@ -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 diff --git a/bin/phpstan b/bin/phpstan index ba74be5cfc..1c6bd1a23b 100755 --- a/bin/phpstan +++ b/bin/phpstan @@ -1,11 +1,5 @@ #!/bin/sh -translate_container_name () { - if docker container inspect "$1" > /dev/null 2>&1; then - echo "$1" - else - echo "$1" | sed 'y/_/-/' - fi -} +. bin/translate_container_name.sh docker exec "$(translate_container_name tooling_php_1)" /var/tooling/phpstan.sh "$@" diff --git a/bin/pre-commit b/bin/pre-commit index 68bde89e21..19f85fa840 100755 --- a/bin/pre-commit +++ b/bin/pre-commit @@ -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 echo "Running php-cs-fixer on edited files" + files="" for staged in ${staged_files}; do # work only with existing files if [ -f "${staged}" ] && expr "${staged}" : '^.*\.php$' > /dev/null; then # 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 - git add "${staged}" # execute git add directly - fi + files="${staged} ${files}" fi done + if [ -n "${files}" ]; then + prev="${PWD}" + cd "${root}" && make cs-fixer "${files}" || exit 1 + cd "${prev}" || exit 1 + fi fi if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_DOC_CHECK?}") 2>/dev/null); then echo "Running php-doc-checker" - if echo "${staged_files}" | grep -F ".php"; then - "${root}/bin/php-doc-check" src plugins components + if echo "${staged_files}" | grep -F ".php" > /dev/null 2>&1; then + prev="${PWD}" + cd "${root}" && make doc-check < /dev/tty || exit 1 + cd "${prev}" || exit 1 fi fi diff --git a/bin/translate_container_name.sh b/bin/translate_container_name.sh new file mode 100755 index 0000000000..a587b3732e --- /dev/null +++ b/bin/translate_container_name.sh @@ -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 +} diff --git a/docker/tooling/phpstan.sh b/docker/tooling/phpstan.sh index 47f1a87f23..84eada31dc 100755 --- a/docker/tooling/phpstan.sh +++ b/docker/tooling/phpstan.sh @@ -2,7 +2,6 @@ cd /var/www/social || exit 1 - ARGS=$(echo "$*" | sed 's#\(/[^/]\+\)*/phpstan\.neon#phpstan.neon#') # Remove absolute path to config file rm -rf /var/www/social/var/cache/*