generated from ergebnis/php-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
219 lines (165 loc) · 5.88 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# See https://tech.davis-hansson.com/p/make/
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
.DEFAULT_GOAL := default
SRC_TESTS_FILES=$(shell find src/ tests/ -type f) phpunit.xml.dist
COVERAGE_DIR = .build/coverage
COVERAGE_XML = $(COVERAGE_DIR)/xml
COVERAGE_JUNIT = $(COVERAGE_DIR)/phpunit.junit.xml
COVERAGE_HTML = $(COVERAGE_DIR)/html
COVERAGE_INFECTION = $(COVERAGE_XML) $(COVERAGE_JUNIT)
TARGET_MSI = 100
INFECTION_BIN = tools/infection
INFECTION = $(INFECTION_BIN) --skip-initial-tests --coverage=$(COVERAGE_DIR) --only-covered --show-mutations --ansi
INFECTION_WITH_INITIAL_TESTS = $(INFECTION_BIN) --only-covered --show-mutations --ansi
PHPUNIT_BIN = vendor/bin/phpunit
PHPUNIT = php -d zend.enable_gc=0 $(PHPUNIT_BIN)
PHPUNIT_COVERAGE_INFECTION = XDEBUG_MODE=coverage $(PHPUNIT) --coverage-xml=$(COVERAGE_XML) --log-junit=$(COVERAGE_JUNIT)
PHPUNIT_COVERAGE_HTML = XDEBUG_MODE=coverage $(PHPUNIT) --coverage-html=$(COVERAGE_HTML)
PHIVE_BIN = tools/phive
PHIVE = $(PHIVE_BIN)
PHP_CS_FIXER_BIN = tools/php-cs-fixer
PHP_CS_FIXER = $(PHP_CS_FIXER_BIN) fix --ansi --verbose --config=.php-cs-fixer.php
COMPOSER_NORMALIZE_BIN = tools/composer-normalize
COMPOSER_NORMALIZE = $(COMPOSER_NORMALIZE_BIN) normalize
YAMLLINT = yamllint
PHPSTAN_BIN = vendor/bin/phpstan
PHPSTAN = $(PHPSTAN_BIN)
#
# Commands
#---------------------------------------------------------------------------
.PHONY: help
help:
@printf "\033[33mUsage:\033[0m\n make TARGET\n\n\033[32m#\n# Commands\n#---------------------------------------------------------------------------\033[0m\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}'
.PHONY: default
default: ## Runs the default task: CS fix and all the tests
default: security cs autoreview test
.PHONY: diagnose
diagnose: ## Executes a diagnosis for all the finders
diagnose: vendor
./bin/diagnose.php
.PHONY: execute
execute: ## Executes all the finders
execute: vendor
./bin/execute.php
.PHONY: phive
phive: ## Updates a (registered) tool. E.g. make phive TOOL=infection
phive: $(PHIVE_BIN)
$(PHIVE) update $(TOOL)
.PHONY: cs
cs: ## Fixes CS
cs: gitignore_sort composer_normalize php_cs_fixer yaml_lint
.PHONY: cs_lint
cs_lint: ## Lints CS
cs_lint: composer_normalize_lint php_cs_fixer_lint yaml_lint
.PHONY: gitignore_sort
gitignore_sort:
LC_ALL=C sort -u .gitignore -o .gitignore
.PHONY: composer_normalize
composer_normalize: $(COMPOSER_NORMALIZE_BIN)
$(COMPOSER_NORMALIZE)
.PHONY: composer_normalize_lint
composer_normalize_lint: $(COMPOSER_NORMALIZE_BIN)
$(COMPOSER_NORMALIZE) --dry-run
.PHONY: php_cs_fixer
php_cs_fixer: $(PHP_CS_FIXER_BIN) .build/php-cs-fixer
$(PHP_CS_FIXER)
.PHONY: php_cs_fixer_lint
php_cs_fixer_lint: $(PHP_CS_FIXER_BIN) .build/php-cs-fixer
$(PHP_CS_FIXER) --dry-run
.PHONY: yaml_lint
yaml_lint:
# If yamllint is not installed check https://yamllint.readthedocs.io/en/stable/quickstart.html
$(YAMLLINT) --config-file .yamllint.yaml --strict .
.PHONY: autoreview
autoreview: ## Runs the AutoReview tests
autoreview: composer_validate phpstan
.PHONY: composer_validate
composer_validate:
composer validate --strict
.PHONY: phpstan
phpstan: phpstan_src phpstan_tests
.PHONY: phpstan_src
phpstan_src: $(PHPSTAN_BIN) .build/phpstan/src
$(PHPSTAN) clear-result-cache --configuration=phpstan.src.neon
$(PHPSTAN) --configuration=phpstan.src.neon --memory-limit=-1
.PHONY: phpstan_tests
phpstan_tests: $(PHPSTAN_BIN) .build/phpstan/tests
$(PHPSTAN) clear-result-cache --configuration=phpstan.tests.neon
$(PHPSTAN) --configuration=phpstan.tests.neon --memory-limit=-1
.PHONY: test
test: ## Runs all the tests
test: infection
.PHONY: phpunit
phpunit: ## Runs PHPUnit
phpunit: $(PHPUNIT_BIN) vendor
$(PHPUNIT)
.PHONY: phpunit_coverage_infection
phpunit_coverage_infection: ## Runs PHPUnit with code coverage for Infection
phpunit_coverage_infection: $(PHPUNIT_BIN) vendor
rm $(COVERAGE_INFECTION) || true
$(PHPUNIT_COVERAGE_INFECTION)
.PHONY: phpunit_coverage_html
phpunit_coverage_html: ## Runs PHPUnit with code coverage with HTML report
phpunit_coverage_html: $(PHPUNIT_BIN) vendor
$(PHPUNIT_COVERAGE_HTML)
@echo "You can check the report by opening the file \"$(COVERAGE_HTML)/index.html\"."
.PHONY: infection
infection: ## Runs infection
infection: $(INFECTION_BIN) vendor
$(INFECTION_WITH_INITIAL_TESTS)
.PHONY: _infection
_infection: $(INFECTION_BIN) $(COVERAGE_XML) $(COVERAGE_JUNIT) vendor
$(INFECTION)
.PHONY: e2e
e2e: vendor
./e2e/test-finders.sh
.PHONY: security
security: ## Runs the security check
security: composer_audit
.PHONY: composer_audit
composer_audit: ## Runs a security analysis with Composer
composer_audit:
composer audit
#
# Rules
#---------------------------------------------------------------------------
# Vendor does not depend on the composer.lock since the later is not tracked
# or committed.
vendor: composer.json
composer update --no-scripts
touch -c $@
touch -c $(PHPUNIT_BIN)
touch -c $(PHPSTAN_BIN)
$(PHPUNIT_BIN): vendor
touch -c $@
$(COVERAGE_XML): $(PHPUNIT_BIN) $(SRC_TESTS_FILES) phpunit.xml.dist
$(PHPUNIT_COVERAGE_INFECTION)
touch -c $@
touch -c $(COVERAGE_JUNIT)
$(COVERAGE_JUNIT): $(PHPUNIT_BIN) $(SRC_TESTS_FILES) phpunit.xml.dist
$(PHPUNIT_COVERAGE_INFECTION)
touch -c $@
touch -c $(COVERAGE_XML)
# PHP-CS-Fixer itself does not depend on the vendor but the config file yes
$(PHP_CS_FIXER_BIN): $(PHIVE_BIN) vendor
$(PHIVE) install php-cs-fixer
touch -c $@
$(INFECTION_BIN): $(PHIVE_BIN)
$(PHIVE) install infection
touch -c $@
$(PHIVE_BIN):
./.phive/install-phive
# Do not touch there: would mess up with the CI
$(PHPSTAN_BIN): vendor
touch -c $@
$(COMPOSER_NORMALIZE_BIN): $(PHIVE_BIN)
$(PHIVE) install composer-normalize
touch -c $@
.build/php-cs-fixer:
mkdir -p .build/php-cs-fixer/
.build/phpstan/src:
mkdir -p .build/phpstan/src
.build/phpstan/tests:
mkdir -p .build/phpstan/tests