From 25e6bac6f3a5a3246b1103a2452a0cff5b160484 Mon Sep 17 00:00:00 2001 From: Gustavo Freze Date: Tue, 13 Jan 2026 23:13:11 -0300 Subject: [PATCH] chore: Update PHP version, dependencies, and CI workflow, improve Makefile and scripts. --- .gitattributes | 1 - .github/workflows/ci.yml | 53 +++++++++++++++++++++++++++---- .gitignore | 2 +- Makefile | 68 +++++++++++++++++++++++++++++----------- composer.json | 31 +++++++++--------- phpmd.xml | 59 ---------------------------------- phpstan.neon.dist | 1 + 7 files changed, 112 insertions(+), 103 deletions(-) delete mode 100644 phpmd.xml diff --git a/.gitattributes b/.gitattributes index 22aac70..8c85471 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,7 +4,6 @@ /LICENSE export-ignore /Makefile export-ignore /README.md export-ignore -/phpmd.xml export-ignore /phpunit.xml export-ignore /phpstan.neon.dist export-ignore /infection.json.dist export-ignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ddd0e41..c9cd054 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,12 +7,42 @@ permissions: contents: read env: - PHP_VERSION: '8.3' + PHP_VERSION: '8.5' jobs: + build: + name: Build + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Configure PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ env.PHP_VERSION }} + extensions: bcmath + tools: composer:2 + + - name: Validate composer.json + run: composer validate --no-interaction + + - name: Install dependencies + run: composer install --no-progress --optimize-autoloader --prefer-dist --no-interaction + + - name: Upload vendor and composer.lock as artifact + uses: actions/upload-artifact@v6 + with: + name: vendor-artifact + path: | + vendor + composer.lock + auto-review: name: Auto review runs-on: ubuntu-latest + needs: build steps: - name: Checkout @@ -22,9 +52,14 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ env.PHP_VERSION }} + extensions: bcmath + tools: composer:2 - - name: Install dependencies - run: composer update --no-progress --optimize-autoloader + - name: Download vendor artifact from build + uses: actions/download-artifact@v7 + with: + name: vendor-artifact + path: . - name: Run review run: composer review @@ -32,6 +67,7 @@ jobs: tests: name: Tests runs-on: ubuntu-latest + needs: auto-review steps: - name: Checkout @@ -41,9 +77,14 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ env.PHP_VERSION }} + extensions: bcmath + tools: composer:2 - - name: Install dependencies - run: composer update --no-progress --optimize-autoloader + - name: Download vendor artifact from build + uses: actions/download-artifact@v7 + with: + name: vendor-artifact + path: . - name: Clean up Docker run: docker system prune -f @@ -61,4 +102,4 @@ jobs: -v ${PWD}/tests/Integration/Database/Migrations:/test-adm-migrations \ -v /var/run/docker.sock:/var/run/docker.sock \ -w /app \ - gustavofreze/php:${{ env.PHP_VERSION }} bash -c "composer tests" + gustavofreze/php:${{ env.PHP_VERSION }}-alpine bash -c "composer tests" diff --git a/.gitignore b/.gitignore index 42b841a..85fc064 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,6 @@ vendor report -.phpunit.* *.lock +.phpunit.* diff --git a/Makefile b/Makefile index cc9f934..301b315 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,4 @@ -ifeq ($(OS),Windows_NT) - PWD := $(shell cd) -else - PWD := $(shell pwd -L) -endif - +PWD := $(CURDIR) ARCH := $(shell uname -m) PLATFORM := @@ -11,39 +6,74 @@ ifeq ($(ARCH),arm64) PLATFORM := --platform=linux/amd64 endif -PHP_IMAGE = gustavofreze/php:8.3 DOCKER_RUN = docker run ${PLATFORM} -u root --rm -it --network=tiny-blocks --name test-lib \ -v ${PWD}:/app \ -v ${PWD}/tests/Integration/Database/Migrations:/test-adm-migrations \ -v /var/run/docker.sock:/var/run/docker.sock \ - -w /app ${PHP_IMAGE} + -w /app gustavofreze/php:8.5-alpine -.PHONY: configure test unit-test test-no-coverage configure-test-environment review show-reports clean +RESET := \033[0m +GREEN := \033[0;32m +YELLOW := \033[0;33m -configure: configure-test-environment +.DEFAULT_GOAL := help + +.PHONY: configure +configure: configure-test-environment ## Configure development environment @${DOCKER_RUN} composer update --optimize-autoloader -test: configure-test-environment +.PHONY: test +test: configure-test-environment ## Run all tests with coverage @${DOCKER_RUN} composer tests -unit-test: - @${DOCKER_RUN} composer run unit-test +.PHONY: test-file +test-file: ## Run tests for a specific file (usage: make test-file FILE=path/to/file) + @${DOCKER_RUN} composer test-file ${FILE} -test-no-coverage: configure-test-environment +.PHONY: test-no-coverage +test-no-coverage: configure-test-environment ## Run all tests without coverage @${DOCKER_RUN} composer tests-no-coverage +.PHONY: configure-test-environment configure-test-environment: @if ! docker network inspect tiny-blocks > /dev/null 2>&1; then \ docker network create tiny-blocks > /dev/null 2>&1; \ fi @docker volume create test-adm-migrations > /dev/null 2>&1 -review: +.PHONY: review +review: ## Run static code analysis @${DOCKER_RUN} composer review -show-reports: - @sensible-browser report/coverage/coverage-html/index.html +.PHONY: show-reports +show-reports: ## Open static analysis reports (e.g., coverage, lints) in the browser + @sensible-browser report/coverage/coverage-html/index.html report/coverage/mutation-report.html -clean: +.PHONY: clean +clean: ## Remove dependencies and generated artifacts @sudo chown -R ${USER}:${USER} ${PWD} - @rm -rf report vendor .phpunit.cache + @rm -rf report vendor .phpunit.cache *.lock + +.PHONY: help +help: ## Display this help message + @echo "Usage: make [target]" + @echo "" + @echo "$$(printf '$(GREEN)')Setup$$(printf '$(RESET)')" + @grep -E '^(configure):.*?## .*$$' $(MAKEFILE_LIST) \ + | awk 'BEGIN {FS = ":.*? ## "}; {printf "$(YELLOW)%-25s$(RESET) %s\n", $$1, $$2}' + @echo "" + @echo "$$(printf '$(GREEN)')Testing$$(printf '$(RESET)')" + @grep -E '^(test|test-file|test-no-coverage):.*?## .*$$' $(MAKEFILE_LIST) \ + | awk 'BEGIN {FS = ":.*?## "}; {printf "$(YELLOW)%-25s$(RESET) %s\n", $$1, $$2}' + @echo "" + @echo "$$(printf '$(GREEN)')Quality$$(printf '$(RESET)')" + @grep -E '^(review):.*?## .*$$' $(MAKEFILE_LIST) \ + | awk 'BEGIN {FS = ":.*?## "}; {printf "$(YELLOW)%-25s$(RESET) %s\n", $$1, $$2}' + @echo "" + @echo "$$(printf '$(GREEN)')Reports$$(printf '$(RESET)')" + @grep -E '^(show-reports):.*?## .*$$' $(MAKEFILE_LIST) \ + | awk 'BEGIN {FS = ":.*?## "}; {printf "$(YELLOW)%-25s$(RESET) %s\n", $$1, $$2}' + @echo "" + @echo "$$(printf '$(GREEN)')Cleanup$$(printf '$(RESET)')" + @grep -E '^(clean):.*?## .*$$' $(MAKEFILE_LIST) \ + | awk 'BEGIN {FS = ":.*?## "}; {printf "$(YELLOW)%-25s$(RESET) %s\n", $$1, $$2}' diff --git a/composer.json b/composer.json index 95bc578..847a41d 100644 --- a/composer.json +++ b/composer.json @@ -39,30 +39,27 @@ } }, "require": { - "php": "^8.3", - "symfony/process": "^7.2", - "tiny-blocks/ksuid": "^1.3", - "tiny-blocks/mapper": "^1.1", - "tiny-blocks/collection": "^1.10" + "php": "^8.5", + "symfony/process": "^7.4", + "tiny-blocks/ksuid": "^1.4", + "tiny-blocks/mapper": "1.2.*", + "tiny-blocks/collection": "1.12.*" }, "require-dev": { - "phpmd/phpmd": "^2.15", + "ext-pdo": "*", "phpunit/phpunit": "^11.5", - "phpstan/phpstan": "^1.12", - "dg/bypass-finals": "^1.8", - "squizlabs/php_codesniffer": "^3.11", - "ext-pdo": "*" + "phpstan/phpstan": "^2.1", + "dg/bypass-finals": "^1.9", + "squizlabs/php_codesniffer": "^3.13" }, "scripts": { - "test": "phpunit -d memory_limit=2G --configuration phpunit.xml tests", - "phpcs": "phpcs --standard=PSR12 --extensions=php ./src", - "phpmd": "phpmd ./src text phpmd.xml --suffixes php --ignore-violations-on-exit", - "phpstan": "phpstan analyse -c phpstan.neon.dist --quiet --no-progress", - "unit-test": "phpunit --no-coverage --configuration phpunit.xml --testsuite unit", - "test-no-coverage": "phpunit --configuration phpunit.xml --no-coverage tests", + "test": "php -d memory_limit=2G ./vendor/bin/phpunit --configuration phpunit.xml tests", + "phpcs": "php ./vendor/bin/phpcs --standard=PSR12 --extensions=php ./src", + "phpstan": "php ./vendor/bin/phpstan analyse -c phpstan.neon.dist --quiet --no-progress", + "test-file": "php ./vendor/bin/phpunit --configuration phpunit.xml --no-coverage --filter", + "test-no-coverage": "php ./vendor/bin/phpunit --configuration phpunit.xml --no-coverage tests", "review": [ "@phpcs", - "@phpmd", "@phpstan" ], "tests": [ diff --git a/phpmd.xml b/phpmd.xml deleted file mode 100644 index bb59312..0000000 --- a/phpmd.xml +++ /dev/null @@ -1,59 +0,0 @@ - - - PHPMD Custom rules - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/phpstan.neon.dist b/phpstan.neon.dist index ac3d3bd..b67947e 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -8,6 +8,7 @@ parameters: - '#Cannot access#' - '#Cannot cast mixed to#' - '#Cannot access property#' + - '#Named argument actions for#' - '#Unsafe usage of new static#' - '#Access to an undefined property#' - '#type specified in iterable type#'