Skip to content

Commit

Permalink
fix: pass exact PHP version to Psalm (#61)
Browse files Browse the repository at this point in the history
* fix: pass exact PHP version to Psalm

* file prefix macro

* block start / end macros

* Monorepo support
  • Loading branch information
dkarlovi authored Oct 22, 2022
1 parent d9ad406 commit 03df5c2
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 32 deletions.
4 changes: 4 additions & 0 deletions resources/Common/Platform/Linux/default.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ help: ## Prints this help

OS_CPUS:=$(shell nproc)

define file_prefix
$(shell test -f ${2}${1} && echo -n ${2}${1} || echo ${1})
endef

define permissions
setfacl -dRm m:rwX $(1)
setfacl -Rm m:rwX $(1)
Expand Down
13 changes: 13 additions & 0 deletions resources/Common/default.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ ifndef SIGWIN_INFRA_ROOT
$(error SIGWIN_INFRA_ROOT must be defined before loading Common/default.mk)
endif

define block_start
endef
define block_end
endef
ifdef GITHUB_ACTIONS
define block_start
echo ::group::$(1)
endef
define block_end
echo ::endgroup::
endef
endif

SHELL := sh
OS_FAMILY :=
ifeq ($(OS),Windows_NT)
Expand Down
10 changes: 10 additions & 0 deletions resources/Monorepo/common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ifndef MONOREPO_ROOT
$(error MONOREPO_ROOT must be defined before loading Monorepo/common.mk)
endif

ifndef MONOREPO_DIRS
$(error MONOREPO_DIRS must be defined before loading Monorepo/common.mk)
endif

all/%: %
$(foreach DIR,${MONOREPO_DIRS},MONOREPO_ROOT=${CURDIR} $(MAKE) -C ${CURDIR}/${DIR} -f ${CURDIR}/Makefile $<;)
49 changes: 17 additions & 32 deletions resources/PHP/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,6 @@ ifndef PHPQA_DOCKER_COMMAND
PHPQA_DOCKER_COMMAND=docker run --init --interactive ${TTY} --rm --env "COMPOSER_CACHE_DIR=/composer/cache" --user "$(shell id -u):$(shell id -g)" --volume "$(shell pwd)/var/phpqa:/cache" --volume "$(shell pwd):/project" --volume "${HOME}/.composer:/composer" --workdir /project ${PHPQA_DOCKER_IMAGE}
endif

PHPSTAN_OUTPUT=
PSALM_OUTPUT=
define start
endef
define end
endef
ifdef GITHUB_ACTIONS
define start
echo ::group::$(1)
endef
define end
echo ::endgroup::
endef
PHPSTAN_OUTPUT=--error-format=github
PSALM_OUTPUT=--output-format=github
endif

sh/php: | ${HOME}/.composer var/phpqa composer.lock ## Run PHP shell
sh -c "${PHPQA_DOCKER_COMMAND} sh"

Expand All @@ -52,37 +35,39 @@ composer/validate: | ${HOME}/.composer var/phpqa composer.lock
composer/normalize: | ${HOME}/.composer var/phpqa composer.lock
sh -c "${PHPQA_DOCKER_COMMAND} composer normalize --no-interaction --no-update-lock"
analyze/composer: | ${HOME}/.composer var/phpqa composer.lock
$(call block_start,$@)
sh -c "${PHPQA_DOCKER_COMMAND} composer normalize --no-interaction --no-update-lock --dry-run"
$(call block_end)

cs: | ${HOME}/.composer var/phpqa composer.lock
sh -c "${PHPQA_DOCKER_COMMAND} php-cs-fixer fix --diff -vvv"
analyze/cs: | ${HOME}/.composer var/phpqa composer.lock
$(call start,PHP CS Fixer)
$(call block_start,$@)
sh -c "${PHPQA_DOCKER_COMMAND} php-cs-fixer fix --dry-run --diff -vvv"
$(call end)
$(call block_end)

analyze/phpstan: | ${HOME}/.composer var/phpqa composer.lock
$(call start,PHPStan)
sh -c "${PHPQA_DOCKER_COMMAND} phpstan analyse ${PHPSTAN_OUTPUT}"
$(call end)
$(call block_start,$@)
sh -c "${PHPQA_DOCKER_COMMAND} phpstan analyse --configuration $(call file_prefix,phpstan.neon.dist,$(PHP_VERSION)-)"
$(call block_end)

analyze/psalm: | ${HOME}/.composer var/phpqa composer.lock
$(call start,Psalm)
sh -c "${PHPQA_DOCKER_COMMAND} psalm ${PSALM_OUTPUT}"
$(call end)
$(call block_start,$@)
sh -c "${PHPQA_DOCKER_COMMAND} psalm --php-version=${PHP_VERSION} --config $(call file_prefix,psalm.xml.dist,$(PHP_VERSION)-)"
$(call block_end)

test/phpunit:
$(call start,PHPUnit)
test/phpunit: | ${HOME}/.composer var/phpqa composer.lock
$(call block_start,$@)
sh -c "${PHPQA_DOCKER_COMMAND} vendor/bin/phpunit --verbose"
$(call end)
$(call block_end)
test/phpunit-coverage: | ${HOME}/.composer var/phpqa composer.lock
$(call start,PHPUnit)
$(call block_start,$@)
sh -c "${PHPQA_DOCKER_COMMAND} php -d pcov.enabled=1 vendor/bin/phpunit --verbose --coverage-text --log-junit=var/phpqa/phpunit/junit.xml --coverage-xml var/phpqa/phpunit/coverage-xml/"
$(call end)
$(call block_end)
test/infection: test/phpunit-coverage
$(call start,Infection)
$(call block_start,$@)
sh -c "${PHPQA_DOCKER_COMMAND} infection run --verbose --show-mutations --no-interaction --only-covered --coverage var/phpqa/phpunit/ --threads ${OS_CPUS}"
$(call end)
$(call block_end)

${HOME}/.composer:
mkdir -p ${HOME}/.composer
Expand Down
9 changes: 9 additions & 0 deletions resources/PHP/library_monorepo.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ifndef SIGWIN_INFRA_ROOT
SIGWIN_INFRA_ROOT := $(dir $(abspath $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))))
endif
include ${SIGWIN_INFRA_ROOT}/PHP/common.mk
include ${SIGWIN_INFRA_ROOT}/Monorepo/common.mk

dist: cs all/composer/normalize all/analyze/phpstan all/analyze/psalm test ## Prepare the codebase for commit
analyze: analyze/cs all/analyze/composer all/analyze/phpstan all/analyze/psalm ## Analyze the codebase
test: all/test/infection ## Test the codebase

0 comments on commit 03df5c2

Please sign in to comment.