-
Notifications
You must be signed in to change notification settings - Fork 19
/
Makefile
217 lines (164 loc) · 5.73 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
# See https://tech.davis-hansson.com/p/make/
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
.DEFAULT_GOAL := help
# Global variables
OS := $(shell uname)
PHPNOGC=php -d zend.enable_gc=0
CCYELLOW=\033[0;33m
CCEND=\033[0m
# PHP specific variables
SRC_TESTS_FILES=$(shell find src/ tests/ -type f)
COVERAGE_DIR = dist/coverage
COVERAGE_XML = $(COVERAGE_DIR)/xml
COVERAGE_JUNIT = $(COVERAGE_DIR)/phpunit.junit.xml
COVERAGE_HTML = $(COVERAGE_DIR)/html
TARGET_MSI = 100
PHP_CS_FIXER_BIN = vendor-bin/php-cs-fixer/vendor/friendsofphp/php-cs-fixer/php-cs-fixer
PHP_CS_FIXER = $(PHPNOGC) $(PHP_CS_FIXER_BIN)
PHPSTAN_BIN = vendor/phpstan/phpstan/phpstan
PHPSTAN = $(PHPSTAN_BIN)
PHPUNIT_BIN = vendor/bin/phpunit
PHPUNIT = $(PHPUNIT_BIN)
PHPUNIT_COVERAGE_INFECTION = XDEBUG_MODE=coverage $(PHPUNIT) --exclude-group autoreview --coverage-xml=$(COVERAGE_XML) --log-junit=$(COVERAGE_JUNIT)
PHPUNIT_COVERAGE_HTML = XDEBUG_MODE=coverage $(PHPUNIT) --coverage-html=$(COVERAGE_HTML)
INFECTION_BIN = vendor/bin/infection
INFECTION = $(INFECTION_BIN) --skip-initial-tests --coverage=$(COVERAGE_DIR) --only-covered --show-mutations --min-msi=$(TARGET_MSI) --min-covered-msi=$(TARGET_MSI) --ansi --threads=max
INFECTION_WITH_INITIAL_TESTS = $(INFECTION_BIN) --only-covered --show-mutations --min-msi=$(TARGET_MSI) --min-covered-msi=$(TARGET_MSI) --ansi --threads=max
RECTOR_BIN = vendor-bin/rector/vendor/bin/rector
RECTOR = $(RECTOR_BIN)
#
# Commands
#---------------------------------------------------------------------------
.PHONY: check
check: ## Runs all the checks
check: autoreview docs infection
.PHONY: help
help:
@echo "\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: autoreview
autoreview: ## Runs the Auto-Review checks
autoreview: cs validate-package phpstan rector_lint phpunit_autoreview
.PHONY: cs
cs: ## Fixes CS
cs: php_cs_fixer gitignore_sort composer_normalize
.PHONY: cs_lint
cs_lint: ## Lints CS
cs_lint: php_cs_fixer_lint composer_normalize_lint
.PHONY: php_cs_fixer
php_cs_fixer: $(PHP_CS_FIXER_BIN)
$(PHP_CS_FIXER) fix
.PHONY: php_cs_fixer_lint
php_cs_fixer_lint: $(PHP_CS_FIXER_BIN)
$(PHP_CS_FIXER) fix --dry-run
.PHONY: gitignore_sort
gitignore_sort:
LC_ALL=C sort -u .gitignore -o .gitignore
.PHONY: composer_normalize
composer_normalize: vendor
composer normalize
.PHONY: composer_normalize_lint
composer_normalize_lint: vendor
composer normalize --dry-run
.PHONY: test
test: ## Runs all the tests
test: validate-package phpstan phpunit
.PHONY: phpstan
phpstan: phpstan_src phpstan_tests
.PHONY: phpstan_src
phpstan_src: $(PHPSTAN_BIN) vendor
$(PHPSTAN) analyze --configuration phpstan-src.neon.dist
.PHONY: phpstan_tests
phpstan_tests: $(PHPSTAN_BIN) vendor
$(PHPSTAN) analyze --configuration phpstan-tests.neon.dist
.PHONY: phpunit
phpunit: $(PHPUNIT_BIN)
$(PHPUNIT) --testsuite=Tests --colors=always
.PHONY: phpunit_autoreview
phpunit_autoreview: $(PHPUNIT_BIN)
$(PHPUNIT) --testsuite=AutoReview --colors=always
.PHONY: phpunit_infection
phpunit_infection: $(PHPUNIT_BIN) vendor
$(PHPUNIT_COVERAGE_INFECTION)
.PHONY: phpunit_html
phpunit_html: ## Runs PHPUnit with code coverage with HTML report
phpunit_html: $(PHPUNIT_BIN) vendor
$(PHPUNIT_COVERAGE_HTML)
@echo "You can check the report by opening the file \"$(COVERAGE_HTML)/index.html\"."
.PHONY: infection
infection: $(INFECTION_BIN) vendor
$(INFECTION_WITH_INITIAL_TESTS) --initial-tests-php-options='-dzend_extension=xdebug.so'
.PHONY: _infection
_infection: $(INFECTION_BIN) $(COVERAGE_XML) $(COVERAGE_JUNIT) vendor
$(INFECTION)
.PHONY: validate-package
validate-package: vendor
composer validate --strict
.PHONY: clean
clean: ## Removes various temporary artifacts
clean: clear_cache clear_coverage clear_dist
@# Silently clean up old files
@rm -rf .php-cs-fixer.cache \
.php_cs.cache \
.phpunit.result.cache
.PHONY: clear_cache
clear_cache:
rm -rf tests/Integration/**/cache || true
.PHONY: clear_coverage
clear_coverage:
rm -rf $(COVERAGE_DIR) || true
.PHONY: clear_dist
clear_dist:
rm -rf dist || true
mkdir -p dist
touch dist/.gitkeep
.PHONY: rector
rector: $(RECTOR_BIN)
$(RECTOR)
.PHONY: rector_lint
rector_lint: $(RECTOR_BIN) dist
$(RECTOR) --dry-run
.PHONY: docs
docs: ## Runs the docs checks
docs: markdownlint lychee
.PHONY: markdownlint
markdownlint:
@echo "$(CCYELLOW)Ensure you have the nodejs & npm installed. For more information, check:$(CCEND)"
@# To keep in sync with .github/workflows/docs.yaml#check-links
npx markdownlint-cli2 "*.md|docs/**/*.md"
.PHONY: lychee
lychee:
@echo "$(CCYELLOW)Ensure you have the lychee command installed. For more information, check:$(CCEND)"
@echo "https://github.com/lycheeverse/lychee"
@# To keep in sync with .github/workflows/docs.yaml#check-links
lychee --verbose --no-progress '*.md' 'docs/**/*.md' --timeout=2
#
# Rules from files
#---------------------------------------------------------------------------
composer.lock: composer.json
composer install
touch -c $@
vendor: composer.lock
composer install
touch -c $@
$(PHP_CS_FIXER_BIN): vendor
composer bin php-cs-fixer install
touch -c $@
$(PHPSTAN_BIN): vendor
touch -c $@
$(PHPUNIT_BIN): vendor
touch -c $@
$(COVERAGE_XML): $(PHPUNIT_BIN) $(SRC_TESTS_FILES) phpunit.xml.dist
$(MAKE) phpunit_infection
touch -c $@
touch -c $(COVERAGE_JUNIT)
$(COVERAGE_JUNIT): $(PHPUNIT_BIN) $(SRC_TESTS_FILES) phpunit.xml.dist
$(MAKE) phpunit_infection
touch -c $@
touch -c $(COVERAGE_XML)
$(INFECTION_BIN): vendor
touch -c $@
$(RECTOR_BIN): vendor
composer bin rector install
touch -c $@