-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathmakefile
More file actions
363 lines (323 loc) · 18.5 KB
/
Copy pathmakefile
File metadata and controls
363 lines (323 loc) · 18.5 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
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
#
# Makefile
#
.PHONY: help prod dev clean build fixtures pr release validate report phpmetrics build-js
.DEFAULT_GOAL := help
PLUGIN_VERSION = $(shell php -r 'echo json_decode(file_get_contents("composer.json"))->version;')
NODE_VERSION:=$(shell node -v)
# Tool set for "make validate". A literal comma cannot be written inside a make
# function call, so this is resolved here instead of inline in the recipe.
ifdef only
VALIDATE_TOOLS := $(only)
else
VALIDATE_TOOLS := sw-cli,phpstan
endif
ifndef nossl
EXPORT_CMD := export NODE_OPTIONS=--openssl-legacy-provider &&
else
EXPORT_CMD :=
endif
help:
@echo ""
@echo "PROJECT COMMANDS"
@echo "--------------------------------------------------------------------------------------------"
@printf "\033[33mInstallation:%-30s\033[0m %s\n"
@grep -E '^[a-zA-Z_-]+:.*?##1 .*$$' $(firstword $(MAKEFILE_LIST)) | awk 'BEGIN {FS = ":.*?##1 "}; {printf "\033[33m - %-30s\033[0m %s\n", $$1, $$2}'
@echo "--------------------------------------------------------------------------------------------"
@printf "\033[36mDevelopment:%-30s\033[0m %s\n"
@grep -E '^[a-zA-Z_-]+:.*?##2 .*$$' $(firstword $(MAKEFILE_LIST)) | awk 'BEGIN {FS = ":.*?##2 "}; {printf "\033[36m - %-30s\033[0m %s\n", $$1, $$2}'
@echo "--------------------------------------------------------------------------------------------"
@printf "\033[32mTests:%-30s\033[0m %s\n"
@grep -E '^[a-zA-Z_-]+:.*?##3 .*$$' $(firstword $(MAKEFILE_LIST)) | awk 'BEGIN {FS = ":.*?##3 "}; {printf "\033[32m - %-30s\033[0m %s\n", $$1, $$2}'
@echo "---------------------------------------------------------------------------------------------------------"
@printf "\033[35mDevOps:%-30s\033[0m %s\n"
@grep -E '^[a-zA-Z_-]+:.*?##4 .*$$' $(firstword $(MAKEFILE_LIST)) | awk 'BEGIN {FS = ":.*?##4 "}; {printf "\033[35m - %-30s\033[0m %s\n", $$1, $$2}'
# ------------------------------------------------------------------------------------------------------------
prod: ##1 Installs all production dependencies
# ----------------------------------------------------------------
composer validate
composer install --no-dev
cd src/Resources/app/administration && npm install --omit=dev
cd src/Resources/app/storefront && npm install --omit=dev
dev: ##1 Installs all dev dependencies
composer validate
composer install
cd dev && npm install
chmod a+x dev/node_modules/.bin/prettier
cd src/Resources/app/administration && npm install
cd src/Resources/app/storefront && npm install
clean: ##1 Cleans all dependencies and files
rm -rf vendor/*
# ------------------------------------------------------
rm -rf .reports | true
# ------------------------------------------------------
rm -rf ./dev/node_modules/*
rm -rf config-*
rm -rf ./src/Resources/app/administration/node_modules
rm -rf ./src/Resources/app/storefront/node_modules
# ------------------------------------------------------
rm -rf ./src/Resources/app/storefront/dist/storefront
build: ##2 Runs the Shopware theme and asset pipeline (JS assets must be built beforehand via shopware-cli).
rm -rf ../../../public/bundles/molliepayments/administration
cd ../../.. && php bin/console --no-debug theme:refresh
cd ../../.. && php bin/console --no-debug theme:compile
cd ../../.. && php bin/console --no-debug theme:refresh
cd ../../.. && php bin/console --no-debug assets:install
cd ../../.. && php bin/console --no-debug cache:clear
fixtures: ##2 Installs all available testing fixtures of the Mollie plugin
cd ../../.. && php bin/console --no-debug cache:clear
cd ../../.. && php bin/console --no-debug mollie:fixtures:load
pr: ##2 Prepares everything for a Pull Request
# -----------------------------------------------------------------
# FIXERS
@make csfix mode=fix -B
@make eslint mode=fix -B
@make stylelint mode=fix -B
@make prettier mode=fix -B
# -----------------------------------------------------------------
# VALIDATORS
@make phpcheck -B
@make phpmin -B
@make stan -B
@make phpunit -B
@make phpintegration -B
@make behat -B
@make vitest -B
@make typecheck -B
@make configcheck -B
@make phpunuhi -B
snippetexport: ##2 Exports all snippets
php vendor/bin/phpunuhi export --configuration=./config/.phpunuhi.xml --dir=./.phpunuhi
snippetimport: ##2 Imports the provided snippet set [set=xyz file=xz.csv]
php vendor/bin/phpunuhi import --configuration=./config/.phpunuhi.xml --set=$(set) --file=$(file) --intent=1
# ------------------------------------------------------------------------------------------------------------
phpcheck: ##3 Starts the PHP syntax checks
@find . -name '*.php' -not -path "./vendor/*" -not -path "./tests/*" | xargs -n 1 -P4 php -l
phpmin: ##3 Starts the PHP compatibility checks
echo "PHPCompatibility is in alpha right now and has issues with enums"
#@php vendor/bin/phpcs -p --standard=PHPCompatibility --extensions=php --runtime-set testVersion 8.2 ./src ./shopware
csfix: ##3 Starts the PHP CS Fixer
ifndef mode
php vendor/bin/php-cs-fixer fix --config=./config/.php_cs.php --dry-run --show-progress=dots --verbose
endif
ifeq ($(mode), fix)
php vendor/bin/php-cs-fixer fix --config=./config/.php_cs.php --show-progress=dots --verbose
endif
stan: ##3 Starts the PHPStan Analyser
cd ../../.. && php vendor/bin/phpstan analyse -c ./custom/plugins/MolliePayments/config/.phpstan.neon
phpunit: ##3 Starts all PHPUnit Tests
@php vendor/bin/phpunit --configuration=./config/phpunit.xml
phpintegration: ##3 Starts all PHPUnit Tests [groups=core to limit to a group]
@cd ../../.. && php vendor/bin/phpunit --configuration=./custom/plugins/MolliePayments/config/phpunit.integration.xml $(if $(groups),--group $(groups),)
report: ##3 Runs the unit tests with coverage and prints the line coverage of shopware/ and src/
# ----------------------------------------------------------------
# reset previous report output
rm -rf ./.reports/phpunit/coverage ./.reports/phpunit/clover.xml ../../../public/coverage
mkdir -p ./.reports/phpunit
# ----------------------------------------------------------------
# pcov records nothing outside pcov.directory, and the dockware image points that
# at the Shopware core - which is why every plugin file used to come back as 0%.
# Overriding XDEBUG_MODE instead would not help: php-code-coverage picks pcov
# over Xdebug whenever pcov is loaded (see Driver/Selector.php).
# XDEBUG_MODE is the fallback for an image without pcov: php-code-coverage picks pcov
# whenever it is loaded, so this has no effect on dockware, but without it a
# pcov-less environment would produce no report at all.
@XDEBUG_MODE=coverage php -d pcov.enabled=1 -d pcov.directory=$(CURDIR) \
vendor/bin/phpunit --configuration=./config/phpunit.xml \
--coverage-html ./.reports/phpunit/coverage \
--coverage-clover ./.reports/phpunit/clover.xml
# PHPUnit only warns when no coverage driver is available and still exits 0, which
# would leave the summary below reporting a truthful-looking 0.00%. Fail loudly instead.
@test -f ./.reports/phpunit/clover.xml || { echo ""; echo " No coverage was recorded - is pcov or Xdebug available?"; exit 1; }
@php -r '$$m = simplexml_load_file("./.reports/phpunit/clover.xml")->project->metrics; $$s = (int) $$m["statements"]; $$c = (int) $$m["coveredstatements"]; printf("%s Line coverage: %.2f%% (%d/%d statements)%s%s", PHP_EOL, $$s > 0 ? $$c / $$s * 100 : 0, $$c, $$s, PHP_EOL, PHP_EOL);'
# ----------------------------------------------------------------
# Publish the HTML report into the Shopware document root, so it can be opened
# in the browser at <shop-url>/coverage instead of only from the file system.
@cp -r ./.reports/phpunit/coverage ../../../public/coverage
@echo " HTML report at .reports/phpunit/coverage/index.html"
@echo " HTML report in the browser at <shop-url>/coverage"
@echo ""
# PHPMetrics is deliberately not part of composer.json: its dependencies clash with the
# other dev tools on the pipeline. It gets its own composer project under dev/tools
# instead, so the plugin's dependency tree stays untouched.
# Version 2.x and not the 3.0 release candidates: only 2.x still has --junit, which is
# what pairs the metrics with the test results.
PHPMETRICS_DIR := ./dev/tools/phpmetrics
PHPMETRICS_BIN := $(PHPMETRICS_DIR)/vendor/bin/phpmetrics
phpmetrics: ##3 Installs PHPMetrics and generates the metrics report from the unit test run
# ----------------------------------------------------------------
@test -f $(PHPMETRICS_BIN) || ( mkdir -p $(PHPMETRICS_DIR) \
&& composer require --working-dir=$(PHPMETRICS_DIR) --no-interaction phpmetrics/phpmetrics:^2.11 )
# ----------------------------------------------------------------
# reset previous report output
rm -rf ./.reports/phpmetrics ../../../public/phpmetrics
mkdir -p ./.reports/phpmetrics
# ----------------------------------------------------------------
# PHPMetrics reads the JUnit log to tell which classes the tests actually reach, so the
# unit tests have to run first. No coverage driver is involved: PHPMetrics cannot read
# Clover, use "make report" for line coverage.
# A non-zero exit code must not stop the report here: PHPUnit already returns 1 for the
# deprecations the Shopware core triggers, and the JUnit log is written either way.
@php vendor/bin/phpunit --configuration=./config/phpunit.xml --log-junit ./.reports/phpmetrics/junit.xml \
|| echo " The test run reported problems - see the JUnit page of the report."
# ----------------------------------------------------------------
# Analysed directories, exclusions and output paths live in config/.phpmetrics.json,
# so they stay in sync with the exclusions of config/phpunit.xml.
# PHPMetrics 2.x still writes dynamic properties, which buries the summary under
# deprecations on PHP 8.4+. They come from the tool, not from this plugin.
@php -d error_reporting="E_ALL & ~E_DEPRECATED" $(PHPMETRICS_BIN) --config=./config/.phpmetrics.json
# ----------------------------------------------------------------
# Publish the HTML report into the Shopware document root, so it can be opened
# in the browser at <shop-url>/phpmetrics instead of only from the file system.
@cp -r ./.reports/phpmetrics/html ../../../public/phpmetrics
@echo ""
@echo " HTML report at .reports/phpmetrics/html/index.html"
@echo " HTML report in the browser at <shop-url>/phpmetrics"
@echo ""
# Behat prints progress to stdout. CI passes allure=<dir> to additionally write Cucumber
# JSON, which Allure reads as-is; --out maps to --format by position, and `std` is Behat's
# word for stdout.
BEHAT_OUTPUT := --format=progress
ifdef allure
BEHAT_OUTPUT := --format=progress --format=cucumber_json --out=std --out=$(allure)
endif
# Scenarios tagged @mollie-broken assert behaviour that is correct for the plugin but that Mollie's
# own test mode currently gets wrong, so they would report our code as broken. They stay in the
# suite and out of the default run; check them with `make behat tags=@mollie-broken` to see whether
# Mollie has fixed it, and drop the tag when it passes.
BEHAT_TAGS := --tags='~@mollie-broken'
ifdef tags
BEHAT_TAGS := --tags='$(tags)'
endif
behat: ##3 Starts all Behat Tests [allure=<dir> writes results for the report, tags=<expr> selects scenarios]
cd ../../.. && php vendor/bin/behat --config ./custom/plugins/MolliePayments/config/behat.yaml $(BEHAT_OUTPUT) $(BEHAT_TAGS) --colors
insights: ##3 Starts the PHPInsights Analyser
@php vendor/bin/phpinsights analyse --no-interaction
vitest: ##3 Starts all Vitest tests
NODE_PATH=$(CURDIR)/dev/node_modules ./dev/node_modules/.bin/vitest -c ./config/vitest.config.ts
eslint: ##3 Starts the ESLinter
ifndef mode
NODE_PATH=$(CURDIR)/dev/node_modules ./dev/node_modules/.bin/eslint --config ./config/eslint.config.cjs ./src/Resources/app/administration
endif
ifeq ($(mode), fix)
NODE_PATH=$(CURDIR)/dev/node_modules ./dev/node_modules/.bin/eslint --config ./config/eslint.config.cjs ./src/Resources/app/administration --fix
endif
stylelint: ##3 Starts the Stylelinter
ifndef mode
NODE_PATH=$(CURDIR)/dev/node_modules ./dev/node_modules/.bin/stylelint --allow-empty-input ./src/Resources/app/**/*.scss --config=./config/.stylelintrc
endif
ifeq ($(mode), fix)
NODE_PATH=$(CURDIR)/dev/node_modules ./dev/node_modules/.bin/stylelint --allow-empty-input ./src/Resources/app/**/*.scss --fix --config=./config/.stylelintrc
endif
prettier: ##3 Starts the Prettier
ifndef mode
./dev/node_modules/.bin/prettier ./src/Resources/app/ --config=./config/.prettierrc --check
endif
ifeq ($(mode), fix)
./dev/node_modules/.bin/prettier ./src/Resources/app/ --config=./config/.prettierrc --write
endif
configcheck: ##3 Tests and verifies the plugin configuration file
cd ./tests/Custom && php verify-plugin-config.php
phpunuhi: ##3 Tests and verifies all plugin snippets
php vendor/bin/phpunuhi validate --configuration=./config/.phpunuhi.xml --report-format=junit --report-output=./.phpunuhi/junit.xml
# -------------------------------------------------------------------------------------------------
release: ##4 Builds a PROD version and creates a ZIP file in plugins/.build.
# Drop any leftover admin/asset build output so stale local builds (e.g. from `make run`)
# don't leak into the distribution ZIP — shopware-cli does not clean it before zipping.
rm -rf ./src/Resources/public/administration ./src/Resources/public/static/css ./src/Resources/public/static/js
cd .. && rm -rf ./.build/MolliePayments* && mkdir -p ./.build
# An empty node_modules makes shopware-cli skip npm install, producing a ZIP
# without admin assets (broken backend on customer update). Remove it so the
# asset build always installs fresh.
rm -rf ./src/Resources/app/administration/node_modules
rm -rf ./src/Resources/app/storefront/node_modules
docker run --rm \
--user "$(shell id -u):$(shell id -g)" \
-e HOME=/tmp \
-v "$(CURDIR)/..":/plugins \
-v "$(CURDIR)/config/.shopware-extension.yml":/plugins/MolliePayments/.shopware-extension.yml \
-w /plugins/.build \
ghcr.io/shopware/shopware-cli:latest \
extension zip /plugins/MolliePayments --disable-git
# The admin build writes into src/Resources/public and runs CleanWebpackPlugin with
# "static/**/*" (see the plugin branch of Shopware's administration webpack.config.js), so
# it deletes the storefront images that are served as bundles/molliepayments/static/*.png -
# the PayPal Express button and the POS terminal screens. Restore them here, then add them
# to the ZIP below; without this the shipped plugin shows broken images.
git checkout -- ./src/Resources/public/static
# STOREFRONT only: make the same ZIP work on Shopware 6.5.x as well.
# - 6.6/6.7 load the nested js/<name>/<name>.js
# - 6.5 loads the flat js/<name>.js
# The storefront is still built with esbuild (enable_es_build_for_storefront: true), so the
# bundle is byte-identical in both layouts (only the output path differs); we copy the nested
# file to the flat 6.5 path instead of running a second build.
# (The admin needs no such copy: the ~6.6.0 build emits a flat js/ plus a .vite manifest
# pointing to it, which both the webpack and the Vite admin load.)
cd ../.build && \
ZIP=$$(ls MolliePayments*.zip | head -1) && \
JS=MolliePayments/src/Resources/app/storefront/dist/storefront/js && \
unzip -o -q "$$ZIP" "$$JS/mollie-payments/mollie-payments.js" && \
cp "$$JS/mollie-payments/mollie-payments.js" "$$JS/mollie-payments.js" && \
zip -q "$$ZIP" "$$JS/mollie-payments.js" && \
STATIC=MolliePayments/src/Resources/public/static && \
mkdir -p "$$STATIC" && \
cp $(CURDIR)/src/Resources/public/static/*.png "$$STATIC/" && \
zip -q "$$ZIP" "$$STATIC"/*.png && \
rm -rf MolliePayments
@echo ""
@echo "CONGRATULATIONS"
@echo "ZIP file available at plugins/.build/"
typecheck: ##3 Starts the TypeScript type check (administration)
NODE_PATH=$(CURDIR)/dev/node_modules ./dev/node_modules/.bin/tsc --noEmit -p ./src/Resources/app/administration/tsconfig.json
validate: ##4 Runs the Shopware extension verifier against a release ZIP [zip=<path>, only=<tools>, reporter=<format>]
# This is the same tooling the Shopware Store runs on upload, so it catches
# rejections before we submit. It deliberately validates the ZIP and not the
# source directory: only the ZIP carries the mounted .shopware-extension.yml
# (and its validation.ignore list), and only the ZIP is free of the vendor
# directory - with a vendor/ present the verifier skips dependency resolution
# and every Shopware class would come back as "not found".
#
# Exit code is non-zero for error-level findings only; warnings are printed
# but do not fail the build, which mirrors what the Store does on upload.
#
# Default tool set:
# phpstan is what the Store shows as "Statische Code Analyse"
# sw-cli is a tool in the same --only list, not a separate mode - dropping
# it would also drop metadata.icon.size, packaging and snippet checks
# ESLint, Stylelint and the Twig linters are left out on purpose: they already
# run as their own jobs in step_review.yml. Override with only=<tools> or
# only=all to run everything.
@ZIP="$(zip)"; \
if [ -z "$$ZIP" ]; then ZIP=$$(ls ../.build/MolliePayments*.zip 2>/dev/null | head -1); fi; \
if [ ! -f "$$ZIP" ]; then \
echo "No release ZIP found. Run 'make release -B' first, or pass zip=<path>."; \
exit 1; \
fi; \
echo "Validating $$ZIP"; \
docker run --rm \
--user "$(shell id -u):$(shell id -g)" \
-e HOME=/tmp \
-v "$$(cd "$$(dirname "$$ZIP")" && pwd)":/build \
ghcr.io/shopware/shopware-cli:latest \
extension validate --full "/build/$$(basename "$$ZIP")" \
$(if $(filter-out all,$(VALIDATE_TOOLS)),--only "$(VALIDATE_TOOLS)",) \
$(if $(reporter),--reporter $(reporter),)
build-js:
rm -rf "./src/Resources/public/administration/assets"
rm -rf "./src/Resources/public/administration/.vite"
docker run --rm \
-v "./..:/plugins" \
-v "./config/.shopware-extension.yml:/plugins/MolliePayments/.shopware-extension.yml" \
ghcr.io/shopware/shopware-cli:latest \
extension build /plugins/MolliePayments
# Both builds delete committed files, so they are put back here.
# - The 6.6 admin webpack build writes into src/Resources/public and runs
# CleanWebpackPlugin with "static/**/*", which wipes the storefront images that are
# served as bundles/molliepayments/static/*.png. Only their sourcemap leftovers
# (static/css, static/js) stay behind, and those are git-ignored.
# - shopware-cli removes dist/storefront/js completely before writing the new bundle,
# which takes the flat 6.5 layout with it. We build for 6.6 (nested
# js/<name>/<name>.js) and copy that to the flat 6.5 path, same as "make release".
git checkout -- ./src/Resources/public/static
@JS_DIR="./src/Resources/app/storefront/dist/storefront/js"; \
cp "$$JS_DIR/mollie-payments/mollie-payments.js" "$$JS_DIR/mollie-payments.js"