-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathPluginsMakefile.mk
More file actions
193 lines (156 loc) · 7.3 KB
/
Copy pathPluginsMakefile.mk
File metadata and controls
193 lines (156 loc) · 7.3 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
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
# Create a file named "Makefile" in the root directory of your plugin and add
# the following line:
# include ../../PluginsMakefile.mk
# Shell to use
SHELL=bash
# Current plugin directory
PLUGIN_DIR = $(shell pwd | xargs basename)
# Check if composer and npm are used
USE_COMPOSER = $(shell test -f composer.json && echo true || echo false)
USE_NPM = $(shell test -f package.json && echo true || echo false)
# Docker commands
COMPOSE = docker compose
PHP = $(COMPOSE) exec app
PLUGIN = $(COMPOSE) exec -w /var/www/glpi/plugins/$(PLUGIN_DIR) app
DB = $(COMPOSE) exec db
CONSOLE = $(PHP) bin/console
# Check which binaries we need to use for some tools that can be suplied by
# either GLPI's core or the plugin itself.
PHPSTAN_BIN = $(shell test -f vendor/bin/phpstan && echo vendor/bin/phpstan || echo ../../vendor/bin/phpstan)
PHPUNIT_BIN = $(shell test -f vendor/bin/phpunit && echo vendor/bin/phpunit || echo ../../vendor/bin/phpunit)
RECTOR_BIN = $(shell test -f vendor/bin/rector && echo vendor/bin/rector || echo ../../vendor/bin/rector)
PSALM_BIN = $(shell test -f vendor/bin/psalm && echo vendor/bin/psalm || echo ../../vendor/bin/psalm)
PHPCSFIXER_BIN = $(shell test -f vendor/bin/php-cs-fixer && echo vendor/bin/php-cs-fixer || echo ../../vendor/bin/php-cs-fixer)
PARALLEL-LINT_BIN = $(shell test -f vendor/bin/parallel-lint && echo vendor/bin/parallel-lint || echo ../../vendor/bin/parallel-lint)
# Path to GLPI's core, where the root Makefile lives.
GLPI_DIR = ../..
##
##This Makefile is used for *local development* only.
##Production or deployment should be handled following GLPI's documentation.
##
# helper: $(call run_if_exists,<file>,<target>)
define run_if_exists
$(if $(wildcard $1), \
(echo -e "\033[36mRunning $2...\033[m" && $(MAKE) --no-print-directory $2), \
echo -e "\033[43mSkipping $2: $1 not found\033[m")
endef
# helper: $(call run_always,<target>)
define run_always
(echo -e "\033[36mRunning $1...\033[m" && $(MAKE) --no-print-directory $1)
endef
##—— General ———————————————————————————————————————————————————————————————————
.DEFAULT_GOAL := help
help: ## Show this help message
@grep -E -h '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-25s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'
.PHONY: help
bash: ## Start a shell inside the php container, in the plugin directory
@$(PLUGIN) bash
.PHONY: bash
##—— Plugin actions ————————————————————————————————————————————————————————————
install: ## Install the plugin
@$(CONSOLE) plugin:install $(PLUGIN_DIR) -u glpi
.PHONY: install
uninstall: ## Uninstall the plugin
@$(CONSOLE) plugin:uninstall $(PLUGIN_DIR)
.PHONY: uninstall
enable: ## Enable the plugin
@$(CONSOLE) plugin:enable $(PLUGIN_DIR)
.PHONY: enable
disable: ## Disable the plugin
@$(CONSOLE) plugin:disable $(PLUGIN_DIR)
.PHONY: disable
test-setup: ## Setup the plugin for tests
@$(CONSOLE) plugin:install --env=testing $(PLUGIN_DIR) -u glpi --force
@$(CONSOLE) plugin:enable --env=testing $(PLUGIN_DIR)
.PHONY: test-setup
test-uninstall: ## Uninstall the plugin in test env
@$(CONSOLE) plugin:uninstall --env=testing $(PLUGIN_DIR) -q
.PHONY: uninstall
test-e2e-setup: ## Setup the plugin for end-to-end tests
@$(CONSOLE) plugin:install --env=e2e_testing $(PLUGIN_DIR) -u glpi --force
@$(CONSOLE) plugin:enable --env=e2e_testing $(PLUGIN_DIR)
.PHONY: test-e2e-setup
locales-extract: ## Extract locales
@$(CONSOLE) tools:locales:extract --plugin=$(PLUGIN_DIR)
.PHONY: locales-extract
locales-compile: ## Compile locales
@$(CONSOLE) tools:locales:compile --plugin=$(PLUGIN_DIR)
.PHONY: locales-compile
plugin-release: ## Build and create plugin release based on HEAD ref, example: make plugin-release
@$(CONSOLE) tools:plugin:release --plugin=$(PLUGIN_DIR) --dest=/var/www/glpi/plugins/$(PLUGIN_DIR)/dist/glpi-$(PLUGIN_DIR)-$(shell date +%Y%m%d).tar.bz2
.PHONY: plugin-release
##—— Licenses —————————————————————————————————————————————————————————————————
license-headers-check: ## Verify that the license headers is present all files
@$(CONSOLE) tools:licence_headers_check --plugin=$(PLUGIN_DIR)
.PHONY: license-headers-check
license-headers: ## Add the missing license headers in all files
@$(CONSOLE) tools:licence_headers_check --fix --plugin=$(PLUGIN_DIR)
.PHONY: license-headers
##—— Dependencies ——————————————————————————————————————————————————————————————
vendor: ## Install dependencies
ifeq ($(USE_COMPOSER),true)
@$(PLUGIN) composer install
endif
ifeq ($(USE_NPM),true)
@$(PLUGIN) npm install --dev
endif
.PHONY: vendor
composer: ## Run a composer command, example: make composer c='require mypackage/package'
@$(eval c ?=)
@$(PLUGIN) composer $(c)
.PHONY: composer
npm: ## Run a npm command, example: make npm c='install mypackage/package'
@$(eval c ?=)
@$(PLUGIN) npm $(c)
.PHONY: npm
##—— Testing and static analysis ———————————————————————————————————————————————
test: ## Run all our lints/tests/static analysis
@$(call run_if_exists, tools/HEADER, license-headers)
@$(call run_always, parallel-lint)
@$(call run_if_exists, .php-cs-fixer.php, phpcsfixer)
@$(call run_if_exists, rector.php, rector)
@$(call run_if_exists, phpstan.neon, phpstan)
@$(call run_if_exists, psalm.xml, psalm)
@$(call run_if_exists, phpunit.xml, phpunit)
.PHONY: test
phpunit: ## Run phpunits tests, example: make phpunit c='tests/functional/Glpi/MySpecificTest.php'
@$(eval c ?=)
@$(PLUGIN) php $(PHPUNIT_BIN) $(c)
.PHONY: phpunit
playwright: ## Run the plugin's playwright tests, example: make playwright c='--headed'
@$(eval c ?=)
@$(MAKE) -C $(GLPI_DIR) playwright c='--project=plugin:$(PLUGIN_DIR) $(c)'
.PHONY: playwright
phpstan: ## Run phpstan
@$(eval c ?=)
@$(PLUGIN) php $(PHPSTAN_BIN) --memory-limit=1G $(c)
.PHONY: phpstan
parallel-lint: ## Check php syntax with parallel-lint
@$(eval c ?=.)
$(PLUGIN) php $(PARALLEL-LINT_BIN) \
--show-deprecated \
--colors \
--exclude ./lib/ \
--exclude ./node_modules/ \
--exclude ./vendor/ \
$(c)
.PHONY: parallel-lint
psalm: ## Run psalm analysis
@$(eval c ?=)
@$(PLUGIN) php $(PSALM_BIN) $(c)
.PHONY: psalm
rector-check: ## Run rector with dry run
@$(eval c ?=)
@$(PLUGIN) php $(RECTOR_BIN) --dry-run $(c)
.PHONY: rector
rector: ## Run rector
@$(eval c ?=)
@$(PLUGIN) php $(RECTOR_BIN) $(c)
.PHONY: rector
##—— Coding standards ——————————————————————————————————————————————————————————
phpcsfixer-check: ## Check for php coding standards issues
@$(PLUGIN) $(PHPCSFIXER_BIN) check --diff -vvv
.PHONY: phpcsfixer-check
phpcsfixer: ## Fix php coding standards issues
@$(PLUGIN) $(PHPCSFIXER_BIN) fix
.PHONY: phpcsfixer