-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
374 lines (328 loc) · 14.2 KB
/
Copy pathMakefile
File metadata and controls
374 lines (328 loc) · 14.2 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
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# SPDX-FileCopyrightText: 2025 STRATO GmbH
# SPDX-License-Identifier: AGPL-3.0-or-later
# Build configuration
TARGET_PACKAGE_NAME = hidrivenext-server.zip
ARCHITECTURE = x86_64
# Variables for notify_push binary
NOTIFY_PUSH_DIR = apps-external/notify_push
NOTIFY_PUSH_BIN_DIR = $(NOTIFY_PUSH_DIR)/bin/$(ARCHITECTURE)
NOTIFY_PUSH_BINARY = $(NOTIFY_PUSH_BIN_DIR)/notify_push
NOTIFY_PUSH_VERSION = $(shell cd $(NOTIFY_PUSH_DIR) && grep -oP '(?<=<version>)[^<]+' appinfo/info.xml)
NOTIFY_PUSH_URL = https://github.com/nextcloud/notify_push/releases/download/v$(NOTIFY_PUSH_VERSION)/notify_push-$(ARCHITECTURE)-unknown-linux-musl
# Common build commands
COMPOSER_INSTALL = composer install --no-dev -o --no-interaction
NPM_INSTALL = npm ci --prefer-offline --no-audit
NPM_BUILD = npm run build
# App category lists — drive .build_deps and generate_apps_matrix_json
# apps-custom/ — npm only (no composer)
CUSTOM_NPM_APPS = simplesettings
# apps-custom/ — composer only (no npm, even if package.json present)
CUSTOM_COMPOSER_APPS = nc_ionos_processes
# apps-external/ — full build (composer + npm)
EXTERNAL_FULL_APPS = richdocuments user_oidc viewer
# Apps with special build targets (not in the standard categories above)
# These apps have dedicated build_<app>_app targets with custom build logic
SPECIAL_BUILD_APPS = nc_theming nc-ionos-theme notify_push
# Metadata for generate_apps_matrix_json: "name|path|has_npm|has_composer"
# One entry per app in SPECIAL_BUILD_APPS — must be kept in sync.
SPECIAL_BUILD_APPS_META = \
"nc_theming|apps-custom/nc_theming|false|true" \
"nc-ionos-theme|themes/nc-ionos-theme|true|false" \
"notify_push|apps-external/notify_push|false|true"
# App folders to add to shipped.json (makes apps non-removable)
# Add additional app folders here to include them in the shipped apps list
APP_FOLDERS_TO_SHIP = \
apps-external \
apps-custom
# Apps to be removed from final package (read from removed-apps.txt)
REMOVE_UNWANTED_APPS = $(shell [ -f IONOS/removed-apps.txt ] && sed '/^#/d;/^$$/d;s/^/apps\//' IONOS/removed-apps.txt || echo "")
# Generate build target lists dynamically from category lists
CUSTOM_NPM_TARGETS = $(patsubst %,build_%_app,$(CUSTOM_NPM_APPS))
CUSTOM_COMPOSER_TARGETS = $(patsubst %,build_%_app,$(CUSTOM_COMPOSER_APPS))
EXTERNAL_FULL_TARGETS = $(patsubst %,build_%_app,$(EXTERNAL_FULL_APPS))
SPECIAL_BUILD_TARGETS = $(patsubst %,build_%_app,$(SPECIAL_BUILD_APPS))
# Core build targets
.PHONY: help clean .precheck
# Main Nextcloud build
.PHONY: build_nextcloud build_nextcloud_dev
# Applications — dynamically derived from category lists
.PHONY: $(CUSTOM_NPM_TARGETS) $(CUSTOM_COMPOSER_TARGETS) $(EXTERNAL_FULL_TARGETS) $(SPECIAL_BUILD_TARGETS)
# Configuration and packaging
.PHONY: add_config_partials patch_shipped_json version.json zip_dependencies
# Meta targets
.PHONY: .build_deps build_release build_locally
# Pipeline targets for CI workflow
.PHONY: build_after_external_apps package_after_build
# CI matrix generation
.PHONY: generate_apps_matrix_json
# Validation targets
.PHONY: validate_app_list_uniqueness validate_external_apps validate_all
# HELP
# This will output the help for each task
# thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
.DEFAULT_GOAL := help
help: ## This help.
@echo "Usage: make [target]"
@echo ""
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@echo ""
@echo "Individual app build targets:"
@for app in $(CUSTOM_NPM_APPS); do printf " \033[36m%-35s\033[0m %s\n" "build_$${app}_app" "apps-custom npm"; done
@for app in $(CUSTOM_COMPOSER_APPS); do printf " \033[36m%-35s\033[0m %s\n" "build_$${app}_app" "apps-custom composer"; done
@for app in $(EXTERNAL_FULL_APPS); do printf " \033[36m%-35s\033[0m %s\n" "build_$${app}_app" "apps-external composer+npm"; done
@for app in $(SPECIAL_BUILD_APPS); do printf " \033[36m%-35s\033[0m %s\n" "build_$${app}_app" "special"; done
.precheck:
@{ \
if [ ! -d "apps-external" ] || [ ! -d "apps-custom" ]; then \
echo ""; \
echo "**********************************************************************"; \
echo "ERROR: apps-external/ or apps-custom/ not found!"; \
echo ""; \
echo "Run this Makefile from the Nextcloud project root:"; \
echo " make -f IONOS/Makefile <target>"; \
echo "**********************************************************************"; \
echo ""; \
exit 1; \
fi; \
if ! test -f "version.php" || ! test -d "lib" || ! test -d "core"; then \
echo ""; \
echo "**********************************************************************"; \
echo "ERROR: Not a valid Nextcloud project directory."; \
echo ""; \
echo "Run this Makefile from the Nextcloud project root:"; \
echo " make -f IONOS/Makefile <target>"; \
echo "**********************************************************************"; \
echo ""; \
exit 1; \
fi; \
if ! command -v jq >/dev/null 2>&1; then \
echo ""; \
echo "**********************************************************************"; \
echo "ERROR: jq is not installed!"; \
echo ""; \
echo "Please install jq:"; \
echo " Ubuntu/Debian: sudo apt-get install jq"; \
echo " macOS: brew install jq"; \
echo " Other: https://jqlang.github.io/jq/download/"; \
echo "**********************************************************************"; \
echo ""; \
exit 1; \
fi; \
} >&2
clean: ## Clean up build artifacts
@echo "[i] Cleaning build artifacts..."
rm -rf node_modules
rm -f version.json
rm -f .buildnumber
rm -f $(TARGET_PACKAGE_NAME)
@echo "[✓] Clean completed"
.remove_node_modules: ## Remove node_modules
@echo "[i] Removing node_modules directories..."
rm -rf node_modules
build_nextcloud: ## Build HiDrive Next for production
set -e && \
composer install --no-dev -o && \
npm ci && \
NODE_OPTIONS="--max-old-space-size=4096" npm run build
@echo "[i] HiDrive Next built"
build_nextcloud_dev: ## Build HiDrive Next only for development
set -e && \
composer install --no-dev -o && \
npm ci && \
NODE_OPTIONS="--max-old-space-size=4096" npm run dev
@echo "[i] HiDrive Next built for dev"
# Common macros for standard build categories
define build_custom_npm_app
@echo "[i] Building $(1) app..."
@cd apps-custom/$(1) && $(NPM_INSTALL) && $(NPM_BUILD)
@echo "[✓] $(1) app built successfully"
endef
define build_custom_composer_app
@echo "[i] Building $(1) app..."
@cd apps-custom/$(1) && $(COMPOSER_INSTALL)
@echo "[✓] $(1) app built successfully"
endef
define build_external_full_app
@echo "[i] Building $(1) app..."
@cd apps-external/$(1) && $(COMPOSER_INSTALL) && $(NPM_INSTALL) && $(NPM_BUILD)
@echo "[✓] $(1) app built successfully"
endef
# Dynamic rules for standard categories
$(CUSTOM_NPM_TARGETS): build_%_app:
$(call build_custom_npm_app,$(patsubst build_%_app,%,$@))
$(CUSTOM_COMPOSER_TARGETS): build_%_app:
$(call build_custom_composer_app,$(patsubst build_%_app,%,$@))
$(EXTERNAL_FULL_TARGETS): build_%_app:
$(call build_external_full_app,$(patsubst build_%_app,%,$@))
# Special build targets — custom logic that doesn't fit the standard categories
build_nc_theming_app: ## Build the custom css
@echo "[i] Building nc_theming app..."
cd apps-custom/nc_theming && \
$(MAKE) build_css
@echo "[✓] nc_theming app built successfully"
build_nc-ionos-theme_app: ## Install and build ionos theme
@echo "[i] Building nc-ionos-theme app..."
cd themes/nc-ionos-theme/IONOS && \
$(NPM_INSTALL) && \
$(NPM_BUILD)
@echo "[✓] nc-ionos-theme app built successfully"
# notify_push binary target: downloads the pre-built binary from GitHub releases
$(NOTIFY_PUSH_BINARY): $(NOTIFY_PUSH_DIR)/appinfo/info.xml
@echo "[i] Building notify_push binary target for version $(NOTIFY_PUSH_VERSION)..."
@mkdir -p $(NOTIFY_PUSH_BIN_DIR)
@echo "[i] Downloading notify_push binary version $(NOTIFY_PUSH_VERSION)..."
curl -L -o $@ $(NOTIFY_PUSH_URL)
@echo "[i] Verifying binary integrity..."
@sha256sum $@ > $@.sha256
@echo "[i] Binary SHA256: $$(sha256sum $@ | cut -d' ' -f1)"
chmod +x $@
@echo "[i] notify_push binary v$(NOTIFY_PUSH_VERSION) downloaded and verified successfully"
$(NOTIFY_PUSH_DIR)/vendor/autoload.php: $(NOTIFY_PUSH_DIR)/composer.json
@echo "[i] Installing notify_push PHP dependencies..."
cd $(NOTIFY_PUSH_DIR) && composer install --no-dev -o
build_notify_push_app: $(NOTIFY_PUSH_DIR)/vendor/autoload.php $(NOTIFY_PUSH_BINARY) ## Install and build notify_push app
@echo "[✓] notify_push app built successfully"
build_notify_push_binary: $(NOTIFY_PUSH_BINARY) ## Download notify_push binary
@echo "[i] notify_push binary ready"
add_config_partials: .precheck ## Copy custom config files to Nextcloud config
@echo "[i] Copying config files..."
cp IONOS/configs/*.config.php config/
@echo "[✓] Config files copied successfully"
patch_shipped_json: .precheck ## Patch shipped.json
@echo "[i] Patching shipped.json..."
@echo "[i] Making external apps non-removable (hiding remove buttons)..."
IONOS/scripts/patch_shipped_json_add_shipped_apps.sh $(APP_FOLDERS_TO_SHIP)
@echo "[i] Making core apps disableable and enforcing always-enabled apps..."
IONOS/apps-disable.sh
version.json: .precheck ## Generate version file
@echo "[i] Generating version.json..."
buildDate=$$(date +%s) && \
buildRef=$$(git rev-parse --short HEAD) && \
ncVersion=$$(php -r 'include("version.php");echo implode(".", $$OC_Version);') && \
jq -n --arg buildDate $$buildDate --arg buildRef $$buildRef --arg ncVersion $$ncVersion '{buildDate: $$buildDate, buildRef: $$buildRef, ncVersion: $$ncVersion}' > version.json && \
echo "[i] version.json created" && \
jq . version.json
zip_dependencies: patch_shipped_json version.json ## Zip relevant files
@echo "[i] Checking if .buildnumber exists..."
@if [ ! -f .buildnumber ]; then \
echo ""; \
echo "**********************************************************************"; \
echo "ERROR: .buildnumber file not found!"; \
echo ""; \
echo "The .buildnumber file must exist before creating the package."; \
echo "Inject it before packaging, e.g. echo 42 > .buildnumber"; \
echo "**********************************************************************"; \
echo ""; \
exit 1; \
fi
@echo "[i] .buildnumber found: $$(cat .buildnumber)"
@echo "[i] zip relevant files to $(TARGET_PACKAGE_NAME)" && \
zip -r "$(TARGET_PACKAGE_NAME)" \
.buildnumber \
IONOS/ \
3rdparty/ \
apps/ \
apps-custom/ \
apps-external/ \
config/ \
core/ \
dist/ \
lib/ \
ocs/ \
ocs-provider/ \
resources/ \
themes/ \
AUTHORS \
composer.json \
composer.lock \
console.php \
COPYING \
cron.php \
index.html \
index.php \
occ \
public.php \
remote.php \
robots.txt \
status.php \
version.php \
version.json \
.htaccess \
-x "apps/theming/img/background/**" \
-x "apps/*/tests/**" \
-x "apps-*/*/.git" \
-x "apps-*/*/composer.json" \
-x "apps-*/*/composer.lock" \
-x "apps-*/*/composer.phar" \
-x "apps-*/*/.tx" \
-x "apps-*/*/.github" \
-x "apps-*/*/src" \
-x "apps-*/*/node_modules**" \
-x "apps-*/*/vendor-bin**" \
-x "apps-*/*/tests**" \
-x "**/cypress/**" \
-x "*.git*" \
-x "*.editorconfig*" \
-x ".tx" \
-x "composer.json" \
-x "composer.lock" \
-x "composer.phar" \
-x "package.json" \
-x "package-lock.json" \
-x "themes/nc-ionos-theme/README.md" \
-x "themes/nc-ionos-theme/IONOS**" \
$(foreach app,$(REMOVE_UNWANTED_APPS),-x "$(app)/*")
@echo "[i] Package $(TARGET_PACKAGE_NAME) created successfully"
.build_deps: $(CUSTOM_NPM_TARGETS) $(CUSTOM_COMPOSER_TARGETS) $(EXTERNAL_FULL_TARGETS) $(SPECIAL_BUILD_TARGETS)
build_after_external_apps: build_nextcloud add_config_partials ## Build HiDrive Next and add configs after external apps are done
@echo "[i] HiDrive Next built and config files added"
package_after_build: zip_dependencies ## Create package after build is complete
@echo "[i] Package created successfully"
build_release: build_nextcloud .build_deps add_config_partials zip_dependencies ## Build a release package (build apps/themes, copy configs and package)
@echo "[i] Everything done for a release"
build_locally: build_nextcloud_dev .build_deps ## Build all apps/themes for local development
@echo "[i] Everything done for local/dev"
validate_app_list_uniqueness: .precheck ## Validate that apps are only in one list and not duplicated by hardcoded targets
@IONOS/scripts/validate_app_list_uniqueness.sh \
"$(CUSTOM_NPM_APPS)" \
"$(CUSTOM_COMPOSER_APPS)" \
"$(EXTERNAL_FULL_APPS)" \
"$(SPECIAL_BUILD_APPS)" \
"$(MAKEFILE_LIST)"
validate_external_apps: .precheck ## Validate and suggest proper categorization for apps-custom/ and apps-external/
@IONOS/scripts/validate_external_apps.sh \
"$(CUSTOM_NPM_APPS)" \
"$(CUSTOM_COMPOSER_APPS)" \
"$(EXTERNAL_FULL_APPS)" \
"$(SPECIAL_BUILD_APPS)"
validate_all: .precheck ## Run all validation tasks
@echo "[i] Running validation..."
@$(MAKE) -f IONOS/Makefile validate_app_list_uniqueness
@$(MAKE) -f IONOS/Makefile validate_external_apps
@echo "[✓] Validation completed successfully"
generate_apps_matrix_json: .precheck ## Generate JSON matrix of buildable apps for the CI pipeline
@bash -c ' \
emit() { \
local app="$$1" path="$$2" has_npm="$$3" has_composer="$$4"; \
local npm_lock_path=""; \
if [ "$$has_npm" = "true" ]; then \
if [ -f "$$path/IONOS/package-lock.json" ]; then \
npm_lock_path="$$path/IONOS/package-lock.json"; \
else \
npm_lock_path="$$path/package-lock.json"; \
fi; \
fi; \
printf "{\"name\":\"%s\",\"path\":\"%s\",\"has_npm\":%s,\"has_composer\":%s,\"npm_lock_path\":\"%s\",\"makefile_target\":\"build_%s_app\",\"needs_custom_npms\":false}\n" \
"$$app" "$$path" "$$has_npm" "$$has_composer" "$$npm_lock_path" "$$app"; \
}; \
for app in $(CUSTOM_NPM_APPS); do emit "$$app" "apps-custom/$$app" true false; done; \
for app in $(CUSTOM_COMPOSER_APPS); do emit "$$app" "apps-custom/$$app" false true; done; \
for app in $(EXTERNAL_FULL_APPS); do emit "$$app" "apps-external/$$app" true true; done; \
for meta in $(SPECIAL_BUILD_APPS_META); do \
app=$$(echo "$$meta" | cut -d"|" -f1); \
path=$$(echo "$$meta" | cut -d"|" -f2); \
has_npm=$$(echo "$$meta" | cut -d"|" -f3); \
has_composer=$$(echo "$$meta" | cut -d"|" -f4); \
emit "$$app" "$$path" "$$has_npm" "$$has_composer"; \
done; \
' | jq -s 'sort_by(.name)'