diff --git a/Makefile b/Makefile index a5ec642..681908b 100644 --- a/Makefile +++ b/Makefile @@ -78,6 +78,7 @@ include $(_MAKEFILE_DIR)makefiles/PHPUnit.mk include $(_MAKEFILE_DIR)makefiles/Psalm.mk include $(_MAKEFILE_DIR)makefiles/Rector.mk include $(_MAKEFILE_DIR)makefiles/Infection.mk +include $(_MAKEFILE_DIR)makefiles/StructArmed.mk include $(_MAKEFILE_DIR)makefiles/Utilities.mk # Include the Tools fragment after all other tooling so that bump and update of stand-alone tools collects all necessary targets diff --git a/README.md b/README.md index 4e51b42..6ab994a 100644 --- a/README.md +++ b/README.md @@ -32,12 +32,8 @@ Other host machine dependencies include: ### Out-of-the-box `Makefile` -Create a Makefile in the project root with the following contents, after installing this dependency via composer: - -```makefile -# ./Makefile -include vendor/laminas/internal-tooling/Makefile -``` +After copying the shipped `Makefile` template, it will need a few minor adjustments. +These are documented in the template. Now, running `make` should list a number of useful targets for general QA work on Laminas and Mezzio libraries. @@ -96,6 +92,33 @@ When rector is installed to `./tools/rector` - `make rector` (Run rector with --dry-run) - `make rector-fix` +### Infection Targets + +When infection is installed to `./tools/infection` + +- `make infection` + +### StructArmed Targets + +When [StructArmed](https://boundwize.github.io/structarmed/) is installed to `./tools/structarmed` + +- `make structarmed` Runs the analysis +- `make structarmed-fix` Runs auto fixers +- `make structarmed-clear` Clears the cache + +### Dependency Management Targets + +- `make install` - Often not required because this lib is distributed via composer itself +- `make update` - Runs composer update with the project docker image +- `make bump-dev` - Bumps _development_ dependencies +- `make outdated` - Run `composer outdated` + +For tools that are installed in subdirectories, it's a pain to cd to each one and run composer for each tool, therefore these targets operate on all installed tools: + +- `make install-tools` +- `make update-tools` +- `make bump-tools` + ## Migrations Migrations represent small units of automation for common or one-off maintenance tasks for Laminas Repos. @@ -127,7 +150,26 @@ Install rector into `./tools/rector` make install-rector ``` -For more information about this migration [see the README](migrations/InstallStandaloneRector/README.md). +### Infection Installation + +Install [infection](https://infection.github.io/) into `./tools/infection` + +```bash +make install-infection +``` + +By default, the Min MSI is not configured, so tweaking the configuration file may be necessary. +Additionally, depending on what version of PHPUnit is installed, some settings may need adjusting for PHPUnit such as `executionOrder` + +### StructArmed Installation + +Install [StructArmed](https://boundwize.github.io/structarmed/) into `./tools/structarmed` + +```bash +make install-structarmed +``` + +Once installed, further [configuration](https://boundwize.github.io/structarmed/quick-start/) will be required. ### Psalm Removal diff --git a/mago.toml b/mago.toml index afbcaf6..50954bc 100644 --- a/mago.toml +++ b/mago.toml @@ -11,6 +11,7 @@ workspace = "." paths = ["migrations/"] excludes = [ "migrations/*/templates/rector.php", + "migrations/*/structarmed.php", ] [analyzer] diff --git a/makefiles/StructArmed.mk b/makefiles/StructArmed.mk new file mode 100644 index 0000000..01d2308 --- /dev/null +++ b/makefiles/StructArmed.mk @@ -0,0 +1,57 @@ +STRUCT_ARMED_DIRECTORY ?= $(PROJECT_DIR)tools/structarmed +HAS_STRUCT_ARMED := $(strip $(shell if [ -d $(STRUCT_ARMED_DIRECTORY) ]; then echo TRUE; fi)) + +ifeq ("$(HAS_STRUCT_ARMED)", "TRUE") + +BUMP_TOOLS_TARGETS += structarmed-bump +UPDATE_TOOLS_TARGETS += structarmed-update +INSTALL_TOOLS_TARGETS += structarmed-install + +HELP += $(call MK_HELP,'structarmed','Check the codebase with StructArmed') +QA_TARGETS += structarmed +CLEAN_TARGETS += structarmed-clear + +structarmed: + @$(DOCKER_RUN) $(DOCKER_IMAGE_NAME) \ + $(STRUCT_ARMED_DIRECTORY)/vendor/bin/structarmed \ + --config $(STRUCT_ARMED_DIRECTORY)/structarmed.php \ + analyze +.PHONY: structarmed + +HELP += $(call MK_HELP,'structarmed-fix','Run automatic fixes provided by StructArmed') +structarmed-fix: + @$(DOCKER_RUN) $(DOCKER_IMAGE_NAME) \ + $(STRUCT_ARMED_DIRECTORY)/vendor/bin/structarmed \ + --config $(STRUCT_ARMED_DIRECTORY)/structarmed.php \ + analyze --fix +.PHONY: structarmed-fix + +structarmed-clear: + @$(DOCKER_RUN) $(DOCKER_IMAGE_NAME) \ + $(STRUCT_ARMED_DIRECTORY)/vendor/bin/structarmed \ + --config $(STRUCT_ARMED_DIRECTORY)/structarmed.php \ + --clear-cache +.PHONY: structarmed-clear + +structarmed-update: + $(DOCKER_RUN) ${DOCKER_IMAGE_NAME} composer \ + --working-dir=$(STRUCT_ARMED_DIRECTORY) \ + update +.PHONY: structarmed-update + +structarmed-install: + $(DOCKER_RUN) ${DOCKER_IMAGE_NAME} composer \ + --working-dir=$(STRUCT_ARMED_DIRECTORY) \ + install +.PHONY: structarmed-install + +structarmed-bump: structarmed-update _do-structarmed-bump structarmed-update +.PHONY: structarmed-bump + +_do-structarmed-bump: + $(DOCKER_RUN) ${DOCKER_IMAGE_NAME} composer \ + --working-dir=$(STRUCT_ARMED_DIRECTORY) \ + bump -D +.PHONY: _do-structarmed-bump + +endif diff --git a/migrations/InstallStructArmed/Install.mk b/migrations/InstallStructArmed/Install.mk new file mode 100644 index 0000000..1435e45 --- /dev/null +++ b/migrations/InstallStructArmed/Install.mk @@ -0,0 +1,36 @@ +_STRUCT_ARMED_MIGRATION_DIRECTORY := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) +STRUCT_ARMED_DIRECTORY := $(PROJECT_DIR)tools/structarmed +HAS_STRUCT_ARMED_DIR := $(strip $(shell if [ -d $(STRUCT_ARMED_DIRECTORY) ]; then echo TRUE; fi)) + +ifneq ("$(HAS_STRUCT_ARMED_DIR)","TRUE") + +PROJECT_COMPOSER_PLATFORM := $(shell $(DOCKER_RUN) ${DOCKER_IMAGE_NAME} composer config platform.php) +HELP += $(call MK_HELP,'install-structarmed','Install a standalone copy of structarmed into tools/structarmed') + +install-structarmed: $(STRUCT_ARMED_DIRECTORY) _do-install-structarmed + @echo 'Now StructArmed is installed, you should edit its configuration file to define appropriate layers:' + @echo 'https://boundwize.github.io/structarmed/configuration/' +.PHONY: install-structarmed + +_do-install-structarmed: + @$(DOCKER_RUN) --env PHP_EXTENSIONS="$(PHP_EXTENSIONS)" ${DOCKER_IMAGE_NAME} php $(_STRUCT_ARMED_MIGRATION_DIRECTORY)migrate $(PROJECT_DIR) +.PHONY: _do-install-structarmed + +# Installation routine for rector: +$(STRUCT_ARMED_DIRECTORY): + mkdir -p $(STRUCT_ARMED_DIRECTORY) + echo '{}' > $(STRUCT_ARMED_DIRECTORY)/composer.json + $(DOCKER_RUN) $(DOCKER_IMAGE_NAME) composer \ + --working-dir=$(STRUCT_ARMED_DIRECTORY) \ + config platform.php $(PROJECT_COMPOSER_PLATFORM) + $(DOCKER_RUN) $(DOCKER_IMAGE_NAME) composer \ + --working-dir=$(STRUCT_ARMED_DIRECTORY) \ + require --dev boundwize/structarmed + cp $(_STRUCT_ARMED_MIGRATION_DIRECTORY)structarmed.php $(STRUCT_ARMED_DIRECTORY)/ + echo vendor > $(STRUCT_ARMED_DIRECTORY)/.gitignore + $(DOCKER_RUN) $(DOCKER_IMAGE_NAME) composer \ + --working-dir=$(STRUCT_ARMED_DIRECTORY) \ + install +# end + +endif diff --git a/migrations/InstallStructArmed/migrate b/migrations/InstallStructArmed/migrate new file mode 100644 index 0000000..a79d2d2 --- /dev/null +++ b/migrations/InstallStructArmed/migrate @@ -0,0 +1,25 @@ +#!/usr/bin/env php +gitAttributes); +$attributes->ignore('tools'); diff --git a/migrations/InstallStructArmed/structarmed.php b/migrations/InstallStructArmed/structarmed.php new file mode 100644 index 0000000..828f585 --- /dev/null +++ b/migrations/InstallStructArmed/structarmed.php @@ -0,0 +1,9 @@ +withPresets(Preset::PER(), Preset::CODEQUALITY()); diff --git a/migrations/Migrations.mk b/migrations/Migrations.mk index bca1cee..55583f0 100644 --- a/migrations/Migrations.mk +++ b/migrations/Migrations.mk @@ -4,3 +4,4 @@ include $(_MAKEFILE_DIR)migrations/InstallStandaloneRector/InstallStandaloneRect include $(_MAKEFILE_DIR)migrations/InstallMago/InstallMago.mk include $(_MAKEFILE_DIR)migrations/UninstallPsalm/UninstallPsalm.mk include $(_MAKEFILE_DIR)migrations/InstallInfectionWithMago/Install.mk +include $(_MAKEFILE_DIR)migrations/InstallStructArmed/Install.mk