-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
152 lines (127 loc) · 7.54 KB
/
Copy pathMakefile
File metadata and controls
152 lines (127 loc) · 7.54 KB
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
.DEFAULT_GOAL := help
MAKEFLAGS += --no-print-directory
projectName = Eonx Easy Quality
enableNotification = yes
.ONESHELL:
.SILENT:
SHELL = /bin/bash
define handleError
echo ''
echo '$(shell tput setab 1)$(shell echo $@ | sed 's/./ /g') $(shell tput sgr0)'
echo '$(shell tput setab 1) $(shell tput setaf 7)[ERROR] The recipe $(shell tput bold)$@$(shell tput sgr0)$(shell tput setab 1)$(shell tput setaf 7) was executed with errors. Please check the output above. $(shell tput sgr0)'
echo '$(shell tput setab 1)$(shell echo $@ | sed 's/./ /g') $(shell tput sgr0)'
echo ''
if [ -n "${EONX_MAKEFILE_ENABLE_NOTIFICATION}" ] && [[ "$(enableNotification)" == "yes" ]]; then
notify-send -u critical "$(projectName)" "[ERROR] The recipe <b>$@</b> was executed with errors. Please check the output." &>/dev/null || osascript -e 'display notification "[ERROR] The recipe [$@] was executed with errors. Please check the output." with title "$(projectName)" sound name "Submarine"' &>/dev/null
fi
# Exit with non zero exit code to allow handling the error
exit 1
endef
define handleSuccess
echo ''
echo '$(shell tput setab 2)$(shell echo $@ | sed 's/./ /g') $(shell tput sgr0)'
echo '$(shell tput setab 2) $(shell tput setaf 0)[OK] The recipe $(shell tput bold)$@$(shell tput sgr0)$(shell tput setab 2)$(shell tput setaf 0) was executed successfully. Cheers! $(shell tput sgr0)'
echo '$(shell tput setab 2)$(shell echo $@ | sed 's/./ /g') $(shell tput sgr0)'
echo ''
if [ -n "${EONX_MAKEFILE_ENABLE_NOTIFICATION}" ] && [[ "$(enableNotification)" == "yes" ]]; then
notify-send "$(projectName)" "[OK] The recipe <b>$@</b> was executed successfully. Cheers" &>/dev/null || osascript -e 'display notification "[OK] The recipe [$@] was executed successfully. Cheers" with title "$(projectName)" sound name "Submarine"' &>/dev/null
fi
endef
define runCommand
if $1; then
$(call handleSuccess)
else
$(call handleError)
fi
endef
check-all: ## Check codebase with all checkers
$(call runCommand,$(MAKE) --jobs=2 --keep-going --output-sync \
check-composer enableNotification="no"\
check-ecs enableNotification="no"\
check-phpstan enableNotification="no"\
check-rector enableNotification="no"\
check-security enableNotification="no")
check-composer: ## Validate composer.json
$(call runCommand,composer validate --no-check-publish)
check-ecs: ## Check code style with ECS
$(call runCommand,php -d memory_limit=2048M vendor/bin/ecs check --clear-cache --config=quality/ecs.php)
check-phpstan: ## Check code with PHPStan
$(call runCommand,vendor/bin/phpstan analyse --ansi --memory-limit=2048M --configuration=quality/phpstan.neon)
check-rector: ## Check code with Rector
$(call runCommand,vendor/bin/rector --dry-run --clear-cache --config=quality/rector.php)
check-security: ## Check packages for known vulnerabilities
$(call runCommand,composer audit)
fix-all: ## Fix all issues
$(call runCommand,$(MAKE) --jobs=2 --keep-going --output-sync \
fix-ecs enableNotification="no"\
fix-rector enableNotification="no")
fix-ecs: ## Fix issues found by ECS
$(call runCommand,php -d memory_limit=2048M vendor/bin/ecs check --fix --config=quality/ecs.php)
fix-rector: ## Fix issues found by Rector
$(call runCommand,vendor/bin/rector --clear-cache --config=quality/rector.php)
test: ## Run all test suites
$(call runCommand,$(MAKE) --jobs=2 --keep-going --output-sync \
test-output enableNotification="no"\
test-phpstan enableNotification="no"\
test-rector enableNotification="no"\
test-sniffs enableNotification="no")
test-output: ## Run Output module tests
$(call runCommand,vendor/bin/phpunit --testsuite Output)
test-phpstan: ## Run PHPStan module tests
$(call runCommand,vendor/bin/phpunit --testsuite PHPStan)
test-rector: ## Run Rector module tests
$(call runCommand,vendor/bin/phpunit --testsuite Rector)
test-sniffs: ## Run Sniffs module tests
$(call runCommand,vendor/bin/phpunit --testsuite Sniffs)
help:
echo ' $(shell tput setaf 6)██████████████████████████████████████████████████████████████████████████████████████████████$(shell tput sgr0)'
echo ' $(shell tput setaf 6)█$(shell tput sgr0) $(shell tput setaf 6)█$(shell tput sgr0)'
echo ' $(shell tput setaf 6)█ $(shell tput setaf 3)E O N X E A S Y Q U A L I T Y$(shell tput sgr0) $(shell tput setaf 6)█$(shell tput sgr0)'
echo ' $(shell tput setaf 6)█$(shell tput sgr0) $(shell tput setaf 6)█$(shell tput sgr0)'
echo ' $(shell tput setaf 6)██████████████████████████████████████████████████████████████████████████████████████████████$(shell tput sgr0)'
echo ''
echo ' It is possible to use shortcuts for recipe, like $(shell tput setaf 3)make c-a$(shell tput sgr0) or $(shell tput setaf 3)make c:a$(shell tput sgr0).'
echo " Escape commands with options using double or single quotes, like $(shell tput setaf 3)make e:m 'cl -v'$(shell tput sgr0) or $(shell tput setaf 3)make e:m \"cl -v\"$(shell tput sgr0)."
echo ''
grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| sed -n 's/^\(.*\):.*##\(.*\)/$(shell tput setaf 2) \1$(shell tput sgr0) :::\2/p' \
| sed 's/\[\#yellow\]/$(shell tput setaf 3)/g' \
| sed 's/\[\#black\]/$(shell tput sgr0)/g' \
| sort \
| column -t -s ':::'
.DEFAULT:
if [[ "$(stopExecution)" == "" ]]; then
$(eval normalizedShortcut := $(shell echo $@ | sed 's/:/-/g' | sed 's/-/[a-zA-Z0-9_]*-/g' | sed "s/\(.*\)/' \1.*'/"))
$(eval foundRecipes := $(shell grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sed -n 's/^\(.*\):.*##\(.*\)/ \1/p' | grep -E $(normalizedShortcut)))
$(eval foundRecipesCount := $(shell echo $(foundRecipes) | tr ' ' '\n' | wc -l))
if [[ "$(foundRecipesCount)" == "1" ]]; then
if [[ "$(foundRecipes)" == "" ]]; then
echo '$(shell tput setaf 3)Recipe$(shell tput sgr0) $(shell tput setaf 2)$@$(shell tput sgr0) $(shell tput setaf 3)is not found.$(shell tput sgr0)'
echo ''
echo 'Showing help.'
echo ''
$(MAKE) help
else
echo 'Executing recipe $(shell tput setaf 2)$(foundRecipes)$(shell tput sgr0)'
echo ''
$(eval parsedCommand := $(shell echo $(MAKECMDGOALS) | sed 's/[a-zA-Z0-9_:-]* //'))
$(MAKE) $(foundRecipes)
if [[ "$(parsedCommand)" != "$(MAKECMDGOALS)" ]]; then
$(MAKE) $(parsedCommand)
fi
fi
else
echo '$(shell tput setaf 3)Multiple recipes are found.$(shell tput sgr0)'
echo ''
echo 'Please use one of the following recipes:'
grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| sed -n 's/^\(.*\):.*##\(.*\)/$(shell tput setaf 2) \1 :::$(shell tput sgr0)\2/p' \
| sed 's/\[\#yellow\]/$(shell tput setaf 3)/g' \
| sed 's/\[\#black\]/$(shell tput sgr0)/g' \
| grep -E $(normalizedShortcut) \
| sort \
| column -t -s ':::'
# Exit with non zero exit code to allow handling the error
exit 1
fi
fi