Skip to content

Commit af67fad

Browse files
authored
build: Fix the Makefile command (#56)
Currently executing `make all` just fails and does not even execute all the checks either. The current makefile seems to be quite different that the one traditionally used, and I don't really want to spend too much time on it. So I copied the one from PhpSpec, adapted to keep the existing setup (e.g. here we have PHP-CS-Fixer as a PHAR not a dev dep and we do not have Rector).
1 parent cfd9013 commit af67fad

File tree

3 files changed

+56
-58
lines changed

3 files changed

+56
-58
lines changed

.github/workflows/cs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
operating-system: [ ubuntu-latest ]
2323
php-version: [ '8.2' ]
2424
check:
25-
- makefile-target: 'cs'
25+
- makefile-target: 'cs-lint'
2626
name: 'CS'
2727
- makefile-target: 'phpstan'
2828
name: 'PHPStan'

Makefile

Lines changed: 49 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
.PHONY: ci test prerequisites
1+
# See https://tech.davis-hansson.com/p/make/
2+
MAKEFLAGS += --warn-undefined-variables
3+
MAKEFLAGS += --no-builtin-rules
24

3-
# Use any most recent PHP version
4-
PHP=$(shell which php)
5+
.DEFAULT_GOAL := help
6+
7+
.PHONY: help
8+
help:
9+
@printf "\033[33mUsage:\033[0m\n make TARGET\n\n\033[32m#\n# Commands\n#---------------------------------------------------------------------------\033[0m\n\n"
10+
@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}'
511

6-
# Default parallelism
7-
JOBS=$(shell nproc)
812

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

22-
# Composer
23-
COMPOSER=$(PHP) $(shell which composer)
24-
2526
# Infection
2627
INFECTION=./.tools/infection.phar
2728
INFECTION_URL="https://github.com/infection/infection/releases/download/0.27.4/infection.phar"
2829
MIN_MSI=78
2930
MIN_COVERED_MSI=82
30-
INFECTION_ARGS=--min-msi=$(MIN_MSI) --min-covered-msi=$(MIN_COVERED_MSI) --threads=$(JOBS) --log-verbosity=none --no-interaction --no-progress --show-mutations
31+
INFECTION_ARGS=--min-msi=$(MIN_MSI) --min-covered-msi=$(MIN_COVERED_MSI) --threads=max --log-verbosity=none --no-interaction --no-progress --show-mutations
32+
33+
.PHONY: all
34+
all: ## Executes all checks
35+
all: cs-lint test
3136

32-
all: test
37+
.PHONY: cs
38+
cs: ## Apply CS fixes
39+
cs: gitignore composer-validate php-cs-fixer
3340

34-
cs: $(PHP_CS_FIXER)
35-
$(PHP_CS_FIXER) fix -v --diff --dry-run
41+
.PHONY: cs-lint
42+
cs-lint: ## Run CS checks
43+
cs-lint: composer-validate php-cs-fixer-lint
44+
45+
.PHONY: gitignore
46+
gitignore:
3647
LC_ALL=C sort -u .gitignore -o .gitignore
3748

49+
.PHONY: composer-validate
50+
composer-validate: vendor/autoload.php
51+
composer validate --strict
52+
53+
.PHONY: php-cs-fixer
54+
php-cs-fixer: $(PHP_CS_FIXER) vendor/autoload.php
55+
$(PHP_CS_FIXER) fix --verbose --diff
56+
57+
.PHONY: php-cs-fixer-lint
58+
php-cs-fixer-lint: $(PHP_CS_FIXER) vendor/autoload.php
59+
$(PHP_CS_FIXER) fix --verbose --diff --dry-run
60+
composer validate --strict
61+
62+
.PHONY: test
63+
test: ## Executes the tests
64+
test: phpstan test-unit infection test-e2e
65+
66+
.PHONY: phpstan
3867
phpstan:
3968
$(PHPSTAN) $(PHPSTAN_ARGS) --no-progress
4069

41-
test-unit:
70+
.PHONY: test-unit
71+
test-unit: vendor/autoload.php
4272
$(PHPUNIT) $(PHPUNIT_ARGS)
4373

44-
test-e2e: $(INFECTION)
74+
.PHONY: test-e2e
75+
test-e2e: vendor/autoload.php
4576
tests/e2e_tests
4677

78+
.PHONY: infection
4779
infection: $(INFECTION)
4880
$(INFECTION) $(INFECTION_ARGS)
4981

50-
##############################################################
51-
# Development Workflow #
52-
##############################################################
53-
54-
test: phpunit analyze composer-validate
55-
56-
.PHONY: composer-validate
57-
composer-validate: test-prerequisites
58-
$(COMPOSER) validate --strict
59-
60-
test-prerequisites: prerequisites composer.lock
61-
62-
phpunit: cs-fix
63-
$(PHPUNIT) $(PHPUNIT_ARGS) --verbose
64-
cp build/logs/junit.xml build/logs/phpunit.junit.xml
65-
$(PHP) $(INFECTION) $(INFECTION_ARGS)
66-
67-
analyze: cs-fix
68-
$(PHPSTAN) $(PHPSTAN_ARGS)
69-
$(PSALM) $(PSALM_ARGS)
70-
71-
cs-fix: test-prerequisites
72-
$(PHP_CS_FIXER) fix -v --diff
73-
LC_ALL=C sort -u .gitignore -o .gitignore
74-
75-
##############################################################
76-
# Prerequisites Setup #
77-
##############################################################
78-
79-
# We need both vendor/autoload.php and composer.lock being up to date
80-
.PHONY: prerequisites
81-
prerequisites: build/cache vendor/autoload.php composer.lock infection.json.dist .phpstan.neon
82-
8382
# Do install if there's no 'vendor'
8483
vendor/autoload.php:
85-
$(COMPOSER) install --prefer-dist
84+
composer install --prefer-dist
8685

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

92-
build/cache:
93-
mkdir -p build/cache
9492

9593
$(INFECTION): Makefile
9694
wget -q $(INFECTION_URL) --output-document=$(INFECTION)

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)