Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
147 lines (116 loc) · 4.77 KB
/
Copy pathMakefile
File metadata and controls
147 lines (116 loc) · 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
### Defensive settings for make:
# https://tech.davis-hansson.com/p/make/
SHELL:=bash
.ONESHELL:
.SHELLFLAGS:=-xeu -o pipefail -O inherit_errexit -c
.SILENT:
.DELETE_ON_ERROR:
MAKEFLAGS+=--warn-undefined-variables
MAKEFLAGS+=--no-builtin-rules
# We like colors
# From: https://coderwall.com/p/izxssa/colored-makefile-for-golang-projects
RED=`tput setaf 1`
GREEN=`tput setaf 2`
RESET=`tput sgr0`
YELLOW=`tput setaf 3`
# Python checks
PYTHON?=python3
# installed?
ifeq (, $(shell which $(PYTHON) ))
$(error "PYTHON=$(PYTHON) not found in $(PATH)")
endif
# version ok?
PYTHON_VERSION_MIN=3.10
PYTHON_VERSION_OK=$(shell $(PYTHON) -c "import sys; print((int(sys.version_info[0]), int(sys.version_info[1])) >= tuple(map(int, '$(PYTHON_VERSION_MIN)'.split('.'))))")
ifeq ($(PYTHON_VERSION_OK),0)
$(error "Need python $(PYTHON_VERSION) >= $(PYTHON_VERSION_MIN)")
endif
BACKEND_FOLDER=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
GIT_FOLDER=$(BACKEND_FOLDER)/.git
VENV_FOLDER=$(BACKEND_FOLDER)/.venv
BIN_FOLDER=$(VENV_FOLDER)/bin
DOCKER_COMPOSE=docker compose -f $(BACKEND_FOLDER)/tests/docker-compose.yml
all: build
# Add the following 'help' target to your Makefile
# And add help text after each target name starting with '\#\#'
.PHONY: help
help: ## This help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
$(BIN_FOLDER)/pip $(BIN_FOLDER)/tox $(BIN_FOLDER)/pipx $(BIN_FOLDER)/uv $(BIN_FOLDER)/mxdev:
@echo "$(GREEN)==> Setup Virtual Env$(RESET)"
$(PYTHON) -m venv $(VENV_FOLDER)
$(BIN_FOLDER)/pip install -U "pip" "uv" "wheel" "pipx" "tox" "pre-commit"
if [ -d $(GIT_FOLDER) ]; then $(BIN_FOLDER)/pre-commit install; else echo "$(RED) Not installing pre-commit$(RESET)";fi
instance/etc/zope.ini: $(BIN_FOLDER)/pip ## Create instance configuration
@echo "$(GREEN)==> Create instance configuration$(RESET)"
$(BIN_FOLDER)/pipx run cookiecutter -f --no-input --config-file instance.yaml gh:plone/cookiecutter-zope-instance
.PHONY: config
config: instance/etc/zope.ini
.PHONY: build-dev
build-dev: config ## Install Plone packages
@echo "$(GREEN)==> Setup Build$(RESET)"
$(BIN_FOLDER)/pipx run mxdev -c mx.ini
VIRTUAL_ENV=.venv $(BIN_FOLDER)/uv pip install -r requirements-mxdev.txt
.PHONY: install
install: build-dev ## Install Plone
.PHONY: build
build: build-dev ## Install Plone
.PHONY: clean
clean: ## Clean environment
@echo "$(RED)==> Cleaning environment and build$(RESET)"
rm -rf $(VENV_FOLDER) pyvenv.cfg .installed.cfg instance/etc .tox .venv .pytest_cache
.PHONY: remove-data
remove-data: ## Remove all content
@echo "$(RED)==> Removing all content$(RESET)"
rm -rf $(VENV_FOLDER) instance/var
.PHONY: start
start: ## Start a Plone instance on localhost:8080
PYTHONWARNINGS=ignore $(BIN_FOLDER)/runwsgi instance/etc/zope.ini
.PHONY: console
console: instance/etc/zope.ini ## Start a console into a Plone instance
PYTHONWARNINGS=ignore $(BIN_FOLDER)/zconsole debug instance/etc/zope.conf
.PHONY: create-site
create-site: instance/etc/zope.ini ## Create a new site from scratch
PYTHONWARNINGS=ignore $(BIN_FOLDER)/zconsole run instance/etc/zope.conf ./scripts/create_site.py
.PHONY: check
check: $(BIN_FOLDER)/tox ## Check and fix code base according to Plone standards
@echo "$(GREEN)==> Format codebase$(RESET)"
$(BIN_FOLDER)/tox -e lint
# i18n
$(BIN_FOLDER)/i18ndude: $(BIN_FOLDER)/pip
@echo "$(GREEN)==> Install translation tools$(RESET)"
VIRTUAL_ENV=.venv $(BIN_FOLDER)/uv pip install i18ndude
.PHONY: i18n
i18n: $(BIN_FOLDER)/i18ndude ## Update locales
@echo "$(GREEN)==> Updating locales$(RESET)"
$(BIN_FOLDER)/update_locale
# Docker
.PHONY: docker-start
docker-start: ## Start test services (Keycloak + DB) in background
@echo "$(GREEN)==> Starting test services$(RESET)"
$(DOCKER_COMPOSE) up -d
@echo "$(GREEN)==> Waiting for Keycloak to be ready$(RESET)"
@n=0; until curl -sf http://localhost:8180/realms/imio/.well-known/openid-configuration > /dev/null; do \
n=$$((n+1)); [ $$n -ge 30 ] && echo "Keycloak did not become ready in time" && exit 1; \
sleep 2; \
done
.PHONY: docker-stop
docker-stop: ## Stop test services
@echo "$(RED)==> Stopping test services$(RESET)"
$(DOCKER_COMPOSE) down
.PHONY: docker-logs
docker-logs: ## Show test services logs
$(DOCKER_COMPOSE) logs -f
.PHONY: docker-status
docker-status: ## Show test services status
$(DOCKER_COMPOSE) ps
# Tests
.PHONY: test
test: $(BIN_FOLDER)/tox ## run tests
$(BIN_FOLDER)/tox -e test
.PHONY: test-coverage
test-coverage: $(BIN_FOLDER)/tox ## run tests with coverage
$(BIN_FOLDER)/tox -e coverage
## Add bobtemplates features (check bobtemplates.plone's documentation to get the list of available features)
add: $(BIN_FOLDER)/pipx
$(BIN_FOLDER)/pipx run plonecli add -b .mrbob.ini $(filter-out $@,$(MAKECMDGOALS))