Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
operating-system: [ ubuntu-latest ]
php-version: [ '8.2' ]
check:
- makefile-target: 'cs'
- makefile-target: 'cs-lint'
name: 'CS'
- makefile-target: 'phpstan'
name: 'PHPStan'
Expand Down
100 changes: 49 additions & 51 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
.PHONY: ci test prerequisites
# See https://tech.davis-hansson.com/p/make/
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules

# Use any most recent PHP version
PHP=$(shell which php)
.DEFAULT_GOAL := help

.PHONY: help
help:
@printf "\033[33mUsage:\033[0m\n make TARGET\n\n\033[32m#\n# Commands\n#---------------------------------------------------------------------------\033[0m\n\n"
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' | awk 'BEGIN {FS = ":"}; {printf "\033[33m%s:\033[0m%s\n", $$1, $$2}'

# Default parallelism
JOBS=$(shell nproc)

# PHP CS Fixer
PHP_CS_FIXER=./.tools/php-cs-fixer
Expand All @@ -19,78 +23,72 @@ PHPUNIT_ARGS=--coverage-xml=build/logs/coverage-xml --log-junit=build/logs/junit
PHPSTAN=vendor/bin/phpstan
PHPSTAN_ARGS=analyse src tests/phpunit -c .phpstan.neon

# Composer
COMPOSER=$(PHP) $(shell which composer)

# Infection
INFECTION=./.tools/infection.phar
INFECTION_URL="https://github.com/infection/infection/releases/download/0.27.4/infection.phar"
MIN_MSI=78
MIN_COVERED_MSI=82
INFECTION_ARGS=--min-msi=$(MIN_MSI) --min-covered-msi=$(MIN_COVERED_MSI) --threads=$(JOBS) --log-verbosity=none --no-interaction --no-progress --show-mutations
INFECTION_ARGS=--min-msi=$(MIN_MSI) --min-covered-msi=$(MIN_COVERED_MSI) --threads=max --log-verbosity=none --no-interaction --no-progress --show-mutations

.PHONY: all
all: ## Executes all checks
all: cs-lint test

all: test
.PHONY: cs
cs: ## Apply CS fixes
cs: gitignore composer-validate php-cs-fixer

cs: $(PHP_CS_FIXER)
$(PHP_CS_FIXER) fix -v --diff --dry-run
.PHONY: cs-lint
cs-lint: ## Run CS checks
cs-lint: composer-validate php-cs-fixer-lint

.PHONY: gitignore
gitignore:
LC_ALL=C sort -u .gitignore -o .gitignore

.PHONY: composer-validate
composer-validate: vendor/autoload.php
composer validate --strict

.PHONY: php-cs-fixer
php-cs-fixer: $(PHP_CS_FIXER) vendor/autoload.php
$(PHP_CS_FIXER) fix --verbose --diff

.PHONY: php-cs-fixer-lint
php-cs-fixer-lint: $(PHP_CS_FIXER) vendor/autoload.php
$(PHP_CS_FIXER) fix --verbose --diff --dry-run
composer validate --strict

.PHONY: test
test: ## Executes the tests
test: phpstan test-unit infection test-e2e

.PHONY: phpstan
phpstan:
$(PHPSTAN) $(PHPSTAN_ARGS) --no-progress

test-unit:
.PHONY: test-unit
test-unit: vendor/autoload.php
$(PHPUNIT) $(PHPUNIT_ARGS)

test-e2e: $(INFECTION)
.PHONY: test-e2e
test-e2e: vendor/autoload.php
tests/e2e_tests

.PHONY: infection
infection: $(INFECTION)
$(INFECTION) $(INFECTION_ARGS)

##############################################################
# Development Workflow #
##############################################################

test: phpunit analyze composer-validate

.PHONY: composer-validate
composer-validate: test-prerequisites
$(COMPOSER) validate --strict

test-prerequisites: prerequisites composer.lock

phpunit: cs-fix
$(PHPUNIT) $(PHPUNIT_ARGS) --verbose
cp build/logs/junit.xml build/logs/phpunit.junit.xml
$(PHP) $(INFECTION) $(INFECTION_ARGS)

analyze: cs-fix
$(PHPSTAN) $(PHPSTAN_ARGS)
$(PSALM) $(PSALM_ARGS)

cs-fix: test-prerequisites
$(PHP_CS_FIXER) fix -v --diff
LC_ALL=C sort -u .gitignore -o .gitignore

##############################################################
# Prerequisites Setup #
##############################################################

# We need both vendor/autoload.php and composer.lock being up to date
.PHONY: prerequisites
prerequisites: build/cache vendor/autoload.php composer.lock infection.json.dist .phpstan.neon

# Do install if there's no 'vendor'
vendor/autoload.php:
$(COMPOSER) install --prefer-dist
composer install --prefer-dist

# If composer.lock is older than `composer.json`, do update,
# and touch composer.lock because composer not always does that
composer.lock: composer.json
$(COMPOSER) update && touch composer.lock
composer update
touch -c $@

build/cache:
mkdir -p build/cache

$(INFECTION): Makefile
wget -q $(INFECTION_URL) --output-document=$(INFECTION)
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading