forked from glpi-project/glpi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginsMakefile.mk
More file actions
134 lines (109 loc) · 5.25 KB
/
PluginsMakefile.mk
File metadata and controls
134 lines (109 loc) · 5.25 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
# 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)
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)
##
##This Makefile is used for *local development* only.
##Production or deployment should be handled following GLPI's documentation.
##
##—— 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 --config-dir=./tests/config $(PLUGIN_DIR) -u glpi --force
@$(CONSOLE) plugin:enable --config-dir=./tests/config $(PLUGIN_DIR)
.PHONY: test-setup
locales-extract: ## Extract locales
@$(PLUGIN) vendor/bin/extract-locales
.PHONY: locales-extract
locales-compile: ## Compile locales
@$(PLUGIN) vendor/bin/plugin-release --compile-mo
.PHONY: locales-compile
##—— Licenses —————————————————————————————————————————————————————————————————
license-headers-check: ## Verify that the license headers is present all files
@$(PLUGIN) vendor/bin/licence-headers-check
.PHONY: license-headers-check
license-headers-fix: ## Add the missing license headers in all files
@$(PLUGIN) vendor/bin/licence-headers-check --fix
.PHONY: license-headers-fix
##—— 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 ———————————————————————————————————————————————
verify: license-headers-check phpstan phpcsfixer-check phpunit ## Run all our lints/tests/static analysis
.PHONY: verify
phpunit: ## Run phpunits tests, example: make phpunit c='phpunit/functional/Glpi/MySpecificTest.php'
@$(eval c ?=)
@$(PLUGIN) php $(PHPUNIT_BIN) $(c)
.PHONY: phpunit
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
##—— Coding standards ——————————————————————————————————————————————————————————
phpcsfixer-check: ## Check for php coding standards issues
@$(PLUGIN) $(PHPCSFIXER_BIN) check --diff -vvv
.PHONY: phpcsfixer-check
phpcsfixer-fix: ## Fix php coding standards issues
@$(PLUGIN) $(PHPCSFIXER_BIN) fix
.PHONY: phpcsfixer-fix