-
-
Notifications
You must be signed in to change notification settings - Fork 144
/
Makefile
266 lines (215 loc) · 9.83 KB
/
Makefile
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#
# expected variables in the CI environment
# - REGISTRY_URL = url of the docker registry
STAGE=build
#-------- git
BRANCH:=$(shell git rev-parse --abbrev-ref HEAD)
BUILDID=$(shell date +"%Y%m%d%H%M")
COMMITID=$(shell git rev-parse --short HEAD)
COMMIT_NUMBER=$(shell git rev-list --count HEAD)
#------- versions
LIZMAP_VERSION:=$(shell sed -n 's:.*<version[^>]*>\(.*\)</version>.*:\1:p' lizmap/project.xml)
LTR:=$(shell sed -n 's:.* ltr="\([^"]*\)".*:\1:p' lizmap/project.xml)
STABLE_VERSION=$(firstword $(subst -, ,$(LIZMAP_VERSION)))
PRERELEASE_VERSION=$(word 2,$(subst -, ,$(LIZMAP_VERSION)))
MAJOR_VERSION=$(firstword $(subst ., ,$(STABLE_VERSION)))
MINOR_VERSION=$(word 2,$(subst ., ,$(STABLE_VERSION)))
PATCH_VERSION=$(word 3,$(subst ., ,$(STABLE_VERSION)))
SHORT_VERSION=$(MAJOR_VERSION).$(MINOR_VERSION)
SHORT_VERSION_NAME=$(MAJOR_VERSION)_$(MINOR_VERSION)
DATE_VERSION=$(shell date +%Y-%m-%d)
LATEST_RELEASE=$(shell git branch -a | grep -Po "(release_\\d+_\\d+)" | sort | tail -n1 | cut -d'_' -f 2,3)
ifdef DO_RELEASE
ifeq ($(PRERELEASE_VERSION),)
# if we release a stable version, we tag the docker image with version and the short version
# and optionally with an ltr tag if this is an ltr version
DOCKER_MANIFEST_VERSION=$(STABLE_VERSION)
DOCKER_MANIFEST_VERSION_SHORT=$(SHORT_VERSION)
ifneq ($(LTR),)
DOCKER_MANIFEST_RELEASE_TAG=ltr-$(SHORT_VERSION)
# compatibility with some scripts?
RELEASE_TAG=ltr-$(SHORT_VERSION)
endif
else
# if we release an unstable version, just tag the docker image with the full version
DOCKER_MANIFEST_VERSION=$(LIZMAP_VERSION)
endif
else
# we don't do a release, we tag the docker image with the -dev label
DOCKER_MANIFEST_VERSION=$(SHORT_VERSION)-dev
endif
SAAS_LIZMAP_VERSION=$(LIZMAP_VERSION).$(COMMIT_NUMBER)
#-------- Packages names
PACKAGE_NAME=lizmap-web-client-$(LIZMAP_VERSION)
DEMO_PACKAGE_NAME=lizmapdemo-module-$(MAJOR_VERSION).$(MINOR_VERSION)
ZIP_PACKAGE=$(STAGE)/$(PACKAGE_NAME).zip
ZIP_DEMO_PACKAGE=$(STAGE)/$(DEMO_PACKAGE_NAME).zip
GENERIC_DIR_NAME=lizmap_web_client
GENERIC_PACKAGE_DIR=$(STAGE)/$(GENERIC_DIR_NAME)
GENERIC_PACKAGE_ZIP=$(GENERIC_DIR_NAME).zip
GENERIC_PACKAGE_PATH=$(STAGE)/$(GENERIC_PACKAGE_ZIP)
#-------- Docker
DOCKER_NAME=lizmap-web-client
DOCKER_BUILDIMAGE=3liz/$(DOCKER_NAME):$(LIZMAP_VERSION)-$(COMMITID)
DOCKER_ARCHIVENAME=$(shell echo $(DOCKER_NAME):$(LIZMAP_VERSION)|tr '[:./]' '_')
DOCKER_BUILD_ARGS=
DOCKER_MANIFEST=docker/factory.manifest
DOCKER_RELEASE_PACKAGE_NAME=$(DOCKER_NAME)-$(MAJOR_VERSION).$(MINOR_VERSION)
REGISTRY_URL ?= 3liz
REGISTRY_PREFIX=$(REGISTRY_URL)/
BUILD_ARGS += --build-arg REGISTRY_PREFIX=$(REGISTRY_PREFIX)
#-------- build
DIST=$(STAGE)/$(PACKAGE_NAME)
FILES=lizmap CONTRIBUTING.md icon.png INSTALL.md license.txt README.md UPGRADE.md
FORBIDDEN_CONFIG_FILES := installer.ini.php installer.bak.ini.php liveconfig.ini.php localframework.ini.php localurls.xml lizmapConfig.ini.php localconfig.ini.php profiles.ini.php
EMPTY_DIRS := var/db var/log var/mails var/uploads var/sessions var/lizmap-theme-config/ var/themes/default
.PHONY: debug build tests clean check-release check-registry stage package deploy_download deploy_download_stable saas_package saas_release
.PHONY: docker-build docker-build-ci docker-tag docker-deliver docker-clean docker-clean-all docker-release docker-hub docker-run
debug:
@echo "LIZMAP_VERSION="$(LIZMAP_VERSION)
@echo "LTR="$(LTR)
@echo "MAJOR_VERSION="$(MAJOR_VERSION)
@echo "MINOR_VERSION="$(MINOR_VERSION)
@echo "PATCH_VERSION="$(PATCH_VERSION)
@echo "PRERELEASE_VERSION="$(PRERELEASE_VERSION)
@echo "STABLE_VERSION="$(STABLE_VERSION)
@echo "SHORT_VERSION="$(SHORT_VERSION)
@echo "SHORT_VERSION_NAME="$(SHORT_VERSION_NAME)
@echo "DATE_VERSION="$(DATE_VERSION)
@echo "DOCKER_MANIFEST_VERSION="$(DOCKER_MANIFEST_VERSION)
ifdef DOCKER_MANIFEST_VERSION_SHORT
@echo "DOCKER_MANIFEST_VERSION_SHORT="$(DOCKER_MANIFEST_VERSION_SHORT)
endif
ifdef DOCKER_MANIFEST_RELEASE_TAG
@echo "DOCKER_MANIFEST_RELEASE_TAG="$(DOCKER_MANIFEST_RELEASE_TAG)
endif
@echo "SAAS_LIZMAP_VERSION="$(SAAS_LIZMAP_VERSION)
@echo "PACKAGE_NAME="$(PACKAGE_NAME)
@echo "GENERIC_PACKAGE_PATH="$(GENERIC_PACKAGE_PATH)
@echo "BRANCH="$(BRANCH)
@echo "BUILDID="$(BUILDID)
@echo "COMMITID="$(COMMITID)
@echo "ZIP_PACKAGE="$(ZIP_PACKAGE)
@echo "GENERIC_PACKAGE_DIR="$(GENERIC_PACKAGE_DIR)
@echo "ZIP_DEMO_PACKAGE="$(ZIP_DEMO_PACKAGE)
@echo "COMMIT_NUMBER="$(COMMIT_NUMBER)
build: debug
composer update --working-dir=lizmap/ --prefer-dist --no-ansi --no-interaction --no-dev --no-suggest --no-progress
cd assets/ && npm install
cd assets/ && npm run build
tests: debug build
composer update --working-dir=tests/units/ --prefer-dist --no-ansi --no-interaction --no-dev --no-suggest --no-progress
cd tests/units/ && php vendor/bin/phpunit
quicktests: debug
cd tests/units/ && php vendor/bin/phpunit
clean:
rm -rf $(STAGE)
rm -f $(DOCKER_MANIFEST) docker/$(GENERIC_PACKAGE_ZIP)
$(DIST): lizmap/www/assets/js/lizmap.js lizmap/vendor
mkdir -p $(DIST)
cp -aR $(FILES) $(DIST)/
sed -i "s/\(<version date=\"\)\([^\"]*\)\(\"\)/\1$(DATE_VERSION)\3/" $(DIST)/lizmap/project.xml
sed -i "s/\(<version.*pre\)</\1\.$(COMMIT_NUMBER)</" $(DIST)/lizmap/project.xml
sed -i "s@commitSha=@commitSha=$(COMMITID)@g" $(DIST)/lizmap/app/system/mainconfig.ini.php
mkdir -p $(DIST)/temp/lizmap/
cp -a temp/.htaccess $(DIST)/temp/
cp -a temp/lizmap/.empty $(DIST)/temp/lizmap/
@for file in $(FORBIDDEN_CONFIG_FILES); do rm -f $(DIST)/lizmap/var/config/$$file; done;
@for dir in $(EMPTY_DIRS); do rm -rf $(DIST)/lizmap/$$dir/*; touch $(DIST)/lizmap/$$dir/.empty; done;
rm -f $(DIST)/lizmap/composer.*
rm -rf $(DIST)/lizmap/www/cache/images/* && touch $(DIST)/lizmap/www/cache/images/.empty
rm -rf $(DIST)/lizmap/www/document/* && touch $(DIST)/lizmap/www/document/.empty
echo $(LIZMAP_VERSION) > $(DIST)/VERSION
chmod -R o-w $(DIST)/
$(STAGE)/lizmapdemo:
cp -aR extra-modules/lizmapdemo $(STAGE)/
$(GENERIC_PACKAGE_DIR): $(DIST)
mkdir -p $(GENERIC_PACKAGE_DIR)
cp -a $(DIST)/* $(GENERIC_PACKAGE_DIR)
$(ZIP_PACKAGE): $(DIST)
cd $(STAGE) && zip -rq $(PACKAGE_NAME).zip $(PACKAGE_NAME)/
$(GENERIC_PACKAGE_PATH): $(GENERIC_PACKAGE_DIR)
cd $(STAGE) && zip -rq $(GENERIC_PACKAGE_ZIP) $(GENERIC_DIR_NAME)/
$(ZIP_DEMO_PACKAGE): $(STAGE)/lizmapdemo
cd $(STAGE) && zip -rq $(DEMO_PACKAGE_NAME).zip lizmapdemo/
$(DOCKER_MANIFEST):
echo name=$(DOCKER_NAME) > $(DOCKER_MANIFEST) && \
echo version=$(DOCKER_MANIFEST_VERSION) >> $(DOCKER_MANIFEST) && \
echo buildid=$(BUILDID) >> $(DOCKER_MANIFEST) && \
echo commitid=$(COMMITID) >> $(DOCKER_MANIFEST) && \
echo archive=$(DOCKER_ARCHIVENAME) >> $(DOCKER_MANIFEST)
ifdef DOCKER_MANIFEST_VERSION_SHORT
echo version_short=$(DOCKER_MANIFEST_VERSION_SHORT) >> $(DOCKER_MANIFEST)
endif
ifdef DOCKER_MANIFEST_RELEASE_TAG
echo release_tag=$(DOCKER_MANIFEST_RELEASE_TAG) >> $(DOCKER_MANIFEST)
endif
check-release:
ifndef DO_RELEASE
$(error DO_RELEASE is undefined, cannot do a release)
endif
check-registry:
ifndef REGISTRY_URL
$(error REGISTRY_URL is undefined)
endif
stage: $(DIST)
ci_package: $(ZIP_PACKAGE) $(GENERIC_PACKAGE_PATH) $(ZIP_DEMO_PACKAGE)
package: clean build ci_package
deploy_download:
upload_to_packages_server $(ZIP_PACKAGE) pub/lizmap/unstable/$(SHORT_VERSION)/
upload_to_packages_server $(ZIP_DEMO_PACKAGE) pub/lizmap/unstable/$(SHORT_VERSION)/
deploy_download_stable:
upload_to_packages_server $(ZIP_PACKAGE) pub/lizmap/release/$(SHORT_VERSION)/
upload_to_packages_server $(ZIP_DEMO_PACKAGE) pub/lizmap/release/$(SHORT_VERSION)/
saas_deploy_snap:
saas_release_lizmap unstable $(SAAS_LIZMAP_VERSION) $(GENERIC_PACKAGE_PATH)
saas_release: check-release
saas_release_lizmap stable $(SAAS_LIZMAP_VERSION) $(GENERIC_PACKAGE_PATH)
php-doc:
docker run --rm -v ${PWD}:/data phpdoc/phpdoc:3 -c docs/phpdoc.xml
js-doc:
rm -rf docs/js
npx jsdoc -c docs/jsdoc.json
docker-build: debug $(GENERIC_PACKAGE_PATH) docker-build-ci
docker-build-ci: debug $(DOCKER_MANIFEST)
cp $(GENERIC_PACKAGE_PATH) docker/
docker build --rm $(DOCKER_BUILD_ARGS) -t $(DOCKER_BUILDIMAGE) docker/
docker-tag:
docker tag $(DOCKER_BUILDIMAGE) $(REGISTRY_PREFIX)$(DOCKER_NAME):$(DOCKER_MANIFEST_VERSION)
ifdef DOCKER_MANIFEST_VERSION_SHORT
docker tag $(DOCKER_BUILDIMAGE) $(REGISTRY_PREFIX)$(DOCKER_NAME):$(DOCKER_MANIFEST_VERSION_SHORT)
endif
ifdef DOCKER_MANIFEST_RELEASE_TAG
docker tag $(DOCKER_BUILDIMAGE) $(REGISTRY_PREFIX)$(DOCKER_NAME):$(DOCKER_MANIFEST_RELEASE_TAG)
endif
docker-deliver: check-registry docker-tag
docker push $(REGISTRY_URL)/$(DOCKER_NAME):$(DOCKER_MANIFEST_VERSION)
ifdef DOCKER_MANIFEST_VERSION_SHORT
docker push $(REGISTRY_URL)/$(DOCKER_NAME):$(DOCKER_MANIFEST_VERSION_SHORT)
endif
ifdef DOCKER_MANIFEST_RELEASE_TAG
docker push $(REGISTRY_URL)/$(DOCKER_NAME):$(DOCKER_MANIFEST_RELEASE_TAG)
endif
docker-clean:
docker rmi -f $(DOCKER_BUILDIMAGE) || true
docker-clean-all:
docker rmi -f $(shell docker images $(DOCKER_BUILDIMAGE) -q) || true
docker-release:
cd docker && release-image $(DOCKER_RELEASE_PACKAGE_NAME)
cd docker && push-to-docker-hub --clean
docker-hub:
cd docker && push-to-docker-hub --clean
php-cs-fixer-test:
php-cs-fixer fix --config=.php-cs-fixer.dist.php --allow-risky=yes --dry-run --diff
php-cs-fixer-test-docker:
# TODO Switch to PHP-CS-Fixer official image, which are more up to date (3.65.0)
# Current 3.26.0 tag is 3.40.0 inside the docker image... :/
# Version must match the one in the GitHub workflow
docker run --rm -w=/app -v ${PWD}:/app oskarstark/php-cs-fixer-ga:3.26.0 --allow-risky=yes --config=.php-cs-fixer.dist.php --dry-run --diff
php-cs-fixer-apply:
php-cs-fixer fix --config=.php-cs-fixer.dist.php --allow-risky=yes
php-cs-fixer-apply-docker:
# TODO Switch to PHP-CS-Fixer official image, which are more up to date (3.65.0)
# Current 3.26.0 tag is 3.40.0 inside the docker image... :/
# Version must match the one in the GitHub workflow
docker run --rm -it -w=/app -v ${PWD}:/app oskarstark/php-cs-fixer-ga:3.26.0 --allow-risky=yes --config=.php-cs-fixer.dist.php