From d88ee801bff8f74b04bad9a5612b7be57aa1248f Mon Sep 17 00:00:00 2001 From: hel-platta-automation <95360595+hel-platta-automation@users.noreply.github.com> Date: Wed, 15 Jan 2025 12:48:43 +0000 Subject: [PATCH] Update configuration --- .platform/schema | 2 +- Makefile | 31 ++++-- composer.lock | 46 ++++----- tools/commit-msg | 0 tools/make/Makefile | 46 --------- tools/make/ansible.mk | 35 ------- tools/make/common.mk | 75 -------------- tools/make/composer.mk | 18 +--- tools/make/docker.mk | 61 +---------- tools/make/drupal.mk | 161 +++++++----------------------- tools/make/{project => }/git.mk | 0 tools/make/include.mk | 60 ----------- tools/make/javascript.mk | 44 -------- tools/make/kubectl.mk | 56 ----------- tools/make/lagoon.mk | 38 ------- tools/make/override.mk | 3 - tools/make/project/.keepme | 0 tools/make/project/composer.mk | 3 - tools/make/project/db-sync.sh | 25 ----- tools/make/project/install.mk | 49 --------- tools/make/qa.mk | 74 ++++---------- tools/make/symfony.mk | 78 --------------- tools/make/{project => }/theme.mk | 2 +- tools/make/utils.mk | 74 -------------- 24 files changed, 108 insertions(+), 873 deletions(-) mode change 100755 => 100644 tools/commit-msg delete mode 100644 tools/make/Makefile delete mode 100644 tools/make/ansible.mk delete mode 100644 tools/make/common.mk rename tools/make/{project => }/git.mk (100%) delete mode 100644 tools/make/include.mk delete mode 100644 tools/make/javascript.mk delete mode 100644 tools/make/kubectl.mk delete mode 100644 tools/make/lagoon.mk delete mode 100644 tools/make/override.mk delete mode 100644 tools/make/project/.keepme delete mode 100644 tools/make/project/composer.mk delete mode 100644 tools/make/project/db-sync.sh delete mode 100644 tools/make/project/install.mk delete mode 100644 tools/make/symfony.mk rename tools/make/{project => }/theme.mk (98%) delete mode 100644 tools/make/utils.mk diff --git a/.platform/schema b/.platform/schema index da2d3988..3f10ffe7 100644 --- a/.platform/schema +++ b/.platform/schema @@ -1 +1 @@ -14 \ No newline at end of file +15 \ No newline at end of file diff --git a/Makefile b/Makefile index 27392cb1..44ee5d48 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,36 @@ PHONY := PROJECT_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +# Colors +NO_COLOR=\033[0m +CYAN=\033[36m +GREEN=\033[0;32m +RED=\033[0;31m +YELLOW=\033[0;33m + +ENV := local + # Include project env vars (if exists) -include .env -include .env.local -# Include druidfi/tools config -include $(PROJECT_DIR)/tools/make/Makefile +define step + @printf "\n⭐ ${YELLOW}${1}${NO_COLOR}\n" +endef + +PHONY += help +help: ## List all make commands + $(call step,Available make commands:\n) + @cat $(MAKEFILE_LIST) | grep -e "^[a-zA-Z_\-]*: *.*## *" | awk 'BEGIN {FS = ":.*?## "}; {printf "${CYAN}%-30s${NO_COLOR} %s\n", $$1, $$2}' -# Include project specific make files (if they exist) --include $(PROJECT_DIR)/tools/make/project/*.mk +# Allow projects to specify makefiles. +-include tools/make/project/*.mk -# Project specific overrides for variables (if they exist) --include $(PROJECT_DIR)/tools/make/override.mk +include tools/make/docker.mk +include tools/make/composer.mk +include tools/make/drupal.mk +include tools/make/git.mk +include tools/make/theme.mk +include tools/make/qa.mk .PHONY: $(PHONY) diff --git a/composer.lock b/composer.lock index 6cce787f..44db46ec 100644 --- a/composer.lock +++ b/composer.lock @@ -3340,17 +3340,17 @@ }, { "name": "drupal/entity_usage", - "version": "2.0.0-beta16", + "version": "2.0.0-beta17", "source": { "type": "git", "url": "https://git.drupalcode.org/project/entity_usage.git", - "reference": "8.x-2.0-beta16" + "reference": "8.x-2.0-beta17" }, "dist": { "type": "zip", - "url": "https://ftp.drupal.org/files/projects/entity_usage-8.x-2.0-beta16.zip", - "reference": "8.x-2.0-beta16", - "shasum": "af6533149a0926d2d539f279e7e08073f8f08c55" + "url": "https://ftp.drupal.org/files/projects/entity_usage-8.x-2.0-beta17.zip", + "reference": "8.x-2.0-beta17", + "shasum": "29691274f6b68b13a8d1ba295677453c85c2ed39" }, "require": { "drupal/core": "^10.2 || ^11" @@ -3370,8 +3370,8 @@ "type": "drupal-module", "extra": { "drupal": { - "version": "8.x-2.0-beta16", - "datestamp": "1733149424", + "version": "8.x-2.0-beta17", + "datestamp": "1736865887", "security-coverage": { "status": "not-covered", "message": "Beta releases are not covered by Drupal security advisories." @@ -4129,16 +4129,16 @@ }, { "name": "drupal/hdbt", - "version": "6.8.34", + "version": "6.8.35", "source": { "type": "git", "url": "https://github.com/City-of-Helsinki/drupal-hdbt.git", - "reference": "9216d2943483e75e9f5d9ed11eba03e836c93f98" + "reference": "a4afd522f090c7f91e03d58e82e74956ccfbd1e9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/City-of-Helsinki/drupal-hdbt/zipball/9216d2943483e75e9f5d9ed11eba03e836c93f98", - "reference": "9216d2943483e75e9f5d9ed11eba03e836c93f98", + "url": "https://api.github.com/repos/City-of-Helsinki/drupal-hdbt/zipball/a4afd522f090c7f91e03d58e82e74956ccfbd1e9", + "reference": "a4afd522f090c7f91e03d58e82e74956ccfbd1e9", "shasum": "" }, "require": { @@ -4157,10 +4157,10 @@ "Drupal" ], "support": { - "source": "https://github.com/City-of-Helsinki/drupal-hdbt/tree/6.8.34", + "source": "https://github.com/City-of-Helsinki/drupal-hdbt/tree/6.8.35", "issues": "https://github.com/City-of-Helsinki/drupal-hdbt/issues" }, - "time": "2025-01-14T10:26:39+00:00" + "time": "2025-01-15T12:38:48+00:00" }, { "name": "drupal/hdbt_admin", @@ -4348,12 +4348,12 @@ "source": { "type": "git", "url": "https://github.com/City-of-Helsinki/drupal-tools.git", - "reference": "2eb037b210a0c311ad8e742d3c1fd97e89d7b677" + "reference": "bc5416375195d1307adf188098d75a19a5de0224" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/City-of-Helsinki/drupal-tools/zipball/2eb037b210a0c311ad8e742d3c1fd97e89d7b677", - "reference": "2eb037b210a0c311ad8e742d3c1fd97e89d7b677", + "url": "https://api.github.com/repos/City-of-Helsinki/drupal-tools/zipball/bc5416375195d1307adf188098d75a19a5de0224", + "reference": "bc5416375195d1307adf188098d75a19a5de0224", "shasum": "" }, "require": { @@ -4428,7 +4428,7 @@ "source": "https://github.com/City-of-Helsinki/drupal-tools/tree/main", "issues": "https://github.com/City-of-Helsinki/drupal-tools/issues" }, - "time": "2024-12-17T10:07:01+00:00" + "time": "2025-01-15T12:24:04+00:00" }, { "name": "drupal/helfi_navigation", @@ -4466,16 +4466,16 @@ }, { "name": "drupal/helfi_platform_config", - "version": "4.12.3", + "version": "4.12.4", "source": { "type": "git", "url": "https://github.com/City-of-Helsinki/drupal-helfi-platform-config.git", - "reference": "fb0ab912a4fe38d695cbfeb84ee623ea644dd6a2" + "reference": "8daff630f9fe1a8bd1f7769cc74ac44d3900181a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/City-of-Helsinki/drupal-helfi-platform-config/zipball/fb0ab912a4fe38d695cbfeb84ee623ea644dd6a2", - "reference": "fb0ab912a4fe38d695cbfeb84ee623ea644dd6a2", + "url": "https://api.github.com/repos/City-of-Helsinki/drupal-helfi-platform-config/zipball/8daff630f9fe1a8bd1f7769cc74ac44d3900181a", + "reference": "8daff630f9fe1a8bd1f7769cc74ac44d3900181a", "shasum": "" }, "require": { @@ -4599,10 +4599,10 @@ ], "description": "HELfi platform config", "support": { - "source": "https://github.com/City-of-Helsinki/drupal-helfi-platform-config/tree/4.12.3", + "source": "https://github.com/City-of-Helsinki/drupal-helfi-platform-config/tree/4.12.4", "issues": "https://github.com/City-of-Helsinki/drupal-helfi-platform-config/issues" }, - "time": "2025-01-13T06:44:52+00:00" + "time": "2025-01-15T12:35:00+00:00" }, { "name": "drupal/helfi_proxy", diff --git a/tools/commit-msg b/tools/commit-msg old mode 100755 new mode 100644 diff --git a/tools/make/Makefile b/tools/make/Makefile deleted file mode 100644 index fa000889..00000000 --- a/tools/make/Makefile +++ /dev/null @@ -1,46 +0,0 @@ -.DEFAULT_GOAL := help - -BUILD_TARGETS := -COMPOSER_JSON_PATH ?= . -DRUIDFI_TOOLS_MAKE_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -ENV := dev -PACKAGE_JSON_PATH ?= . -RUN_ON := host -UNAME_S := $(shell uname -s) -# Shorten with https://git.io/ : https://raw.githubusercontent.com/druidfi/tools/main/update.sh -UPDATE_SCRIPT_URL := https://git.io/JP10q -WEBROOT ?= public - -include $(DRUIDFI_TOOLS_MAKE_DIR)utils.mk - -# Include druidfi/tools make files -include $(DRUIDFI_TOOLS_MAKE_DIR)include.mk - -PHONY += debug -debug: ## Show debug information - @printf "\n$(YELLOW)Debug starts:$(NO_COLOR)\n\n" - $(call dbg,DOCKER,$(call has,docker)) - $(call dbg,DOCKER_PROJECT_ROOT,$(DOCKER_PROJECT_ROOT)) - $(call dbg,DOCKER_COMPOSE_YML_EXISTS,$(DOCKER_COMPOSE_YML_EXISTS)) - $(call dbg,CLI_SERVICE,$(CLI_SERVICE)) - $(call dbg,CLI_USER,$(if $(CLI_USER),$(CLI_USER),default user from CLI image)) - $(call dbg,CLI_SHELL,${CLI_SHELL}) - $(call dbg,ENV,${ENV}) - $(call dbg,PHP on host,$(call has,php)) - $(call dbg,PHP_BIN,$(shell command -v php || echo no)) - $(call dbg,RUN_ON,${RUN_ON}) - $(call dbg,Composer on host,$(call has,composer)) - $(call dbg,COMPOSER_BIN,$(shell command -v composer || echo no)) - $(call dbg,COMPOSER_JSON_EXISTS,${COMPOSER_JSON_EXISTS}) - $(call dbg,IS_DRUPAL,${IS_DRUPAL}) - $(call dbg,IS_SYMFONY,${IS_SYMFONY}) - $(call dbg,LAGOON,${LAGOON}) - $(call dbg,SYSTEM,${SYSTEM}) - $(call dbg,WEBROOT,${WEBROOT}) - $(call dbg,UNAME_S,${UNAME_S}) -ifeq ($(RUN_ON),docker) - @printf "\n${YELLOW}Assumption: We should run on Docker and not on host${NO_COLOR}\n" -else - @printf "\n${YELLOW}Assumption: We should run on host and not on Docker${NO_COLOR}\n" -endif - @printf "\n${GREEN}End of debug.${NO_COLOR}\n" diff --git a/tools/make/ansible.mk b/tools/make/ansible.mk deleted file mode 100644 index 132f84c1..00000000 --- a/tools/make/ansible.mk +++ /dev/null @@ -1,35 +0,0 @@ -ANSIBLE_ROLES_PATH ?= ansible/roles -ANSIBLE_CHECK_ROLE ?= geerlingguy.docker -ANSIBLE_PLAYBOOK ?= ansible-playbook -ANSIBLE_PROVISION ?= ansible/provision.yml -ANSIBLE_REQUIREMENTS ?= ansible/requirements.yml -ANSIBLE_FLAGS ?= - -PHONY += provision -provision: $(ANSIBLE_ROLES_PATH)/$(ANSIBLE_CHECK_ROLE) ## Make provisioning - $(call step,Ansible: Make dry run on provisioning...\n) - @$(ANSIBLE_PLAYBOOK) $(ANSIBLE_PROVISION) $(ANSIBLE_FLAGS) - -PHONY += provision-% -provision-%: $(ANSIBLE_ROLES_PATH)/$(ANSIBLE_CHECK_ROLE) ## Make provisioning by tag - $(call step,Ansible: Make provisioning by tag "$*"...\n) - @$(ANSIBLE_PLAYBOOK) $(ANSIBLE_PROVISION) --tags="$*" $(ANSIBLE_FLAGS) - -PHONY += provision-dry-run -provision-dry-run: $(ANSIBLE_ROLES_PATH)/$(ANSIBLE_CHECK_ROLE) ## Make dry run on provisioning - $(call step,Ansible: Make dry run on provisioning...\n) - @$(ANSIBLE_PLAYBOOK) $(ANSIBLE_PROVISION) $(ANSIBLE_FLAGS) --check - -PHONY += ansible-install-roles -ansible-install-roles: ## Install Ansible roles - $(call step,Ansible: Install Ansible roles...\n) - @ansible-galaxy install -r $(ANSIBLE_REQUIREMENTS) -p $(ANSIBLE_ROLES_PATH) - -PHONY += ansible-update-roles -ansible-update-roles: ## Update Ansible roles - $(call step,Ansible: Update Ansible roles...\n) - @ansible-galaxy remove --roles-path=$(ANSIBLE_ROLES_PATH) $(shell find $(ANSIBLE_ROLES_PATH) -mindepth 1 -maxdepth 1 -type d -exec basename {} \;) || true - @ansible-galaxy install --force-with-deps --role-file=$(ANSIBLE_REQUIREMENTS) --roles-path=$(ANSIBLE_ROLES_PATH) - -$(ANSIBLE_ROLES_PATH)/$(ANSIBLE_CHECK_ROLE): - @$(MAKE) ansible-install-roles diff --git a/tools/make/common.mk b/tools/make/common.mk deleted file mode 100644 index 0ede4457..00000000 --- a/tools/make/common.mk +++ /dev/null @@ -1,75 +0,0 @@ -ARTIFACT_INCLUDE_EXISTS := $(shell test -f conf/artifact/include && echo yes || echo no) -ARTIFACT_EXCLUDE_EXISTS := $(shell test -f conf/artifact/exclude && echo yes || echo no) -ARTIFACT_CMD := tar -hczf artifact.tar.gz -DUMP_SQL_FILENAME ?= dump.sql -DUMP_SQL_EXISTS := $(shell test -f $(DUMP_SQL_FILENAME) && echo yes || echo no) -SSH_OPTS ?= -o LogLevel=ERROR -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -CLEAN_EXCLUDE := .idea $(DUMP_SQL_FILENAME) .env.local - -ifeq ($(ARTIFACT_EXCLUDE_EXISTS),yes) - ARTIFACT_CMD := $(ARTIFACT_CMD) --exclude-from=conf/artifact/exclude -endif - -ifeq ($(ARTIFACT_INCLUDE_EXISTS),yes) - ARTIFACT_CMD := $(ARTIFACT_CMD) --files-from=conf/artifact/include -else - ARTIFACT_CMD := $(ARTIFACT_CMD) * -endif - -PHONY += artifact -# This command can always be run on host -artifact: RUN_ON := host -artifact: ## Make tar.gz package from the current build - $(call step,Create artifact...\n) - @$(ARTIFACT_CMD) - -PHONY += build -build: ## Build codebase(s) - $(call group_step,Build ($(ENV)):${NO_COLOR} $(BUILD_TARGETS)) - @$(MAKE) $(BUILD_TARGETS) ENV=$(ENV) - -PHONY += build-dev -build-dev: build - -PHONY += build-testing -build-testing: - @$(MAKE) build ENV=testing - -PHONY += build-production -build-production: - @$(MAKE) build ENV=production - -PHONY += clean -clean: ## Cleanup - $(call step,Cleanup loaded files...\n) - @rm -rf vendor - @git clean -fdx $(foreach item,$(CLEAN_EXCLUDE),-e $(item)) - -PHONY += self-update -self-update: ## Self-update makefiles from druidfi/tools - $(call step,Update makefiles from druidfi/tools\n) - @bash -c "$$(curl -fsSL $(UPDATE_SCRIPT_URL))" - -PHONY += shell-% -shell-%: OPTS = $(INSTANCE_$*_OPTS) -shell-%: USER = $(INSTANCE_$*_USER) -shell-%: HOST = $(INSTANCE_$*_HOST) -shell-%: EXTRA = $(INSTANCE_$*_EXTRA) -shell-%: ## Login to remote instance - ssh $(OPTS) $(USER)@$(HOST) $(EXTRA) - -PHONY += sync -sync: ## Sync data from other environments - $(call group_step,Sync:$(NO_COLOR) $(SYNC_TARGETS)) - @$(MAKE) $(SYNC_TARGETS) ENV=$(ENV) - -PHONY += gh-download-dump -gh-download-dump: GH_FLAGS += $(if $(GH_ARTIFACT),-n $(GH_ARTIFACT),-n latest-dump) -gh-download-dump: GH_FLAGS += $(if $(GH_REPO),-R $(GH_REPO),) -gh-download-dump: ## Download database dump from repository artifacts - $(call step,Download database dump from repository artifacts\n) -ifeq ($(DUMP_SQL_EXISTS),no) - $(call run,gh run download $(strip $(GH_FLAGS)),Downloaded $(DUMP_SQL_FILENAME),Failed) -else - @echo "There is already $(DUMP_SQL_FILENAME)" -endif diff --git a/tools/make/composer.mk b/tools/make/composer.mk index 4dd21954..1e61b280 100644 --- a/tools/make/composer.mk +++ b/tools/make/composer.mk @@ -1,11 +1,3 @@ -BUILD_TARGETS += composer-install -COMPOSER_PROD_FLAGS := --no-dev --optimize-autoloader --prefer-dist - -PHONY += composer-info -composer-info: ## Composer info - $(call step,Do Composer info...\n) - $(call composer,info) - PHONY += composer-update composer-update: ## Update Composer packages $(call step,Do Composer update...\n) @@ -14,19 +6,13 @@ composer-update: ## Update Composer packages PHONY += composer-install composer-install: ## Install Composer packages $(call step,Do Composer install...\n) - $(call composer,install$(if $(filter production,$(ENV)), $(COMPOSER_PROD_FLAGS),)) + $(call composer,install) PHONY += composer-outdated composer-outdated: ## Show outdated Composer packages $(call step,Show outdated Composer packages...\n) $(call composer,outdated --direct) -ifeq ($(RUN_ON),docker) -define composer - $(call docker_compose_exec,composer --ansi$(if $(filter $(COMPOSER_JSON_PATH),.),, --working-dir=$(COMPOSER_JSON_PATH)) $(1)) -endef -else define composer - @composer --ansi$(if $(filter $(COMPOSER_JSON_PATH),.),, --working-dir=$(COMPOSER_JSON_PATH)) $(1) + $(call docker_compose_exec,composer $(1)) endef -endif diff --git a/tools/make/docker.mk b/tools/make/docker.mk index 4367e2df..5fd10595 100644 --- a/tools/make/docker.mk +++ b/tools/make/docker.mk @@ -1,26 +1,3 @@ -CLI_SERVICE := app -CLI_SHELL := sh -# Note: specification says this file would be compose.yaml -DOCKER_COMPOSE_YML_PATH ?= compose.yaml -DOCKER_COMPOSE_YML_EXISTS := $(shell test -f $(DOCKER_COMPOSE_YML_PATH) && echo yes || echo no) -DOCKER_ENV := $(shell test -f /.dockerenv && echo yes || echo no) -DOCKER_PROJECT_ROOT ?= /app -DOCKER_WARNING_INSIDE := You are inside the Docker container! - -ifeq ($(DOCKER_ENV),yes) - RUN_ON := host -endif - -# If compose.yaml exists -ifeq ($(DOCKER_ENV)-$(DOCKER_COMPOSE_YML_EXISTS),no-yes) - RUN_ON := docker -endif - -PHONY += config -config: ## Show docker-compose config - $(call step,Show Docker Compose config...\n) - $(call docker_compose,config) - PHONY += pull pull: ## Pull docker images $(call step,Pull the latest docker images...\n) @@ -48,43 +25,13 @@ up: ## Launch the environment PHONY += shell shell: ## Login to CLI container -ifeq ($(RUN_ON),docker) - $(call docker_compose,exec $(CLI_SERVICE) $(CLI_SHELL)) -else - $(call warn,$(DOCKER_WARNING_INSIDE)) -endif + $(call docker_compose,exec app bash) -PHONY += ssh-check -ssh-check: ## Check SSH keys on CLI container - $(call docker_compose_exec,ssh-add -L) - -ifeq ($(RUN_ON),docker) -define docker - @docker $(1) > /dev/null 2>&1 && $(if $(2),echo "$(2)",) -endef -else -define docker - $(call sub_step,$(DOCKER_WARNING_INSIDE)) -endef -endif - -ifeq ($(RUN_ON),docker) -define docker_compose_exec - $(call docker_compose,exec$(if $(CLI_USER), -u $(CLI_USER),) $(CLI_SERVICE) $(CLI_SHELL) -c "$(1)") - $(if $(2),@echo "$(2)",) -endef -else define docker_compose_exec - @$(1) && echo $(2) + $(call docker_compose,exec app bash -c "$(1)") endef -endif -ifeq ($(RUN_ON),docker) define docker_compose - @docker compose$(if $(filter $(DOCKER_COMPOSE_YML_PATH),$(DOCKER_COMPOSE_YML_PATH)),, -f $(DOCKER_COMPOSE_YML_PATH)) $(1) + @docker compose $(1) endef -else -define docker_compose - $(call sub_step,$(DOCKER_WARNING_INSIDE)) -endef -endif + diff --git a/tools/make/drupal.mk b/tools/make/drupal.mk index 059237a4..5af190c1 100644 --- a/tools/make/drupal.mk +++ b/tools/make/drupal.mk @@ -1,59 +1,14 @@ -BUILD_TARGETS += drupal-create-folders +DUMP_SQL_EXISTS := $(shell test -f dump.sql && echo yes || echo no) DRUPAL_CONF_EXISTS := $(shell test -f conf/cmi/core.extension.yml && echo yes || echo no) -DRUPAL_FRESH_TARGETS := up build sync post-install -DRUPAL_NEW_TARGETS := up build drush-si drush-uli -DRUPAL_POST_INSTALL_TARGETS := drush-deploy -CLEAN_EXCLUDE += $(WEBROOT)/sites/default/files -DRUPAL_DISABLE_MODULES ?= no -DRUPAL_ENABLE_MODULES ?= no -DRUPAL_PROFILE ?= minimal -DRUPAL_SITE_EMAIL ?= maintenance@druid.fi -DRUPAL_SYNC_FILES ?= yes -DRUPAL_SYNC_SOURCE ?= main -DRUSH_RSYNC_MODE ?= Pakzu -DRUSH_RSYNC_OPTS ?= -- --omit-dir-times --no-perms --no-group --no-owner --chmod=ugo=rwX -DRUSH_RSYNC_EXCLUDE ?= css:ctools:js:php:tmp:tmp_php -SYNC_TARGETS += drush-sync -SYNC_FROM_REMOTE ?= no -CS_EXTS := inc,php,module,install,profile,theme -CS_STANDARD_PATHS := vendor/drupal/coder/coder_sniffer,vendor/slevomat/coding-standard -CS_STANDARDS := Drupal,DrupalPractice -LINT_PATHS_JS += ./$(WEBROOT)/modules/custom/*/js -LINT_PATHS_JS += ./$(WEBROOT)/themes/custom/*/js -LINT_PATHS_PHP += drush -LINT_PATHS_PHP += $(WEBROOT)/modules/custom -LINT_PATHS_PHP += $(WEBROOT)/themes/custom -LINT_PHP_TARGETS += lint-drupal -FIX_TARGETS += fix-drupal -DRUPAL_CREATE_FOLDERS := $(WEBROOT)/sites/default/files/private -DRUPAL_CREATE_FOLDERS += $(WEBROOT)/sites/default/files/translations - -ifeq ($(LAGOON),yes) - SYNC_FROM_REMOTE := yes -endif - -ifeq ($(GH_DUMP_ARTIFACT),yes) - DRUPAL_FRESH_TARGETS := gh-download-dump $(DRUPAL_FRESH_TARGETS) -endif -ifneq ($(DRUPAL_DISABLE_MODULES),no) - SYNC_TARGETS += drush-disable-modules -endif - -ifneq ($(DRUPAL_ENABLE_MODULES),no) - DRUPAL_POST_INSTALL_TARGETS += drush-enable-modules -endif +DRUPAL_CREATE_FOLDERS := /app/public/sites/default/files/private +DRUPAL_CREATE_FOLDERS += /app/public/sites/default/files/translations PHONY += drupal-create-folders drupal-create-folders: $(call step,Create folders for Drupal...\n) $(call docker_compose_exec,mkdir -v -p $(DRUPAL_CREATE_FOLDERS)) -PHONY += drupal-update -drupal-update: ## Update Drupal core with Composer - $(call step,Update Drupal core with Composer...\n) - $(call composer,update -W "drupal/core-*") - PHONY += drush-cex drush-cex: ## Export configuration $(call step,Export configuration...\n) @@ -78,7 +33,7 @@ drush-uli: DRUPAL_UID ?= drush-uli: DRUPAL_DESTINATION ?= admin/reports/status drush-uli: ## Get login link $(call step,Login to your site with:\n) - $(call drush,uli$(if $(DRUPAL_UID), --uid=$(DRUPAL_UID),) $(DRUPAL_DESTINATION)) + $(call drush,uli $(DRUPAL_DESTINATION)) PHONY += drush-uli-% drush-uli-%: ## Get login link for provided uid @@ -93,7 +48,7 @@ else endif drush-si: ## Site install $(call step,Do Drush site:install...\n) - $(call drush,si ${DRUSH_SI} --site-mail=$(DRUPAL_SITE_EMAIL)) + $(call drush,si ${DRUSH_SI}) PHONY += drush-deploy drush-deploy: ## Run Drush deploy @@ -113,69 +68,47 @@ drush-reset-local: ## Reset local configuration (cim, cr, updb, cr) $(call drush,updb -y --no-cache-clear) $(call drush,cr) +PHONY += drush-unblock +drush-unblock: ## Get login link + $(call step,Unblocking helfi-admin...\n) + $(call drush,user:unblock --uid=1) + +PHONY += drush-locale-update +drush-locale-update: drupal-create-folders ## Update translations. + $(call step,Update translations...) + $(call drush,state:set locale.translation_last_checked 0) + $(call drush,locale:check) + $(call drush,locale:update) + $(call drush,cr) + +DRUPAL_POST_INSTALL_TARGETS := drush-sanitize-database drush-deploy drush-locale-update drush-unblock drush-uli + +DRUPAL_FRESH_TARGETS := up drupal-create-folders composer-install drush-import-dump $(DRUPAL_POST_INSTALL_TARGETS) PHONY += fresh -fresh: ## Build fresh development environment and sync - @$(MAKE) $(DRUPAL_FRESH_TARGETS) +fresh: $(DRUPAL_FRESH_TARGETS) ## Build fresh development environment and sync +DRUPAL_NEW_TARGETS := up drupal-create-folders composer-install drush-si $(DRUPAL_POST_INSTALL_TARGETS) PHONY += new -new: ## Create a new empty Drupal installation from configuration - @$(MAKE) $(DRUPAL_NEW_TARGETS) - -PHONY += post-install -post-install: ## Run post-install Drush actions - @$(MAKE) $(DRUPAL_POST_INSTALL_TARGETS) drush-uli - -PHONY += drush-disable-modules -drush-disable-modules: ## Disable Drupal modules - $(call step,Disable Drupal modules...\n) -ifneq ($(DRUPAL_DISABLE_MODULES),no) - $(call drush,pmu -y $(subst ",,$(DRUPAL_DISABLE_MODULES))) -else - $(call sub_step,No modules to disable) -endif +new: $(DRUPAL_NEW_TARGETS) ## Create a new empty Drupal installation from configuration -PHONY += drush-enable-modules -drush-enable-modules: ## Enable Drupal modules - $(call step,Enable Drupal modules...\n) -ifneq ($(DRUPAL_ENABLE_MODULES),no) - $(call drush,en -y $(subst ",,$(DRUPAL_ENABLE_MODULES))) -else - $(call sub_step,No modules to enable) -endif - -PHONY += drush-sync -drush-sync: drush-sync-db drush-sync-files ## Sync database and files +dump.sql: + @touch /tmp/kube-config + @docker run --network host --env-file .env -it --rm -v /tmp/kube-config:/root/.kube/config -v $(shell pwd):/app --name helfi-oc ghcr.io/city-of-helsinki/drupal-oc-cli:latest sh -c "db-sync" + $(call docker_compose_exec,gunzip dump.sql.gz) -PHONY += drush-sync-db -drush-sync-db: ## Sync database +PHONY += drush-import-dump +drush-import-dump: dump.sql $(call drush,sql-drop --quiet -y) -ifeq ($(DUMP_SQL_EXISTS),yes) $(call step,Import local SQL dump...) - $(call drush,sql-query --file=${DOCKER_PROJECT_ROOT}/$(DUMP_SQL_FILENAME) && echo 'SQL dump imported') -else -ifeq ($(SYNC_FROM_REMOTE),yes) - $(call step,Sync database from @$(DRUPAL_SYNC_SOURCE)...) - $(call drush,sql-sync -y --structure-tables-key=common @$(DRUPAL_SYNC_SOURCE) @self) -endif -endif + $(call drush,sql-query --file=/app/dump.sql && echo 'SQL dump imported') -PHONY += drush-sync-files -drush-sync-files: ## Sync files -ifeq ($(DRUPAL_SYNC_FILES),yes) -ifeq ($(SYNC_FROM_REMOTE),yes) - $(call step,Sync files from @$(DRUPAL_SYNC_SOURCE)...) - $(call drush,-y rsync --exclude-paths=$(DRUSH_RSYNC_EXCLUDE) --mode=$(DRUSH_RSYNC_MODE) @$(DRUPAL_SYNC_SOURCE):%files @self:%files $(DRUSH_RSYNC_OPTS)) -endif -endif +PHONY += drush-sanitize-database +drush-sanitize-database: + $(call drush,sql-query \"UPDATE file_managed SET uri = REPLACE(uri, 'azure://', 'public://');\",Fixed Azure URIs) PHONY += drush-create-dump -drush-create-dump: FLAGS := --structure-tables-key=common --extra-dump=--no-tablespaces drush-create-dump: ## Create database dump to dump.sql - $(call drush,sql-dump $(FLAGS) --result-file=${DOCKER_PROJECT_ROOT}/$(DUMP_SQL_FILENAME)) - -PHONY += drush-download-dump -drush-download-dump: ## Download database dump to dump.sql - $(call drush,@$(DRUPAL_SYNC_SOURCE) sql-dump --structure-tables-key=common > ${DOCKER_PROJECT_ROOT}/$(DUMP_SQL_FILENAME)) + $(call drush,sql-dump --structure-tables-key=common --extra-dump=--no-tablespaces --result-file=/app/dump.sql) PHONY += open-db-gui open-db-gui: ## Open database with GUI tool @@ -185,30 +118,6 @@ open-db-gui: ## Open database with GUI tool $(eval DB_PASS ?= drupal) @open mysql://$(DB_USER):$(DB_PASS)@$(shell docker compose port $(DB_SERVICE) 3306 | grep -v ::)/$(DB_NAME) -PHONY += fix-drupal -fix-drupal: PATHS := $(subst $(space),,$(LINT_PATHS_PHP)) -fix-drupal: ## Fix Drupal code style - $(call step,Fix Drupal code style with phpcbf...\n) - $(call cs,phpcbf,$(PATHS)) - -PHONY += lint-drupal -lint-drupal: PATHS := $(subst $(space),,$(LINT_PATHS_PHP)) -lint-drupal: ## Lint Drupal code style - $(call step,Lint Drupal code style with phpcs...\n) - $(call cs,phpcs,$(PATHS)) - -PHONY += mmfix -mmfix: MODULE := MISSING_MODULE -mmfix: - $(call step,Remove missing module '$(MODULE)'\n) - $(call drush,sql-query \"DELETE FROM key_value WHERE collection='system.schema' AND name='$(MODULE)';\",Module was removed) - -ifeq ($(RUN_ON),docker) define drush $(call docker_compose_exec,drush $(1),$(2)) endef -else -define drush - @drush $(1) -endef -endif diff --git a/tools/make/project/git.mk b/tools/make/git.mk similarity index 100% rename from tools/make/project/git.mk rename to tools/make/git.mk diff --git a/tools/make/include.mk b/tools/make/include.mk deleted file mode 100644 index de30c41e..00000000 --- a/tools/make/include.mk +++ /dev/null @@ -1,60 +0,0 @@ -include $(DRUIDFI_TOOLS_MAKE_DIR)common.mk - -ifeq ($(call has,docker),yes) -include $(DRUIDFI_TOOLS_MAKE_DIR)docker.mk -endif - -include $(DRUIDFI_TOOLS_MAKE_DIR)qa.mk - -# -# Apps -# - -IS_DRUPAL ?= $(shell test -f $(WEBROOT)/sites/default/settings.php && echo yes || echo no) -IS_SYMFONY ?= $(shell test -f config/bundles.php && echo yes || echo no) - -ifeq ($(IS_DRUPAL),yes) -include $(DRUIDFI_TOOLS_MAKE_DIR)drupal.mk -endif - -ifeq ($(IS_SYMFONY),yes) -include $(DRUIDFI_TOOLS_MAKE_DIR)symfony.mk -endif - -# -# Other tools -# - -HAS_ANSIBLE ?= $(shell test -d ansible && echo yes || echo no) - -ifeq ($(HAS_ANSIBLE),yes) -include $(DRUIDFI_TOOLS_MAKE_DIR)ansible.mk -endif - -# -# Hosting systems -# - -LAGOON := $(shell test -f .lagoon.yml && echo yes || echo no) - -ifeq ($(LAGOON),yes) - SYSTEM := LAGOON -else - SYSTEM := WHOKNOWS -endif - -ifeq ($(SYSTEM),LAGOON) -include $(DRUIDFI_TOOLS_MAKE_DIR)lagoon.mk -endif - -COMPOSER_JSON_EXISTS := $(shell test -f $(COMPOSER_JSON_PATH)/composer.json && echo yes || echo no) - -ifeq ($(COMPOSER_JSON_EXISTS),yes) -include $(DRUIDFI_TOOLS_MAKE_DIR)composer.mk -endif - -PACKAGE_JSON_EXISTS := $(shell test -f $(PACKAGE_JSON_PATH)/package.json && echo yes || echo no) - -ifeq ($(PACKAGE_JSON_EXISTS),yes) -include $(DRUIDFI_TOOLS_MAKE_DIR)javascript.mk -endif diff --git a/tools/make/javascript.mk b/tools/make/javascript.mk deleted file mode 100644 index 9b8c2fcf..00000000 --- a/tools/make/javascript.mk +++ /dev/null @@ -1,44 +0,0 @@ -BUILD_TARGETS += js-install -JS_PACKAGE_MANAGER ?= yarn -JS_PACKAGE_MANAGER_CWD_FLAG_NPM ?= --prefix -JS_PACKAGE_MANAGER_CWD_FLAG_YARN ?= --cwd -INSTALLED_NODE_VERSION := $(shell command -v node > /dev/null && node --version | cut -c2-3 || echo no) -NVM_SH := $(HOME)/.nvm/nvm.sh -NVM := $(shell test -f "$(NVM_SH)" && echo yes || echo no) -NODE_BIN := $(shell command -v node || echo no) -NPM_BIN := $(shell command -v npm || echo no) -YARN_BIN := $(shell command -v yarn || echo no) -NODE_VERSION ?= 16 - -PHONY += js-install -js-install: ## Install JS packages -ifeq ($(JS_PACKAGE_MANAGER),yarn) - $(call node_run,install --frozen-lockfile) -else - $(call node_run,install --no-audit --no-fund --engine-strict true) -endif - -PHONY += js-outdated -js-outdated: ## Show outdated JS packages - $(call step,Show outdated JS packages with $(JS_PACKAGE_MANAGER)...) - $(call node_run,outdated) - -ifeq ($(NVM),no) -define node_run - $(call error,$(NVM_REQUIRED)) -endef -else -define node_run - $(call step,Run '$(JS_PACKAGE_MANAGER) $(1)' with Node $(NODE_VERSION)...\n) - @. $(NVM_SH) && (nvm which $(NODE_VERSION) > /dev/null 2>&1 || nvm install $(NODE_VERSION)) && \ - nvm exec $(NODE_VERSION) $(JS_PACKAGE_MANAGER) $(if $(filter $(JS_PACKAGE_MANAGER),yarn),$(JS_PACKAGE_MANAGER_CWD_FLAG_YARN),$(JS_PACKAGE_MANAGER_CWD_FLAG_NPM)) $(PACKAGE_JSON_PATH) $(1) -endef -endif - -define NVM_REQUIRED - - -🚫 NVM is required to run $(JS_PACKAGE_MANAGER) commands and control Node versions! - - -endef diff --git a/tools/make/kubectl.mk b/tools/make/kubectl.mk deleted file mode 100644 index 60f5003e..00000000 --- a/tools/make/kubectl.mk +++ /dev/null @@ -1,56 +0,0 @@ -KUBECTL_BIN := $(shell command -v kubectl || echo no) -KUBECTL_NAMESPACE ?= foobar-namespace -KUBECTL_SHELL ?= sh -KUBECTL_EXEC_FLAGS ?= -n $(KUBECTL_NAMESPACE) -c $(KUBECTL_CONTAINER) -KUBECTL_POD_SELECTOR ?= appName=foobar-app -KUBECTL_WORKDIR ?= /app - -PHONY += kubectl-sync-db -kubectl-sync-db: ## Sync database from Kubernetes - $(call drush,sql-drop --quiet -y) -ifeq ($(DUMP_SQL_EXISTS),no) - $(eval POD := $(call kubectl_get_pod)) - $(call step,Get database dump from $(POD)...\n) - $(KUBECTL_BIN) exec $(KUBECTL_EXEC_FLAGS) $(POD) -- drush sql-dump --structure-tables-key=common --extra-dump=--no-tablespaces --result-file=/tmp/$(DUMP_SQL_FILENAME) --gzip - $(KUBECTL_BIN) cp $(KUBECTL_EXEC_FLAGS) --retries=-1 $(POD):/tmp/$(DUMP_SQL_FILENAME).gz ./$(DUMP_SQL_FILENAME).gz - $(KUBECTL_BIN) exec $(KUBECTL_EXEC_FLAGS) $(POD) -- rm -f /tmp/$(DUMP_SQL_FILENAME).gz - @gzip -d $(DUMP_SQL_FILENAME).gz -endif - $(call step,Import local SQL dump...\n) - $(call drush,sql-query --file=${DOCKER_PROJECT_ROOT}/$(DUMP_SQL_FILENAME)) - -PHONY += kubectl-sync-files-tar -kubectl-sync-files-tar: ## Sync files from Kubernetes using tar - $(call step,Copy files from remote...\n) - $(eval POD := $(call kubectl_get_pod)) - $(KUBECTL_BIN) exec $(KUBECTL_EXEC_FLAGS) $(POD) -- tar cf - $(SYNC_FILES_EXCLUDE) $(SYNC_FILES_PATH) | tar xfv - -C . - -PHONY += kubectl-rsync-files -kubectl-rsync-files: FLAGS := -aurP --blocking-io -kubectl-rsync-files: REMOTE_PATH := $(KUBECTL_WORKDIR)/$(SYNC_FILES_PATH)/ -kubectl-rsync-files: LOCAL_PATH := ./$(SYNC_FILES_PATH)/ -kubectl-rsync-files: ## Sync files from Kubernetes using rsync - $(call step,Sync files from remote...\n) - $(eval POD := $(call kubectl_get_pod)) - rsync $(FLAGS) $(SYNC_FILES_EXCLUDE) --rsync-path=$(REMOTE_PATH) -e '$(KUBECTL_BIN) exec -i $(KUBECTL_EXEC_FLAGS) $(POD) -- env ' rsync: $(LOCAL_PATH) - -PHONY += kubectl-shell -kubectl-shell: ## Open shell to Pod in Kubernetes - $(eval POD := $(call kubectl_get_pod)) - $(KUBECTL_BIN) exec $(KUBECTL_EXEC_FLAGS) -ti $(POD) -- $(KUBECTL_SHELL) - -define kubectl_exec - $(KUBECTL_BIN) exec $(KUBECTL_EXEC_FLAGS) $(1) -- $(KUBECTL_SHELL) -c '$(2)' -endef - -define kubectl_exec_to_file - $(KUBECTL_BIN) exec $(KUBECTL_EXEC_FLAGS) $(1) -- $(KUBECTL_SHELL) -c '$(2)' > $(3) -endef - -define kubectl_cp - $(KUBECTL_BIN) cp $(KUBECTL_EXEC_FLAGS) $(1) $(2) -endef - -define kubectl_get_pod - $(shell $(KUBECTL_BIN) get pods -n $(KUBECTL_NAMESPACE) --selector=$(KUBECTL_POD_SELECTOR) --template '{{range .items}}{{ if not .metadata.deletionTimestamp }}{{.metadata.name}}{{"\n"}}{{end}}{{end}}') -endef diff --git a/tools/make/lagoon.mk b/tools/make/lagoon.mk deleted file mode 100644 index e6baebad..00000000 --- a/tools/make/lagoon.mk +++ /dev/null @@ -1,38 +0,0 @@ -CLI_SERVICE := cli -CLI_SHELL := bash -DB_SERVICE := mariadb - -INSTANCE_prod_USER ?= project-name-branch -INSTANCE_prod_HOST ?= ssh.lagoon.amazeeio.cloud -INSTANCE_prod_OPTS ?= $(SSH_OPTS) -p 32222 -t -INSTANCE_test_USER ?= project-name-branch -INSTANCE_test_HOST ?= $(INSTANCE_prod_HOST) -INSTANCE_test_OPTS ?= $(INSTANCE_prod_OPTS) - -ifeq ($(MAKECMDGOALS),set-lagoon-secrets) -include .env.local.lagoon -endif - -PHONY += lagoon-env -lagoon-env: ## Print Lagoon env variables - $(call docker_compose_exec,printenv | grep LAGOON_) - -PHONY += deploy-lagoon-% -deploy-lagoon-%: ## Deploy lagoon branch - $(call step,Deploy Lagoon branch $*...\n) - @lagoon -p $(LAGOON_PROJECT) deploy branch -b $* - -PHONY += set-lagoon-secrets-% -set-lagoon-secrets-%: ## Set Lagoon secrets - $(call step,Set Lagoon secrets on $*...\n) - @$(foreach secret,$(LAGOON_SECRETS),$(call set_lagoon_secret,$(secret),$*)) - -PHONY += list-lagoon-vars-% -list-lagoon-vars-%: ## List variables from Lagoon - $(call step,List variables from Lagoon on $*...\n) - @lagoon -p $(LAGOON_PROJECT) list v --reveal -e $* - -define set_lagoon_secret -printf "Setting secret on ${2}: %s = %s \n" "${1}" "${${1}}"; -lagoon -p $(LAGOON_PROJECT) a v -N "${1}" -V "${${1}}" -S runtime -e ${2} --force || true; -endef diff --git a/tools/make/override.mk b/tools/make/override.mk deleted file mode 100644 index df8baac5..00000000 --- a/tools/make/override.mk +++ /dev/null @@ -1,3 +0,0 @@ -# Docker CLI container -CLI_SERVICE=app -CLI_SHELL=bash diff --git a/tools/make/project/.keepme b/tools/make/project/.keepme deleted file mode 100644 index e69de29b..00000000 diff --git a/tools/make/project/composer.mk b/tools/make/project/composer.mk deleted file mode 100644 index aefdbcc6..00000000 --- a/tools/make/project/composer.mk +++ /dev/null @@ -1,3 +0,0 @@ -PHONY += insert-post-install-hooks - -insert-post-install-hooks: diff --git a/tools/make/project/db-sync.sh b/tools/make/project/db-sync.sh deleted file mode 100644 index 2d69f38e..00000000 --- a/tools/make/project/db-sync.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/sh - -set -e - -if [ ! -n "$OC_PROJECT_NAME" ]; then - echo "OC_PROJECT_NAME not set." - exit 1; -fi - -oc login --token=${1} --server=https://api.arodevtest.hel.fi:6443 -oc project ${OC_PROJECT_NAME} - -OC_POD_NAME=$(oc get pods -o name | grep drupal-cron | grep -v deploy) - -if [ ! -n "$OC_POD_NAME" ]; then - echo "Failed to parse pod name." - exit 1 -fi - -oc rsh $OC_POD_NAME rm -f /tmp/dump.sql -oc rsh $OC_POD_NAME drush sql:dump --structure-tables-key=common \ - --extra-dump='--no-tablespaces --hex-blob' \ - --result-file=/tmp/dump.sql - -oc rsync $OC_POD_NAME:/tmp/dump.sql /app diff --git a/tools/make/project/install.mk b/tools/make/project/install.mk deleted file mode 100644 index 1982e3da..00000000 --- a/tools/make/project/install.mk +++ /dev/null @@ -1,49 +0,0 @@ -ifeq ($(DRUPAL_CONF_EXISTS),yes) - DRUPAL_NEW_TARGETS := up build drush-si drush-cr drush-locale-update drush-helfi-locale-import drush-unblock drush-uli -else - DRUPAL_NEW_TARGETS := up build drush-si drush-helfi-enable-modules drush-locale-update drush-helfi-locale-import drush-unblock drush-uli -endif -DRUPAL_POST_INSTALL_TARGETS := drush-deploy drush-locale-update drush-helfi-locale-import drush-unblock - -OC_LOGIN_TOKEN ?= $(shell bash -c 'read -s -p "You must obtain an API token by visiting https://oauth-openshift.apps.arodevtest.hel.fi/oauth/token/request (Token):" token; echo $$token') - -SYNC_TARGETS := drush-sync-db - -ifneq ($(DUMP_SQL_EXISTS),yes) -SYNC_TARGETS := oc-sync -endif - -PHONY += oc-sync -oc-sync: - @docker run --env-file .env -it --rm -v $(shell pwd):/app --name helfi-oc ghcr.io/city-of-helsinki/drupal-oc-cli:latest sh -c "chmod +x /app/tools/make/project/db-sync.sh && /app/tools/make/project/db-sync.sh $(OC_LOGIN_TOKEN)" - $(call drush,sql-query --file=${DOCKER_PROJECT_ROOT}/$(DUMP_SQL_FILENAME),SQL dump imported) - $(call drush,sql-query \"UPDATE file_managed SET uri = REPLACE(uri, 'azure://', 'public://');\",Sanitized Azure URIs) - $(call drush,cr) - $(call drush,cim -y) - $(call drush,cr) - -PHONY += drush-helfi-enable-modules -drush-helfi-enable-modules: ## Enable modules and base configurations. - $(call step,Install base configurations...) - $(call drush,cr) - $(call drush,en -y helfi_platform_config helfi_platform_config_base) - -PHONY += drush-locale-update -drush-locale-update: ## Update translations. - $(call step,Update translations...) - @mkdir -p public/sites/default/files/translations - $(call drush,state:set locale.translation_last_checked 0) - $(call drush,locale:check) - $(call drush,locale:update) - $(call drush,cr) - -PHONY += drush-helfi-locale-import -drush-helfi-locale-import: ## Update translations from helfi platform config. - $(call step,Import helfi platform config translations...) - $(call drush,helfi:locale-import helfi_platform_config) - $(call drush,cr) - -PHONY += drush-unblock -drush-unblock: ## Get login link - $(call step,Unblocking helfi-admin...\n) - $(call drush,user:unblock --uid=1) diff --git a/tools/make/qa.mk b/tools/make/qa.mk index f4988fbe..4a9427e1 100644 --- a/tools/make/qa.mk +++ b/tools/make/qa.mk @@ -1,73 +1,33 @@ -TEST_TARGETS += test-phpunit -FIX_TARGETS := -LINT_PHP_TARGETS := -CS_INSTALLED := $(shell test -f $(COMPOSER_JSON_PATH)/vendor/bin/phpcs && echo yes || echo no) -CS_CONF_EXISTS := $(shell test -f phpcs.xml.dist && echo yes || echo no) -TESTSUITES ?= unit,kernel,functional +LINT_PHP_STANDARDS := Drupal,DrupalPractice +LINT_PHP_EXTENSIONS := inc,php,module,install,profile,theme + +LINT_PATHS_PHP := /app/public/modules/custom +LINT_PATHS_PHP += /app/public/themes/custom PHONY += fix -fix: ## Fix code style - $(call step,Fix code...) - $(call sub_step,Following targets will be run: $(FIX_TARGETS)) - @$(MAKE) $(FIX_TARGETS) +fix: fix-php ## Fix code style -PHONY += lint -lint: lint-php lint-js ## Check code style +PHONY += fix-php +fix-php: + $(call step,Fix code using phpcbf ($(LINT_PATHS_PHP))...) + $(call cs,phpcbf) -PHONY += lint-js -lint-js: DOCKER_NODE_IMG ?= node:$(NODE_VERSION)-alpine -lint-js: WD := /app -lint-js: ## Check code style for JS files - $(call step,Install linters...) - @docker run --rm -v "$(CURDIR)":$(WD):cached -w $(WD) $(DOCKER_NODE_IMG) yarn --cwd $(WEBROOT)/core install - $(call step,Check code style for JS files: $(DRUPAL_LINT_PATHS)) - @docker run --rm -v "$(CURDIR)":$(WD):cached -w $(WD) $(DOCKER_NODE_IMG) \ - $(WEBROOT)/core/node_modules/eslint/bin/eslint.js --color --ignore-pattern '**/vendor/*' \ - --c ./$(WEBROOT)/core/.eslintrc.json --global nav,moment,responsiveNav:true $(LINT_PATHS_JS) +PHONY += lint +lint: lint-php ## Check code style PHONY += lint-php lint-php: ## Check code style for PHP files - $(call step,Check code style for PHP files...) - $(call sub_step,Following targets will be run: $(LINT_PHP_TARGETS)) - @$(MAKE) $(LINT_PHP_TARGETS) - $(call test_result,lint-php,"[OK]") + $(call step,Check code style for PHP files ($(LINT_PATHS_PHP))...) + $(call cs,phpcs) PHONY += test -test: ## Run tests - $(call group_step,Run test targets:${NO_COLOR} $(TEST_TARGETS)\n) - @$(MAKE) $(TEST_TARGETS) - $(call step,Tests completed.) +test: test-phpunit ## Run tests PHONY += test-phpunit test-phpunit: ## Run PHPUnit tests $(call step,Run PHPUnit tests...) -ifeq ($(CI),true) - vendor/bin/phpunit -c phpunit.xml.dist --testsuite $(TESTSUITES) -else - $(call docker_compose_exec,${DOCKER_PROJECT_ROOT}/vendor/bin/phpunit -c $(DOCKER_PROJECT_ROOT)/phpunit.xml.dist \ - --testsuite $(TESTSUITES)) -endif - $(call test_result,test-phpunit,"[OK]") - -PHONY += test-phpunit-locally -test-phpunit-locally: - @SIMPLETEST_BASE_URL=https://$(DRUPAL_HOSTNAME) SIMPLETEST_DB=mysql://$(DB_URL) \ - vendor/bin/phpunit -c $(CURDIR)/phpunit.xml.dist --testsuite $(TESTSUITES) - -define test_result - @echo "\n${YELLOW}${1}:${NO_COLOR} ${GREEN}${2}${NO_COLOR}" -endef + $(call docker_compose_exec,/app/vendor/bin/phpunit -c /app/phpunit.xml.dist $(1)) -ifeq ($(CS_INSTALLED)-$(CS_CONF_EXISTS),yes-yes) -define cs -$(call docker_compose_exec,vendor/bin/$(1)) -endef -else ifeq ($(CS_INSTALLED)-$(CS_CONF_EXISTS),yes-no) -define cs -$(call docker_compose_exec,vendor/bin/$(1) --standard=$(CS_STANDARDS) --extensions=$(CS_EXTS) --ignore=node_modules $(2)) -endef -else define cs -$(call warn,CodeSniffer is not installed!) + $(call docker_compose_exec,vendor/bin/$(1) --standard=$(LINT_PHP_STANDARDS) --extensions=$(LINT_PHP_EXTENSIONS) --ignore=node_modules $(LINT_PATHS_PHP)) endef -endif diff --git a/tools/make/symfony.mk b/tools/make/symfony.mk deleted file mode 100644 index 73672075..00000000 --- a/tools/make/symfony.mk +++ /dev/null @@ -1,78 +0,0 @@ -SF_FRESH_TARGETS := up build sf-cw sf-about sf-open -FIX_TARGETS += fix-symfony -LINT_PHP_TARGETS += lint-symfony -CS_FIXER_INSTALLED := $(shell test -f $(COMPOSER_JSON_PATH)/vendor/bin/php-cs-fixer && echo yes || echo no) - -PHONY += encore-dev -encore-dev: ## Do Encore development build - $(call step,Do Encore development build...) - $(call node_run,dev) - -PHONY += encore-watch -encore-watch: ## Run Encore watch - $(call step,Do Encore watch...) - $(call node_run,watch) - -PHONY += sf-about -sf-about: ## Displays information about the current project - $(call sf_console,about) - -PHONY += sf-cc -sf-cc: ## Clear Symfony caches - $(call step,Clear Symfony caches...) - $(call sf_console,cache:clear) - -PHONY += sf-cw -sf-cw: ## Warm Symfony caches - $(call step,Warm Symfony caches...) - $(call sf_console,cache:warmup) - -PHONY += sf-db-init -sf-db-init: ## Setup database schema and load fixtures - $(call step,Setup database schema...) - $(call sf_console,doctrine:schema:update --force) - $(call sf_console,doctrine:fixtures:load -n) - -PHONY += sf-open -sf-open: ## Warm Symfony caches - $(call step,See your Symfony application with:\n) - $(call output,https://$(APP_HOST)) - -PHONY += sf-update -sf-update: ## Update Symfony packages with Composer - $(call step,Update Symfony packages with Composer...\n) - $(call composer,update -W "doctrine/*" "symfony/*" "twig/*" --no-scripts) - -PHONY += fresh -fresh: ## Build fresh development environment - @$(MAKE) $(SF_FRESH_TARGETS) - -PHONY += fix-symfony -fix-symfony: ## Fix Symfony code style - $(call step,Fix Symfony code style...\n) - $(call cs_symfony,fix --ansi src) - -PHONY += lint-symfony -lint-symfony: ## Lint Symfony code style - $(call step,Lint Symfony code style...\n) - $(call cs_symfony,fix --dry-run --diff --ansi --verbose src) - -ifeq ($(RUN_ON),docker) -define sf_console - $(call docker_compose_exec,bin/console $(1)) -endef -else -define sf_console - @bin/console $(1) -endef -endif - -ifeq ($(CS_FIXER_INSTALLED),yes) -define cs_symfony -$(call docker_compose_exec,vendor/bin/php-cs-fixer $(1)) -endef -else -define cs_symfony -$(call warn,PHP CS Fixer is not installed!) -endef -endif diff --git a/tools/make/project/theme.mk b/tools/make/theme.mk similarity index 98% rename from tools/make/project/theme.mk rename to tools/make/theme.mk index fd34d5d1..2657775c 100644 --- a/tools/make/project/theme.mk +++ b/tools/make/theme.mk @@ -1,4 +1,4 @@ -DEFAULT_NODE_VERSION ?= 18 +DEFAULT_NODE_VERSION ?= 20 NODE_DOCKER_RUN_EXTRA_ARGS ?= -it ifeq ($(CI),true) diff --git a/tools/make/utils.mk b/tools/make/utils.mk deleted file mode 100644 index 0feb372a..00000000 --- a/tools/make/utils.mk +++ /dev/null @@ -1,74 +0,0 @@ -# Colors -NO_COLOR=\033[0m -CYAN=\033[36m -GREEN=\033[0;32m -RED=\033[0;31m -YELLOW=\033[0;33m - -PHONY += help -help: ## List all make commands - $(call step,Available make commands:\n) - @cat $(MAKEFILE_LIST) | grep -e "^[a-zA-Z_\-]*: *.*## *" | awk 'BEGIN {FS = ":.*?## "}; {printf "${CYAN}%-30s${NO_COLOR} %s\n", $$1, $$2}' | sort - -PHONY += lt -lt: ## Open localtunnel -ifeq ($(shell command -v lt || echo no),no) - $(call warn,Install localtunnel with: ${YELLOW}npm install -g localtunnel${NO_COLOR}) -else - $(call step,Open localtunnel. Use CTRL+C to close localtunnel.\n) - @lt --port 443 --subdomain $(COMPOSE_PROJECT_NAME) --local-https --allow-invalid-cert -endif - -define dbg - @printf "${GREEN}${1}:${NO_COLOR} ${2}\n" -endef - -define group_step - @printf "\n🌟 ${YELLOW}${1}${NO_COLOR}\n" -endef - -define has -$(shell command -v ${1} > /dev/null 2>&1 && echo yes || echo no) -endef - -define step - @printf "\n⭐ ${YELLOW}${1}${NO_COLOR}\n" -endef - -define sub_step - @printf "\n ${YELLOW}${1}${NO_COLOR}\n" -endef - -define output - @echo "${1}" -endef - -define warn - @printf "\n⚠️ ${1}\n\n" -endef - -define copy - $(call output,Copy $(1) >> $(2)) - @cp $(1) $(2) -endef - -SED_Darwin := sed -i '' -SED_Linux := sed -i - -define get_port -$(shell netstat -aln|awk '$$6=="LISTEN"{if($$4~"[.:][0-9]+$$"){split($$4,a,/[:.]/);p2=a[length(a)];p[p2]=1;}}END{for(i=3000;i<3999&&p[i];i++){};if(i==3999){exit 1};print i}') -endef - -define replace_string - $(call output,Replace $(1) >> $(2) in $(3)) - @$(SED_$(UNAME_S)) 's/$(1)/$(2)/g' $(3) -endef - -define remove_string - $(call output,Remove $(1) from $(2)) - @$(SED_$(UNAME_S)) '/$(1)/d' $(2) -endef - -define run - @${1} && printf "${2}\n" || (printf "${RED}${3}${NO_COLOR}\n" && exit 1) -endef