@@ -3,56 +3,88 @@ SHELL=bash
3
3
4
4
.PHONY : *
5
5
6
- DOCKER_CGROUP: =$(shell cat /proc/1/cgroup | grep docker | wc -l)
7
-
8
- ifneq ("$(wildcard /.dockerenv) ","")
6
+ COMPOSER_SHOW_EXTENSION_LIST =$(shell composer show -t | grep -o "\-\-\(ext-\) .\+" | sort | uniq | cut -d- -f4- | tr -d '\n' | grep . | sed '/^$$/d' | xargs | sed -e 's/ /, /g' | tr -cd '[:alnum:],' | sed 's/.$$//')
7
+ SLIM_DOCKER_IMAGE =$(shell php -r 'echo count(array_intersect(["gd", "vips"], explode(",", "${COMPOSER_SHOW_EXTENSION_LIST}") )) > 0 ? "" : "-slim";')
8
+ PHP_VERSION: =$(shell docker run --rm -v "`pwd`:`pwd`" jess/jq jq -r -c '.config.platform.php' "`pwd`/composer.json" | php -r "echo str_replace('|', '.', explode('.', implode('|', explode('.', stream_get_contents(STDIN) , 2)), 2)[0]);")
9
+ CONTAINER_NAME =$(shell echo "ghcr.io/wyrihaximusnet/php:${PHP_VERSION}-nts-alpine${SLIM_DOCKER_IMAGE}-dev")
10
+ COMPOSER_CACHE_DIR =$(shell composer config --global cache-dir -q || echo ${HOME}/.composer-php/cache)
11
+ COMPOSER_CONTAINER_CACHE_DIR =$(shell docker run --rm -it ${CONTAINER_NAME} composer config --global cache-dir -q || echo ${HOME}/.composer-php/cache)
12
+
13
+ ifneq ("$(wildcard /.you-are-in-a-wyrihaximus.net-php-docker-image) ","")
9
14
IN_DOCKER =TRUE
10
- else ifneq ("$(DOCKER_CGROUP)","0")
11
- IN_DOCKER=TRUE
12
15
else
13
- IN_DOCKER =FALSe
16
+ IN_DOCKER =FALSE
14
17
endif
15
18
16
19
ifeq ("$(IN_DOCKER ) ","TRUE")
17
- DOCKER_RUN=
20
+ DOCKER_RUN: =
18
21
else
19
- DOCKER_RUN=docker run --rm -it \
22
+ DOCKER_RUN: =docker run --rm -it \
20
23
-v "`pwd`:`pwd`" \
24
+ -v "${COMPOSER_CACHE_DIR}:${COMPOSER_CONTAINER_CACHE_DIR}" \
21
25
-w "`pwd`" \
22
- "wyrihaximusnet/php:7.4-nts-alpine3.12-dev"
26
+ ${CONTAINER_NAME}
23
27
endif
24
28
25
- all : lint cs-fix cs stan psalm unit infection composer-require-checker composer-unused backward-compatibility-check
29
+ ifneq (,$(findstring icrosoft,$(shell cat /proc/version) ) )
30
+ THREADS =1
31
+ else
32
+ THREADS =$(shell nproc)
33
+ endif
26
34
27
- lint :
35
+ all : # # Runs everything ####
36
+ @grep -E ' ^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST ) | grep -v " ####" | awk ' BEGIN {FS = ":.*?## "}; {printf "%s\n", $$1}' | xargs --open-tty $(MAKE )
37
+
38
+ syntax-php : # # Lint PHP syntax
28
39
$(DOCKER_RUN ) vendor/bin/parallel-lint --exclude vendor .
29
40
30
- cs :
31
- $(DOCKER_RUN ) vendor/bin/phpcs --parallel=$(shell nproc)
41
+ cs-fix : # # Fix any automatically fixable code style issues ###
42
+ $(DOCKER_RUN ) vendor/bin/phpcbf --parallel=$(THREADS ) --cache=./var/.phpcs.cache.json --standard=./etc/qa/phpcs.xml || $(DOCKER_RUN ) vendor/bin/phpcbf --parallel=$(THREADS ) --cache=./var/.phpcs.cache.json --standard=./etc/qa/phpcs.xml || $(DOCKER_RUN ) vendor/bin/phpcbf --parallel=$(THREADS ) --cache=./var/.phpcs.cache.json --standard=./etc/qa/phpcs.xml -vvvv
43
+
44
+ cs : # # Check the code for code style issues
45
+ $(DOCKER_RUN ) vendor/bin/phpcs --parallel=$(THREADS ) --cache=./var/.phpcs.cache.json --standard=./etc/qa/phpcs.xml
46
+
47
+ stan : # # Run static analysis (PHPStan)
48
+ $(DOCKER_RUN ) vendor/bin/phpstan analyse src tests --level max --ansi -c ./etc/qa/phpstan.neon
49
+
50
+ unit-testing : # # Run tests
51
+ $(DOCKER_RUN ) vendor/bin/phpunit --colors=always -c ./etc/qa/phpunit.xml --coverage-text --coverage-html ./var/tests-unit-coverage-html --coverage-clover ./var/tests-unit-clover-coverage.xml
52
+ $(DOCKER_RUN ) test -n " $( COVERALLS_REPO_TOKEN) " && test -n " $( COVERALLS_RUN_LOCALLY) " && test -f ./var/tests-unit-clover-coverage.xml && vendor/bin/php-coveralls -v --coverage_clover ./build/logs/clover.xml --json_path ./var/tests-unit-clover-coverage-upload.json || true
53
+
54
+ unit-testing-raw : # # Run tests ####
55
+ php vendor/phpunit/phpunit/phpunit --colors=always -c ./etc/qa/phpunit.xml --coverage-text --coverage-html ./var/tests-unit-coverage-html --coverage-clover ./var/tests-unit-clover-coverage.xml
56
+ test -n " $( COVERALLS_REPO_TOKEN) " && test -n " $( COVERALLS_RUN_LOCALLY) " && test -f ./var/tests-unit-clover-coverage.xml && ./vendor/bin/php-coveralls -v --coverage_clover ./build/logs/clover.xml --json_path ./var/tests-unit-clover-coverage-upload.json || true
57
+
58
+ composer-require-checker : # # Ensure we require every package used in this package directly
59
+ $(DOCKER_RUN ) vendor/bin/composer-require-checker --ignore-parse-errors --ansi -vvv --config-file=./etc/qa/composer-require-checker.json
60
+
61
+ composer-unused : # # Ensure we don't require any package we don't use in this package directly
62
+ $(DOCKER_RUN ) vendor/bin/composer-unused --ansi --configuration=./etc/qa/composer-unused.php
32
63
33
- cs-fix :
34
- $(DOCKER_RUN ) vendor/bin/phpcbf --parallel= $( shell nproc)
64
+ composer-install : # # Install dependencies
65
+ $(DOCKER_RUN ) composer install --no-progress --ansi --no-interaction --prefer-dist -o
35
66
36
- stan :
37
- $(DOCKER_RUN ) vendor/bin/phpstan analyse src tests --level max --ansi -c phpstan.neon
67
+ backward-compatibility-check : # # Check code for backwards incompatible changes
68
+ $(MAKE ) backward-compatibility-check-raw || true
38
69
39
- psalm :
40
- $(DOCKER_RUN ) vendor/bin/psalm --threads= $( shell nproc) --shepherd --stats
70
+ backward-compatibility-check-raw : # # Check code for backwards incompatible changes, doesn't ignore the failure ###
71
+ $(DOCKER_RUN ) vendor/bin/roave-backward-compatibility-check
41
72
42
- unit :
43
- $(DOCKER_RUN ) vendor/bin/phpunit --colors=always -c phpunit.xml.dist --coverage-text --coverage-html covHtml --coverage-clover ./build/logs/clover.xml
73
+ shell : # # Provides Shell access in the expected environment ####
74
+ $(DOCKER_RUN ) bash
44
75
45
- unit-ci : unit
46
- if [ -f ./build/logs/clover.xml ] ; then wget https://scrutinizer-ci.com/ocular.phar && sleep 3 && php ocular.phar code-coverage:upload --format=php-clover ./build/logs/clover.xml ; fi
76
+ install : # # Install dependencies ####
77
+ $( DOCKER_RUN ) composer install
47
78
48
- infection :
49
- $(DOCKER_RUN ) vendor/bin/infection --ansi --min-msi=100 --min-covered-msi=100 --threads= $( shell nproc)
79
+ update : # # Update dependencies ####
80
+ $(DOCKER_RUN ) composer update -W
50
81
51
- composer-require-checker :
52
- $(DOCKER_RUN ) vendor/bin/ composer-require-checker --ignore-parse-errors --ansi -vvv --config-file=composer-require-checker.json
82
+ outdated : # # Show outdated dependencies ####
83
+ $(DOCKER_RUN ) composer outdated
53
84
54
- composer-unused :
55
- $( DOCKER_RUN ) composer unused --ansi
85
+ task-list-ci : # # CI: Generate a JSON array of jobs to run, matches the commands run when running `make (|all)` ####
86
+ @grep -E ' ^[a-zA-Z0-9_-]+:.*?## .*$$ ' $( MAKEFILE_LIST ) | grep -v " ### " | sort | awk ' BEGIN {FS = ":.*?## "}; {printf "%s\n", $$1} ' | jq --raw-input --slurp -c ' split("\n")| .[0:-1] '
56
87
57
- backward-compatibility-check :
58
- $(DOCKER_RUN ) vendor/bin/roave-backward-compatibility-check || true
88
+ help : # # Show this help ####
89
+ @printf " \033[33mUsage:\033[0m\n make [target]\n\n\033[33mTargets:\033[0m\n"
90
+ @grep -E ' ^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST ) | sort | awk ' BEGIN {FS = ":.*?## "}; {printf " \033[32m%-32s\033[0m %s\n", $$1, $$2}' | tr -d ' #'
0 commit comments