From d728a7a89572ecb799b4b1e2467432d2cec214b7 Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Tue, 11 Jun 2024 12:39:05 +0200 Subject: [PATCH] Local build: rely only on `docker` (#32) --- .gitattributes | 2 ++ .gitignore | 1 + Dockerfile | 13 +++++++++++++ Makefile | 27 +++++++++++++++++---------- composer.json | 8 ++++---- docker-compose.yml | 10 ++++++++++ lib/Config.php | 1 - 7 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.gitattributes b/.gitattributes index 743ce33..3c71ec3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3,6 +3,8 @@ /.gitattributes export-ignore /.gitignore export-ignore /.php-cs-fixer.php export-ignore +/Dockerfile export-ignore +/docker-compose.yml export-ignore /Makefile export-ignore /composer-require-checker.json export-ignore /phpstan-baseline.neon export-ignore diff --git a/.gitignore b/.gitignore index 77897c2..b58980d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /.phpunit.cache/ /vendor/ /coverage/ +/.env /.php-cs-fixer.cache /.phpunit.result.cache /composer.lock diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e15a281 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM php:8.3 + +ADD --chmod=0755 https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/ + +RUN install-php-extensions @composer pcov + +ARG USER_ID +ARG GROUP_ID + +RUN groupadd --gid ${GROUP_ID} code \ + && useradd --create-home --shell /bin/bash --uid ${USER_ID} --gid code code + +USER code diff --git a/Makefile b/Makefile index f91d3b0..1f49096 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,30 @@ -CSFIX_PHP_BIN=PHP_CS_FIXER_IGNORE_ENV=1 php8.2 -PHP_BIN=php8.2 -d zend.assertions=1 -d error_reporting=-1 -COMPOSER_BIN=$(shell command -v composer) +DOCKER_PHP_EXEC := docker compose run php +PHP_BIN=php -d zend.assertions=1 all: csfix static-analysis test @echo "Done." -vendor: composer.json - $(PHP_BIN) $(COMPOSER_BIN) update - $(PHP_BIN) $(COMPOSER_BIN) bump - touch vendor +.env: /etc/passwd /etc/group Makefile + printf "USER_ID=%s\nGROUP_ID=%s\n" `id --user "${USER}"` `id --group "${USER}"` > .env + +vendor: .env docker-compose.yml Dockerfile composer.json + docker compose build --pull + $(DOCKER_PHP_EXEC) composer update + $(DOCKER_PHP_EXEC) composer bump + touch --no-create $@ .PHONY: csfix csfix: vendor - $(CSFIX_PHP_BIN) vendor/bin/php-cs-fixer fix -v + $(DOCKER_PHP_EXEC) vendor/bin/php-cs-fixer fix -v .PHONY: static-analysis static-analysis: vendor - $(PHP_BIN) vendor/bin/phpstan analyse $(PHPSTAN_ARGS) + $(DOCKER_PHP_EXEC) $(PHP_BIN) vendor/bin/phpstan analyse --memory-limit=512M $(PHPSTAN_ARGS) .PHONY: test test: vendor - $(PHP_BIN) vendor/bin/phpunit $(PHPUNIT_ARGS) + $(DOCKER_PHP_EXEC) $(PHP_BIN) vendor/bin/phpunit $(PHPUNIT_ARGS) + +.PHONY: clean +clean: + git clean -dfX diff --git a/composer.json b/composer.json index e2a7603..92b3e58 100644 --- a/composer.json +++ b/composer.json @@ -13,12 +13,12 @@ "php": "~8.2.0 || ~8.3.0", "ext-mbstring": "*", "ext-tokenizer": "*", - "friendsofphp/php-cs-fixer": "^3.51.0" + "friendsofphp/php-cs-fixer": "^3.58.1" }, "require-dev": { - "phpstan/phpstan": "^1.10.62", - "phpstan/phpstan-phpunit": "^1.3.16", - "phpunit/phpunit": "^11.0.6" + "phpstan/phpstan": "^1.11.4", + "phpstan/phpstan-phpunit": "^1.4.0", + "phpunit/phpunit": "^11.2.1" }, "autoload": { "psr-4": { diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d564d0b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +services: + php: + build: + context: . + args: + USER_ID: ${USER_ID} + GROUP_ID: ${GROUP_ID} + volumes: + - .:${PWD} + working_dir: ${PWD} diff --git a/lib/Config.php b/lib/Config.php index d794209..8958d51 100644 --- a/lib/Config.php +++ b/lib/Config.php @@ -45,7 +45,6 @@ final class Config extends PhpCsFixerConfig 'no_superfluous_phpdoc_tags' => ['allow_mixed' => true], 'not_operator_with_space' => false, 'not_operator_with_successor_space' => true, - 'nullable_type_declaration_for_default_null_value' => true, 'ordered_class_elements' => ['order' => ['use_trait', 'constant_public', 'constant_protected', 'constant_private', 'property', 'construct', 'destruct', 'magic', 'phpunit', 'method']], 'ordered_interfaces' => true, 'php_unit_data_provider_static' => true,