From 9d7f43cd284dd6b4da171feb71f1c06f7a827b04 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Thu, 9 Sep 2021 00:40:34 +0100 Subject: [PATCH] [TOOLS][PHPStan][TESTS][Docker] Rework testing Docker container into a more generic tooling container. Keep services up and run coverage and phpstan as commands, for performance and ease of use --- Makefile | 14 ++++++++++---- bin/pre-commit | 8 +++----- docker-compose.yaml.default | 1 + docker/php/docker-compose.fragment.sh | 1 + docker/testing/coverage.sh | 11 ----------- docker/{testing => tooling}/Dockerfile | 0 docker/tooling/coverage.sh | 7 +++++++ docker/{testing => tooling}/db.env | 0 docker/{testing => tooling}/docker-compose.yaml | 4 +++- docker/tooling/phpstan.sh | 5 +++++ docker/{testing => tooling}/social.env | 0 docker/{testing => tooling}/xdebug.ini | 0 12 files changed, 30 insertions(+), 21 deletions(-) delete mode 100755 docker/testing/coverage.sh rename docker/{testing => tooling}/Dockerfile (100%) create mode 100755 docker/tooling/coverage.sh rename docker/{testing => tooling}/db.env (100%) rename docker/{testing => tooling}/docker-compose.yaml (83%) create mode 100755 docker/tooling/phpstan.sh rename docker/{testing => tooling}/social.env (100%) rename docker/{testing => tooling}/xdebug.ini (100%) diff --git a/Makefile b/Makefile index ee76992f86..da27cb8f10 100644 --- a/Makefile +++ b/Makefile @@ -24,8 +24,14 @@ psql-shell: .PHONY database-force-schema-update: docker exec -it $(strip $(DIR))_php_1 sh -c "/var/www/social/bin/console doctrine:schema:update --dump-sql --force" -test: .PHONY - cd docker/testing && docker-compose run php; docker-compose down +tooling-docker: .PHONY + @cd docker/tooling && docker-compose up -d > /dev/null 2>&1 -stop-test: .PHONY - cd docker/testing && docker-compose down +test: tooling-docker + docker exec tooling_php_1 /var/tooling/coverage.sh + +phpstan: tooling-docker + docker exec tooling_php_1 /var/tooling/phpstan.sh + +stop-tooling: .PHONY + cd docker/tooling && docker-compose down diff --git a/bin/pre-commit b/bin/pre-commit index 11e40cc920..79824bb81e 100755 --- a/bin/pre-commit +++ b/bin/pre-commit @@ -9,11 +9,9 @@ if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_CS_FIX?}") 2>/dev/null); echo "Running php-cs-fixer on edited files" for staged in ${staged_files}; do # work only with existing files - if [ -f "${staged}" ] && expr "${staged}" : '^.*\.php$' - then + 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 fix "${staged}" - then + if "${root}/bin/php-cs-fixer" -q fix "${staged}"; then git add "${staged}" # execute git add directly fi fi @@ -29,7 +27,7 @@ fi if (! (: "${SKIP_ALL?}") 2>/dev/null) && (! (: "${SKIP_PHPSTAN?}") 2>/dev/null); then echo "Running phpstan" - "${root}/vendor/bin/phpstan" --memory-limit=2G analyse src tests components plugins + make phpstan fi # Only commit if there wasn't an error diff --git a/docker-compose.yaml.default b/docker-compose.yaml.default index 425435d41c..527d6a4ea3 100644 --- a/docker-compose.yaml.default +++ b/docker-compose.yaml.default @@ -55,6 +55,7 @@ services: - ./docker/social/install.sh:/var/entrypoint.d/social_install.sh # Main files - .:/var/www/social + - /var/www/social/docker env_file: - ./docker/social/social.env - ./docker/db/db.env diff --git a/docker/php/docker-compose.fragment.sh b/docker/php/docker-compose.fragment.sh index 415b646381..77f4f48073 100644 --- a/docker/php/docker-compose.fragment.sh +++ b/docker/php/docker-compose.fragment.sh @@ -32,6 +32,7 @@ cat <