SHELL := /bin/bash
PHP := "$(shell which php)" $(PHP_EXTRA_ARGS)
COMPOSER := $(PHP) "$(shell which composer)" $(COMPOSER_EXTRA_ARGS)
PHPUNIT_EXTRA_ARGS := --config=test/phpunit.xml
PHPUNIT := $(PHP) vendor/bin/phpunit $(PHPUNIT_EXTRA_ARGS)
INFECTION := $(PHP) vendor/bin/infection $(INFECTION_EXTRA_ARGS)
CURL := "$(shell which curl)"
JQ := "$(shell which jq)"
XSLTPROC := "$(shell which xsltproc)"
JSON_FILES := $(shell find . -name '*.json' -not -path './vendor/*' -not -path './.build/*' -not -path './dev-ops/bin/*/vendor/*' -not -path './src/Core/vendor/*' -not -path './src/DatasetBase/vendor/*' -not -path './src/PortalBase/vendor/*' -not -path './src/StorageBase/vendor/*' -not -path './src/TestSuitePortal/vendor/*' -not -path './src/TestSuiteStorage/vendor/*' -not -path './src/UiAdminBase/vendor/*' -not -path './src/Utility/vendor/*' -not -path './test/Core/Fixture/_files/portal-node-configuration-invalid.json' -not -path './test-suite-portal-test-portal/vendor/*')
GIT := "$(shell which git)"

PHPSTAN_COMPOSER_DIR := dev-ops/bin/phpstan
PHPSTAN_FILE := $(PHPSTAN_COMPOSER_DIR)/vendor/bin/phpstan

COMPOSER_NORMALIZE_PHAR := https://github.com/ergebnis/composer-normalize/releases/download/2.42.0/composer-normalize.phar
COMPOSER_NORMALIZE_FILE := dev-ops/bin/composer-normalize
COMPOSER_NORMALIZE_EXTRA_ARGS := --indent-size=4 --indent-style=space --no-check-lock --no-update-lock

COMPOSER_REQUIRE_CHECKER_PHAR := https://github.com/maglnet/ComposerRequireChecker/releases/download/4.11.0/composer-require-checker.phar
COMPOSER_REQUIRE_CHECKER_FILE := dev-ops/bin/composer-require-checker

PHPMD_PHAR := https://github.com/phpmd/phpmd/releases/download/2.15.0/phpmd.phar
PHPMD_FILE := dev-ops/bin/phpmd

PHPCPD_PHAR := https://phar.phpunit.de/phpcpd.phar
PHPCPD_FILE := dev-ops/bin/phpcpd

COMPOSER_UNUSED_COMPOSER_DIR := dev-ops/bin/composer-unused
COMPOSER_UNUSED_FILE := $(COMPOSER_UNUSED_COMPOSER_DIR)/vendor/bin/composer-unused

EASY_CODING_STANDARD_COMPOSER_DIR := dev-ops/bin/easy-coding-standard
EASY_CODING_STANDARD_FILE := $(EASY_CODING_STANDARD_COMPOSER_DIR)/vendor/bin/ecs

PHPCHURN_COMPOSER_DIR := dev-ops/bin/php-churn
PHPCHURN_FILE := $(PHPCHURN_COMPOSER_DIR)/vendor/bin/churn

RECTOR_COMPOSER_DIR := dev-ops/bin/rector
RECTOR_FILE := $(RECTOR_COMPOSER_DIR)/vendor/bin/rector

.DEFAULT_GOAL := help
.PHONY: help
help: ## List useful make targets
	@echo 'Available make targets'
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: all
all: clean it coverage infection ## Cleans up and runs typical tests and style analysis

.PHONY: clean
clean: clean-package-vendor ## Cleans up all ignored files and directories
	[[ ! -f composer.lock ]] || rm composer.lock
	[[ ! -d vendor ]] || rm -rf vendor
	[[ ! -d .build ]] || rm -rf .build
	[[ ! -f "$(COMPOSER_NORMALIZE_FILE)" ]] || rm -f "$(COMPOSER_NORMALIZE_FILE)"
	[[ ! -f "$(COMPOSER_REQUIRE_CHECKER_FILE)" ]] || rm -f "$(COMPOSER_REQUIRE_CHECKER_FILE)"
	[[ ! -d "$(COMPOSER_UNUSED_COMPOSER_DIR)/vendor" ]] || rm -rf "$(COMPOSER_UNUSED_COMPOSER_DIR)/vendor"
	[[ ! -d "$(EASY_CODING_STANDARD_COMPOSER_DIR)/vendor" ]] || rm -rf "$(EASY_CODING_STANDARD_COMPOSER_DIR)/vendor"
	[[ ! -f "$(PHPMD_FILE)" ]] || rm -f "$(PHPMD_FILE)"
	[[ ! -f "$(PHPCPD_FILE)" ]] || rm -f "$(PHPCPD_FILE)"
	[[ ! -d "$(PHPSTAN_COMPOSER_DIR)/vendor" ]] || rm -rf "$(PHPSTAN_COMPOSER_DIR)/vendor"
	[[ ! -d "$(PHPCHURN_COMPOSER_DIR)/vendor" ]] || rm -rf "$(PHPCHURN_COMPOSER_DIR)/vendor"
	[[ ! -d "$(RECTOR_COMPOSER_DIR)/vendor" ]] || rm -rf "$(RECTOR_COMPOSER_DIR)/vendor"
	[[ ! -d test/Core/Fixture/_files/portal_filesystem ]] || rm -rf test/Core/Fixture/_files/portal_filesystem
	make -C test-suite-portal-test-portal clean

.PHONY: clean-package-vendor
clean-package-vendor:
	[[ ! -f src/Core/composer.lock ]] || rm -f src/Core/composer.lock
	[[ ! -f src/DatasetBase/composer.lock ]] || rm -f src/DatasetBase/composer.lock
	[[ ! -f src/PortalBase/composer.lock ]] || rm -f src/PortalBase/composer.lock
	[[ ! -f src/StorageBase/composer.lock ]] || rm -f src/StorageBase/composer.lock
    # TODO add portal test suite
	[[ ! -f src/TestSuiteStorage/composer.lock ]] || rm -f src/TestSuiteStorage/composer.lock
	[[ ! -f src/UiAdminBase/composer.lock ]] || rm -f src/UiAdminBase/composer.lock
	[[ ! -f src/Utility/composer.lock ]] || rm -f src/Utility/composer.lock

.PHONY: it
it: cs-fix cs coverage ## Fix code style and run unit tests

.PHONY: coverage
coverage: vendor .build test-setup-fixture clean-package-vendor run-phpunit-coverage test-clean-fixture ## Run phpunit coverage tests

.PHONY: run-phpunit-coverage
run-phpunit-coverage:
	$(PHPUNIT) --coverage-text
	make -C test-suite-portal-test-portal coverage

.PHONY: tests-without-coverage
tests-without-coverage: vendor .build test-setup-fixture clean-package-vendor run-phpunit test-clean-fixture ## Run phpunit tests without coverage. This is needed as pecl does not serve xdebug 3.2 for php 8.3 . See https://bugs.xdebug.org/view.php?id=2252

.PHONY: run-phpunit
run-phpunit:
	$(PHPUNIT)
	make -C test-suite-portal-test-portal test

.PHONY: cs
cs: cs-php cs-phpstan cs-phpmd cs-soft-require cs-composer-unused cs-composer-normalize cs-json cs-phpchurn ## Run every code style check target

.PHONY: cs-php
cs-php: .build $(EASY_CODING_STANDARD_FILE) ## Run easy-coding-standard for code style analysis
	$(PHP) $(EASY_CODING_STANDARD_FILE) check --config=dev-ops/ecs.php

.PHONY: cs-phpstan
cs-phpstan: vendor .build $(PHPSTAN_FILE) ## Run phpstan for static code analysis
	[[ -z "${CI}" ]] || $(PHP) $(PHPSTAN_FILE) analyse --level 8 -c dev-ops/phpstan.neon --error-format=junit > .build/phpstan.junit.xml
	[[ -n "${CI}" ]] || $(PHP) $(PHPSTAN_FILE) analyse --level 8 -c dev-ops/phpstan.neon

.PHONY: cs-phpmd
cs-phpmd: vendor .build $(PHPMD_FILE) ## Run php mess detector for static code analysis
	[[ -z "${CI}" ]] || [[ -f .build/phpmd-junit.xslt ]] || $(CURL) https://phpmd.org/junit.xslt -o .build/phpmd-junit.xslt
	[[ -z "${CI}" ]] || $(PHP) -d 'error_reporting=E_ALL & ~E_DEPRECATED' $(PHPMD_FILE) src/Core xml dev-ops/phpmd.xml | $(XSLTPROC) .build/phpmd-junit.xslt - > .build/php-md-core.junit.xml && exit $${PIPESTATUS[0]}
	[[ -z "${CI}" ]] || $(PHP) -d 'error_reporting=E_ALL & ~E_DEPRECATED' $(PHPMD_FILE) src/DatasetBase xml dev-ops/phpmd.xml | $(XSLTPROC) .build/phpmd-junit.xslt - > .build/php-md-dataset-base.junit.xml && exit $${PIPESTATUS[0]}
	[[ -z "${CI}" ]] || $(PHP) -d 'error_reporting=E_ALL & ~E_DEPRECATED' $(PHPMD_FILE) src/PortalBase xml dev-ops/phpmd.xml | $(XSLTPROC) .build/phpmd-junit.xslt - > .build/php-md-portal-base.junit.xml && exit $${PIPESTATUS[0]}
	[[ -z "${CI}" ]] || $(PHP) -d 'error_reporting=E_ALL & ~E_DEPRECATED' $(PHPMD_FILE) src/StorageBase xml dev-ops/phpmd.xml | $(XSLTPROC) .build/phpmd-junit.xslt - > .build/php-md-storage-base.junit.xml && exit $${PIPESTATUS[0]}
	[[ -z "${CI}" ]] || $(PHP) -d 'error_reporting=E_ALL & ~E_DEPRECATED' $(PHPMD_FILE) src/TestSuitePortal xml dev-ops/phpmd.xml | $(XSLTPROC) .build/phpmd-junit.xslt - > .build/php-md-test-suite-portal.junit.xml && exit $${PIPESTATUS[0]}
	[[ -z "${CI}" ]] || $(PHP) -d 'error_reporting=E_ALL & ~E_DEPRECATED' $(PHPMD_FILE) src/TestSuiteStorage xml dev-ops/phpmd.xml | $(XSLTPROC) .build/phpmd-junit.xslt - > .build/php-md-test-suite-storage.junit.xml && exit $${PIPESTATUS[0]}
	[[ -z "${CI}" ]] || $(PHP) -d 'error_reporting=E_ALL & ~E_DEPRECATED' $(PHPMD_FILE) src/UiAdminBase xml dev-ops/phpmd.xml | $(XSLTPROC) .build/phpmd-junit.xslt - > .build/php-md-ui-admin-base.junit.xml && exit $${PIPESTATUS[0]}
	[[ -z "${CI}" ]] || $(PHP) -d 'error_reporting=E_ALL & ~E_DEPRECATED' $(PHPMD_FILE) src/Utility xml dev-ops/phpmd.xml | $(XSLTPROC) .build/phpmd-junit.xslt - > .build/php-md-utility.junit.xml && exit $${PIPESTATUS[0]}
	$(PHP) $(PHPMD_FILE) src ansi dev-ops/phpmd.xml

.PHONY: cs-phpcpd
cs-phpcpd: vendor clean-package-vendor .build $(PHPCPD_FILE) ## Run php copy paste detector for static code analysis
	# clean up because phpcpd --exclude is not working atm https://github.com/sebastianbergmann/phpcpd/issues/202
	[[ -z "${CI}" ]] || $(PHP) "$(PHPCPD_FILE)" --fuzzy src/Core --log-pmd .build/phpcpd-core.xml
	[[ -n "${CI}" ]] || $(PHP) "$(PHPCPD_FILE)" --fuzzy src/Core
	[[ -z "${CI}" ]] || $(PHP) "$(PHPCPD_FILE)" --fuzzy src/DatasetBase --log-pmd .build/phpcpd-dataset.xml
	[[ -n "${CI}" ]] || $(PHP) "$(PHPCPD_FILE)" --fuzzy src/DatasetBase
	[[ -z "${CI}" ]] || $(PHP) "$(PHPCPD_FILE)" --fuzzy src/PortalBase --log-pmd .build/phpcpd-portal.xml
	[[ -n "${CI}" ]] || $(PHP) "$(PHPCPD_FILE)" --fuzzy src/PortalBase
	[[ -z "${CI}" ]] || $(PHP) "$(PHPCPD_FILE)" --fuzzy src/StorageBase --log-pmd .build/phpcpd-storage.xml
	[[ -n "${CI}" ]] || $(PHP) "$(PHPCPD_FILE)" --fuzzy src/StorageBase
	[[ -z "${CI}" ]] || $(PHP) "$(PHPCPD_FILE)" --fuzzy src/TestSuiteStorage --log-pmd .build/phpcpd-test-suite-storage.xml
	[[ -n "${CI}" ]] || $(PHP) "$(PHPCPD_FILE)" --fuzzy src/TestSuiteStorage
	[[ -z "${CI}" ]] || $(PHP) "$(PHPCPD_FILE)" --fuzzy src/UiAdminBase --log-pmd .build/phpcpd-ui-admin-base.xml
	[[ -n "${CI}" ]] || $(PHP) "$(PHPCPD_FILE)" --fuzzy src/UiAdminBase
	[[ -z "${CI}" ]] || $(PHP) "$(PHPCPD_FILE)" --fuzzy src/Utility --log-pmd .build/phpcpd-utility.xml
	[[ -n "${CI}" ]] || $(PHP) "$(PHPCPD_FILE)" --fuzzy src/Utility

.PHONY: cs-composer-unused
cs-composer-unused: vendor src/Core/vendor src/DatasetBase/vendor src/PortalBase/vendor src/StorageBase/vendor src/TestSuiteStorage/vendor src/UiAdminBase/vendor src/Utility/vendor $(COMPOSER_UNUSED_FILE) ## Run composer-unused to detect once-required packages that are not used anymore
	$(PHP) "$(COMPOSER_UNUSED_FILE)" --configuration=dev-ops/composer-unused.php --no-progress
	cd src/Core && $(PHP) "../../$(COMPOSER_UNUSED_FILE)" --configuration=../../dev-ops/composer-unused.php --no-progress
	cd src/DatasetBase && $(PHP) "../../$(COMPOSER_UNUSED_FILE)" --no-progress
	cd src/PortalBase && $(PHP) "../../$(COMPOSER_UNUSED_FILE)" --configuration=../../dev-ops/composer-unused-portal-base.php --no-progress
	cd src/StorageBase && $(PHP) "../../$(COMPOSER_UNUSED_FILE)" --no-progress
# TODO add portal test suite
	cd src/TestSuiteStorage && $(PHP) "../../$(COMPOSER_UNUSED_FILE)" --no-progress
	cd src/UiAdminBase && $(PHP) "../../$(COMPOSER_UNUSED_FILE)" --no-progress
	cd src/Utility && $(PHP) "../../$(COMPOSER_UNUSED_FILE)" --no-progress

.PHONY: cs-soft-require
cs-soft-require: vendor .build $(COMPOSER_REQUIRE_CHECKER_FILE) ## Run composer-require-checker to detect library usage without requirement entry in composer.json
	$(PHP) "$(COMPOSER_REQUIRE_CHECKER_FILE)" check --config-file=$(shell pwd)/dev-ops/composer-soft-requirements.json composer.json

.PHONY: cs-composer-normalize
cs-composer-normalize: $(COMPOSER_NORMALIZE_FILE) ## Run composer-normalize for composer.json style analysis
	$(PHP) "$(COMPOSER_NORMALIZE_FILE)" $(COMPOSER_NORMALIZE_EXTRA_ARGS) --diff --dry-run composer.json
	$(PHP) "$(COMPOSER_NORMALIZE_FILE)" $(COMPOSER_NORMALIZE_EXTRA_ARGS) --diff --dry-run src/Core/composer.json
	$(PHP) "$(COMPOSER_NORMALIZE_FILE)" $(COMPOSER_NORMALIZE_EXTRA_ARGS) --diff --dry-run src/DatasetBase/composer.json
	$(PHP) "$(COMPOSER_NORMALIZE_FILE)" $(COMPOSER_NORMALIZE_EXTRA_ARGS) --diff --dry-run src/PortalBase/composer.json
	$(PHP) "$(COMPOSER_NORMALIZE_FILE)" $(COMPOSER_NORMALIZE_EXTRA_ARGS) --diff --dry-run src/StorageBase/composer.json
	$(PHP) "$(COMPOSER_NORMALIZE_FILE)" $(COMPOSER_NORMALIZE_EXTRA_ARGS) --diff --dry-run src/TestSuitePortal/composer.json
	$(PHP) "$(COMPOSER_NORMALIZE_FILE)" $(COMPOSER_NORMALIZE_EXTRA_ARGS) --diff --dry-run src/TestSuiteStorage/composer.json
	$(PHP) "$(COMPOSER_NORMALIZE_FILE)" $(COMPOSER_NORMALIZE_EXTRA_ARGS) --diff --dry-run src/UiAdminBase/composer.json
	$(PHP) "$(COMPOSER_NORMALIZE_FILE)" $(COMPOSER_NORMALIZE_EXTRA_ARGS) --diff --dry-run src/Utility/composer.json

.PHONY: cs-json
cs-json: $(JSON_FILES) ## Run jq on every json file to ensure they are parsable and therefore valid

.PHONY: cs-phpchurn
cs-phpchurn: .build $(PHPCHURN_FILE) ## Run php-churn for prediction of refactoring cases
	$(PHP) "$(PHPCHURN_FILE)" run --configuration dev-ops/churn.yml --format text

.PHONY: cs-fix-rector
cs-fix-rector: $(RECTOR_FILE) ## Run rector to upgrade PHP code to recent features
	$(PHP) "$(RECTOR_FILE)" --config=dev-ops/rector.php

.PHONY: $(JSON_FILES)
$(JSON_FILES):
	$(JQ) . "$@"

.PHONY: cs-fix ## Run all code style fixer that change files
cs-fix: cs-fix-composer-normalize cs-fix-php

.PHONY: cs-fix-composer-normalize
cs-fix-composer-normalize: $(COMPOSER_NORMALIZE_FILE) ## Run composer-normalize for automatic composer.json style fixes
	$(PHP) "$(COMPOSER_NORMALIZE_FILE)" $(COMPOSER_NORMALIZE_EXTRA_ARGS) --diff composer.json
	$(PHP) "$(COMPOSER_NORMALIZE_FILE)" $(COMPOSER_NORMALIZE_EXTRA_ARGS) --diff src/Core/composer.json
	$(PHP) "$(COMPOSER_NORMALIZE_FILE)" $(COMPOSER_NORMALIZE_EXTRA_ARGS) --diff src/DatasetBase/composer.json
	$(PHP) "$(COMPOSER_NORMALIZE_FILE)" $(COMPOSER_NORMALIZE_EXTRA_ARGS) --diff src/PortalBase/composer.json
	$(PHP) "$(COMPOSER_NORMALIZE_FILE)" $(COMPOSER_NORMALIZE_EXTRA_ARGS) --diff src/StorageBase/composer.json
	$(PHP) "$(COMPOSER_NORMALIZE_FILE)" $(COMPOSER_NORMALIZE_EXTRA_ARGS) --diff src/TestSuitePortal/composer.json
	$(PHP) "$(COMPOSER_NORMALIZE_FILE)" $(COMPOSER_NORMALIZE_EXTRA_ARGS) --diff src/TestSuiteStorage/composer.json
	$(PHP) "$(COMPOSER_NORMALIZE_FILE)" $(COMPOSER_NORMALIZE_EXTRA_ARGS) --diff src/UiAdminBase/composer.json
	$(PHP) "$(COMPOSER_NORMALIZE_FILE)" $(COMPOSER_NORMALIZE_EXTRA_ARGS) --diff src/Utility/composer.json

.PHONY: cs-fix-php
cs-fix-php: .build $(EASY_CODING_STANDARD_FILE) ## Run easy-coding-standard for automatic code style fixes
	$(PHP) "$(EASY_CODING_STANDARD_FILE)" check --config=dev-ops/ecs.php --fix

.PHONY: infection
infection: clean test-setup-fixture vendor .build ## Run infection tests
	# Can be simplified when infection/infection#1283 is resolved
	[[ -d .build/phpunit-logs ]] || mkdir -p .build/.phpunit-coverage
	$(PHPUNIT) --coverage-xml=.build/.phpunit-coverage/index.xml --log-junit=.build/.phpunit-coverage/infection.junit.xml
	$(INFECTION) --only-covered --only-covering-test-cases --threads=max --configuration=dev-ops/infection.json --coverage=../.build/.phpunit-coverage --show-mutations --no-interaction

.PHONY: run-phpunit
run-phpunit: vendor .build
	$(PHPUNIT) --log-junit=.build/.phpunit-coverage/phpunit.junit.xml
	make -C test-suite-portal-test-portal test

test/%Test.php: vendor
	$(PHPUNIT) "$@"

$(PHPSTAN_FILE): ## Install phpstan executable
	$(COMPOSER) install -d "$(PHPSTAN_COMPOSER_DIR)"

$(COMPOSER_NORMALIZE_FILE): ## Install composer-normalize executable
	$(CURL) -L "$(COMPOSER_NORMALIZE_PHAR)" -o "$(COMPOSER_NORMALIZE_FILE)"

$(COMPOSER_REQUIRE_CHECKER_FILE): ## Install composer-require-checker executable
	$(CURL) -L "$(COMPOSER_REQUIRE_CHECKER_PHAR)" -o "$(COMPOSER_REQUIRE_CHECKER_FILE)"

$(PHPMD_FILE): ## Install phpmd executable
	$(CURL) -L "$(PHPMD_PHAR)" -o "$(PHPMD_FILE)"

$(PHPCPD_FILE): ## Install phpcpd executable
	$(CURL) -L "$(PHPCPD_PHAR)" -o "$(PHPCPD_FILE)"

$(COMPOSER_UNUSED_FILE): ## Install composer-unused executable
	$(COMPOSER) install -d "$(COMPOSER_UNUSED_COMPOSER_DIR)"

$(EASY_CODING_STANDARD_FILE): ## Install easy-coding-standard executable
	$(COMPOSER) install -d "$(EASY_CODING_STANDARD_COMPOSER_DIR)"

$(PHPCHURN_FILE): ## Install php-churn executable
	$(COMPOSER) install -d "$(PHPCHURN_COMPOSER_DIR)"

$(RECTOR_FILE): ## Install rector executable
	$(COMPOSER) install -d "$(RECTOR_COMPOSER_DIR)"

.PHONY: composer-update
composer-update:
	[[ -f vendor/autoload.php && -n "${CI}" ]] || $(COMPOSER) update

src/Core/vendor:
	[[ -f src/Core/vendor/autoload.php && -n "${CI}" ]] || $(COMPOSER) update -d src/Core

src/DatasetBase/vendor:
	[[ -f src/DatasetBase/vendor/autoload.php && -n "${CI}" ]] || $(COMPOSER) update -d src/DatasetBase

src/PortalBase/vendor:
	[[ -f src/PortalBase/vendor/autoload.php && -n "${CI}" ]] || $(COMPOSER) update -d src/PortalBase

src/StorageBase/vendor:
	[[ -f src/StorageBase/vendor/autoload.php && -n "${CI}" ]] || $(COMPOSER) update -d src/StorageBase
# TODO add portal test suite

src/TestSuiteStorage/vendor:
	[[ -f src/TestSuiteStorage/vendor/autoload.php && -n "${CI}" ]] || $(COMPOSER) update -d src/TestSuiteStorage

src/UiAdminBase/vendor:
	[[ -f src/UiAdminBase/vendor/autoload.php && -n "${CI}" ]] || $(COMPOSER) update -d src/UiAdminBase

src/Utility/vendor:
	[[ -f src/Utility/vendor/autoload.php && -n "${CI}" ]] || $(COMPOSER) update -d src/Utility

vendor: composer-update

.PHONY: .build
.build:
	[[ -d .build ]] || mkdir .build

composer.lock: vendor

.PHONY: test-refresh-fixture
test-refresh-fixture: test-setup-fixture test-clean-fixture

.PHONY: test-setup-fixture
test-setup-fixture: vendor
	[[ ! -d test-composer-integration/vendor ]] || rm -rf test-composer-integration/vendor
	[[ ! -f test-composer-integration/composer.lock ]] || rm test-composer-integration/composer.lock
	composer install -d test-composer-integration/
	make -C test-suite-portal-test-portal clean
	make -C test-suite-portal-test-portal vendor

.PHONY: test-clean-fixture
test-clean-fixture:
	[[ ! -d test-composer-integration/vendor ]] || rm -rf test-composer-integration/vendor
	make -C test-suite-portal-test-portal clean

.PHONY: build-packages
build-packages:
	dev-ops/bin/build-subpackage Core
	dev-ops/bin/build-subpackage DatasetBase
	dev-ops/bin/build-subpackage PortalBase
	dev-ops/bin/build-subpackage StorageBase
	dev-ops/bin/build-subpackage TestSuiteStorage
	dev-ops/bin/build-subpackage UiAdminBase
	dev-ops/bin/build-subpackage Utility
	# TODO Add TestSuitePortal

.PHONY: publish-packages
publish-packages: build-packages
	$(GIT) add -A
	$(GIT) commit -m "Build subpackages"
	dev-ops/bin/publish-subpackage Core core "$(TAG)" "$(BRANCH)"
	dev-ops/bin/publish-subpackage DatasetBase dataset-base "$(TAG)" "$(BRANCH)"
	dev-ops/bin/publish-subpackage PortalBase portal-base "$(TAG)" "$(BRANCH)"
	dev-ops/bin/publish-subpackage StorageBase storage-base "$(TAG)" "$(BRANCH)"
	dev-ops/bin/publish-subpackage TestSuiteStorage test-suite-storage "$(TAG)" "$(BRANCH)"
	dev-ops/bin/publish-subpackage UiAdminBase ui-admin-base "$(TAG)" "$(BRANCH)"
	dev-ops/bin/publish-subpackage Utility utility "$(TAG)" "$(BRANCH)"
	# TODO Add TestSuitePortal
	$(GIT) reset --hard HEAD^1

.PHONY: subtree-merge
subtree-merge: ## Merge core and base packages into framework
	git subtree add -P src/DatasetBase ../heptaconnect-dataset-base master
	git subtree add -P src/PortalBase ../heptaconnect-portal-base master
	git subtree add -P src/StorageBase ../heptaconnect-storage-base master
	git subtree add -P src/Core ../heptaconnect-core master
