-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
340 lines (310 loc) · 18 KB
/
Makefile
File metadata and controls
340 lines (310 loc) · 18 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
.PHONY: all check precommit deps gen analyze test coverage linux android android-x64 web cf-pages clean install uninstall help sync-datacenters icons icons-check release
# ══════════════════════════════════════════════════════════════════════════════
# Dash for CF - Makefile
# ══════════════════════════════════════════════════════════════════════════════
#
# Workflow:
# make check - Quick validation during development (~20s)
# make precommit - Full verification before commit (~30s)
#
# All commands suppress successful output to save tokens.
# Logs only shown on errors.
#
# ══════════════════════════════════════════════════════════════════════════════
# Paths
LINUX_BUNDLE = build/linux/x64/release/bundle
APK_DIR = build/app/outputs/flutter-apk
APK_PATH = $(APK_DIR)/dash-for-cf.apk
WEB_PATH = build/web
INSTALL_DIR = $(HOME)/.local
ANALYZE_LOG = /tmp/dash-cf-analyze.log
ANALYZE_BUDGET = 50
COVERAGE_MIN = 25
# Temp log file
LOG = /tmp/dash-cf-build.log
# ══════════════════════════════════════════════════════════════════════════════
# Output control: TTY detection with explicit override
#
# - Interactive terminal (user): show full output
# - Non-interactive (agent/CI): suppress successful output, show only errors
# - VERBOSE=1: force full output regardless of TTY
# ══════════════════════════════════════════════════════════════════════════════
ifeq ($(VERBOSE),1)
# Explicit verbose mode
RUN =
RUN_LENIENT =
else ifeq ($(shell [ -t 1 ] && echo 1),1)
# Interactive terminal - show output
RUN =
RUN_LENIENT =
else
# Non-interactive (agent/CI) - suppress successful output
RUN = > $(LOG) 2>&1 || (cat $(LOG) && exit 1)
RUN_LENIENT = > $(LOG) 2>&1 || (cat $(LOG) && true)
endif
# Default target
all: help
# ══════════════════════════════════════════════════════════════════════════════
# CHECK - Quick validation (deps + gen + analyze + test)
# ══════════════════════════════════════════════════════════════════════════════
check:
@echo "══════════════════════════════════════════════════════════════"
@echo " CHECK - Quick Validation"
@echo "══════════════════════════════════════════════════════════════"
@echo ""
@echo "[1/4] Installing dependencies..."
@flutter pub get $(RUN)
@echo "✓ Dependencies installed"
@echo ""
@echo "[2/4] Generating code (build_runner)..."
@dart run build_runner build --delete-conflicting-outputs $(RUN)
@echo "✓ Code generated"
@echo ""
@echo "[3/4] Static Analysis..."
@flutter analyze --no-fatal-infos --no-fatal-warnings 2>&1 | tee $(ANALYZE_LOG) $(RUN_LENIENT)
@bash tool/ci/check_analyze_budget.sh $(ANALYZE_LOG) $(ANALYZE_BUDGET)
@echo "✓ Analysis passed (budget: $(ANALYZE_BUDGET))"
@echo ""
@echo "[4/4] Running Tests..."
@flutter test $(RUN)
@echo "✓ All tests passed"
@echo ""
@echo "══════════════════════════════════════════════════════════════"
@echo " ✅ CHECK PASSED"
@echo "══════════════════════════════════════════════════════════════"
# ══════════════════════════════════════════════════════════════════════════════
# PRECOMMIT - Full verification (check + builds)
# ══════════════════════════════════════════════════════════════════════════════
precommit: check
@echo ""
@echo "══════════════════════════════════════════════════════════════"
@echo " PRECOMMIT - Build Verification"
@echo "══════════════════════════════════════════════════════════════"
@echo ""
@echo "[5/6] Linux Build..."
@flutter build linux --release $(RUN_LENIENT)
@if [ -d "$(LINUX_BUNDLE)" ]; then echo "✓ Linux build successful"; else echo "⚠ Linux build skipped (not on Linux or missing deps)"; fi
@echo ""
@echo "[6/6] Android Build & Upload..."
@$(MAKE) android VERBOSE=$(VERBOSE)
@echo ""
@echo "══════════════════════════════════════════════════════════════"
@echo " ✅ PRECOMMIT PASSED - Safe to commit!"
@echo "══════════════════════════════════════════════════════════════"
# ══════════════════════════════════════════════════════════════════════════════
# BUILD TARGETS
# ══════════════════════════════════════════════════════════════════════════════
# Install dependencies
deps: sync-datacenters
@echo "Installing dependencies..."
@flutter pub get $(RUN)
@echo "✓ Dependencies installed"
# Regenerate app icons and splash screens
icons:
@echo "Regenerating icons and splash..."
@dart run flutter_launcher_icons $(RUN)
@dart run flutter_native_splash:create $(RUN)
@echo "Fixing Android adaptive icon XML (removing inset)..."
@echo '<?xml version="1.0" encoding="utf-8"?>' > android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
@echo '<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">' >> android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
@echo ' <background android:drawable="@color/ic_launcher_background"/>' >> android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
@echo ' <foreground android:drawable="@drawable/ic_launcher_foreground"/>' >> android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
@echo '</adaptive-icon>' >> android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
@echo "✓ Icons and splash regenerated"
# Validate icon artifacts exist
icons-check:
@echo "Checking icon artifacts..."
@set -e; \
for f in \
android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml \
android/app/src/main/res/mipmap-hdpi/ic_launcher.png \
android/app/src/main/res/mipmap-mdpi/ic_launcher.png \
android/app/src/main/res/mipmap-xhdpi/ic_launcher.png \
android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png \
android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png \
web/icons/Icon-192.png \
web/icons/Icon-512.png \
web/icons/Icon-maskable-192.png \
web/icons/Icon-maskable-512.png; do \
test -f "$$f" || { echo "Missing icon artifact: $$f"; exit 1; }; \
done
@echo "✓ Icon artifacts verified"
# Generate code (Freezed, Retrofit, JSON Serializable)
gen:
@echo "Generating code (build_runner)..."
@dart run build_runner build --delete-conflicting-outputs $(RUN)
@echo "✓ Code generated"
# Static analysis with budget gate
analyze:
@echo "Running static analysis..."
@flutter analyze --no-fatal-infos --no-fatal-warnings 2>&1 | tee $(ANALYZE_LOG)
@bash tool/ci/check_analyze_budget.sh $(ANALYZE_LOG) $(ANALYZE_BUDGET)
# Run tests
test:
@echo "Running tests..."
@flutter test $(RUN)
@echo "✓ All tests passed"
# Run tests with coverage + threshold gate
coverage:
@echo "Running tests with coverage..."
@flutter test --coverage $(RUN)
@echo "✓ Tests passed"
@bash tool/ci/check_coverage.sh coverage/lcov.info $(COVERAGE_MIN)
# Linux release build
linux:
@echo "Building Linux release..."
@flutter build linux --release $(RUN)
@echo "✓ Linux build complete"
@echo " Bundle: $(LINUX_BUNDLE)/"
@ls -lh $(LINUX_BUNDLE)/dash_for_cloudflare 2>/dev/null || true
# Android release build + tdl upload
android:
@echo "Building Android APK (arm64)..."
@flutter build apk --release --target-platform android-arm64 $(RUN)
@mv -f $(APK_DIR)/app-release.apk $(APK_PATH)
@echo "✓ Android build complete"
@echo " APK: $(APK_PATH)"
@ls -lh $(APK_PATH)
@echo ""
@CAPTION_TEXT="$${HEY_CAPTION:-$$(git log -1 --pretty=%s 2>/dev/null || echo DashCF-Android-build)}"; \
~/bin/hey -f "$(APK_PATH)" "$$CAPTION_TEXT"
# Android x64 build (for emulator)
android-x64:
@echo "Building Android APK (x64 for emulator)..."
@flutter build apk --release --target-platform android-x64 $(RUN)
@mv -f $(APK_DIR)/app-release.apk $(APK_PATH)
@echo "✓ Android x64 build complete"
@echo " APK: $(APK_PATH)"
@ls -lh $(APK_PATH)
# Web release build
web:
@echo "Building Web release..."
@flutter build web --release $(RUN)
@echo "✓ Web build complete"
@echo " Output: $(WEB_PATH)/"
@du -sh $(WEB_PATH)
# Cloudflare Pages build command (for CI)
# Copy this output to Cloudflare Pages "Build command" field
cf-pages:
@echo 'git clone --depth 1 -b stable https://github.com/flutter/flutter.git && export PATH="$$PATH:$$PWD/flutter/bin" && flutter pub get && dart run build_runner build --delete-conflicting-outputs && flutter build web --release'
# Clean build artifacts
clean:
@echo "Cleaning build artifacts..."
@flutter clean $(RUN)
@rm -rf build/
@echo "✓ Clean complete"
# ══════════════════════════════════════════════════════════════════════════════
# RELEASE - Bump version, commit, tag, push
# ══════════════════════════════════════════════════════════════════════════════
release:
@if [ -z "$(V)" ]; then echo "Usage: make release V=patch|minor|major"; exit 1; fi
@# Parse current version from pubspec.yaml
$(eval CUR_FULL := $(shell grep '^version:' pubspec.yaml | sed 's/version: *//'))
$(eval CUR_VER := $(shell echo $(CUR_FULL) | sed 's/+.*//'))
$(eval CUR_BUILD := $(shell echo $(CUR_FULL) | grep -o '+.*' | sed 's/+//' || echo 0))
$(eval MAJOR := $(shell echo $(CUR_VER) | cut -d. -f1))
$(eval MINOR := $(shell echo $(CUR_VER) | cut -d. -f2))
$(eval PATCH := $(shell echo $(CUR_VER) | cut -d. -f3))
$(eval SAFE_BUILD := $(if $(CUR_BUILD),$(CUR_BUILD),0))
$(eval NEW_BUILD := $(shell echo $$(($(SAFE_BUILD) + 1))))
@# Calculate new version
$(eval NEW_VER := $(if $(filter major,$(V)),$(shell echo $$(($(MAJOR) + 1))).0.0,\
$(if $(filter minor,$(V)),$(MAJOR).$(shell echo $$(($(MINOR) + 1))).0,\
$(if $(filter patch,$(V)),$(MAJOR).$(MINOR).$(shell echo $$(($(PATCH) + 1))),\
$(error V must be patch, minor, or major)))))
@echo "$(CUR_VER)+$(SAFE_BUILD) -> $(NEW_VER)+$(NEW_BUILD)"
@# Update pubspec.yaml
@sed -i 's/^version: .*/version: $(NEW_VER)+$(NEW_BUILD)/' pubspec.yaml
@# Commit, tag, push
@git add pubspec.yaml
@git commit -m "release: cut v$(NEW_VER)"
@git tag -a "v$(NEW_VER)" -m "v$(NEW_VER)"
@git push --follow-tags
@echo "Released v$(NEW_VER) — CI and Release workflows triggered."
# ══════════════════════════════════════════════════════════════════════════════
# LINUX INSTALLATION
# ══════════════════════════════════════════════════════════════════════════════
# Install on Linux (after build)
install: linux
@echo "Installing Dash for CF to $(INSTALL_DIR)..."
@mkdir -p $(INSTALL_DIR)/bin
@mkdir -p $(INSTALL_DIR)/share/dash-for-cloudflare
@mkdir -p $(INSTALL_DIR)/share/applications
@mkdir -p $(INSTALL_DIR)/share/icons/hicolor/128x128/apps
@cp -r $(LINUX_BUNDLE)/* $(INSTALL_DIR)/share/dash-for-cloudflare/
@ln -sf $(INSTALL_DIR)/share/dash-for-cloudflare/dash_for_cloudflare $(INSTALL_DIR)/bin/dash-cf
@echo "[Desktop Entry]" > $(INSTALL_DIR)/share/applications/ad.dash.cf.desktop
@echo "Name=Dash for CF" >> $(INSTALL_DIR)/share/applications/ad.dash.cf.desktop
@echo "Comment=Unofficial Cloudflare management app" >> $(INSTALL_DIR)/share/applications/ad.dash.cf.desktop
@echo "Exec=$(INSTALL_DIR)/share/dash-for-cloudflare/dash_for_cloudflare" >> $(INSTALL_DIR)/share/applications/ad.dash.cf.desktop
@echo "Icon=$(INSTALL_DIR)/share/icons/hicolor/128x128/apps/ad.dash.cf.png" >> $(INSTALL_DIR)/share/applications/ad.dash.cf.desktop
@echo "Terminal=false" >> $(INSTALL_DIR)/share/applications/ad.dash.cf.desktop
@echo "Type=Application" >> $(INSTALL_DIR)/share/applications/ad.dash.cf.desktop
@echo "Categories=Network;Utility;" >> $(INSTALL_DIR)/share/applications/ad.dash.cf.desktop
@cp assets/icons/app_icon.png $(INSTALL_DIR)/share/icons/hicolor/128x128/apps/ad.dash.cf.png 2>/dev/null || \
cp android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png $(INSTALL_DIR)/share/icons/hicolor/128x128/apps/ad.dash.cf.png 2>/dev/null || true
@gtk-update-icon-cache $(INSTALL_DIR)/share/icons/hicolor 2>/dev/null || true
@echo ""
@echo "✅ Dash for CF installed!"
@echo ""
@echo "Make sure $(INSTALL_DIR)/bin is in your PATH:"
@echo " export PATH=\"\$$HOME/.local/bin:\$$PATH\""
@echo ""
@echo "Run: dash-cf"
# Uninstall from Linux
uninstall:
@echo "Uninstalling Dash for CF..."
@rm -f $(INSTALL_DIR)/bin/dash-cf
@rm -rf $(INSTALL_DIR)/share/dash-for-cloudflare
@rm -f $(INSTALL_DIR)/share/applications/ad.dash.cf.desktop
@rm -f $(INSTALL_DIR)/share/icons/hicolor/128x128/apps/ad.dash.cf.png
@echo "✓ Uninstalled"
# ══════════════════════════════════════════════════════════════════════════════
# DATA SYNC
# ══════════════════════════════════════════════════════════════════════════════
# Sync Cloudflare data centers list from GitHub
sync-datacenters:
@echo "Syncing Cloudflare data centers..."
@curl -sfL "https://raw.githubusercontent.com/insign/Cloudflare-Data-Center-IATA-Code-list/main/cloudflare-iata-full.json" \
-o assets/data/cloudflare-iata-full.json $(RUN)
@echo "✓ Data centers synced"
# ══════════════════════════════════════════════════════════════════════════════
# HELP
# ══════════════════════════════════════════════════════════════════════════════
help:
@echo "Dash for CF - Build Commands"
@echo ""
@echo " Validation:"
@echo " make check Quick validation (deps+gen+analyze+test) ~20s"
@echo " make precommit Full verification (check+builds) ~30s"
@echo ""
@echo " Build:"
@echo " make android Build APK (arm64) + upload via hey"
@echo " make android-x64 Build APK (x64 for emulator)"
@echo " make linux Build Linux release"
@echo " make web Build Web release"
@echo " make cf-pages Show build command for Cloudflare Pages CI"
@echo ""
@echo " Quality:"
@echo " make test Run tests only"
@echo " make analyze Static analysis + budget gate (max $(ANALYZE_BUDGET) issues)"
@echo " make coverage Tests + coverage threshold gate (min $(COVERAGE_MIN)%)"
@echo " make icons-check Validate icon artifacts exist"
@echo ""
@echo " Development:"
@echo " make deps Install dependencies (+ sync data centers)"
@echo " make sync-datacenters Update Cloudflare data centers list"
@echo " make gen Generate code (Freezed, Retrofit)"
@echo " make icons Regenerate app icons and splash screens"
@echo " make clean Clean build artifacts"
@echo ""
@echo " Release:"
@echo " make release V=patch Bump patch version, commit, tag, push"
@echo " make release V=minor Bump minor version, commit, tag, push"
@echo " make release V=major Bump major version, commit, tag, push"
@echo ""
@echo " Linux Install:"
@echo " make install Install to ~/.local"
@echo " make uninstall Remove from ~/.local"
@echo ""
@echo "Workflow: make check (during dev) -> make precommit (before commit)"