Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
372 lines (318 loc) · 14.6 KB
/
Copy pathMakefile
File metadata and controls
372 lines (318 loc) · 14.6 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
.PHONY: all env install screenshots screenshots-caption clean clean-chrome icons sync-assets build-android build-android-release build-aab build-ios-dev build-ios build-ios-release build-ipa update-version firebase-config build-web upload-web-symbols upload-ios-symbols upload-android-symbols test check-l10n generate-forwarding-localizations update-ui-literals-baselinerun-pseudo-locale start-platform stop-platform install-chromedriver test-integration test-integration-smoke test-playwright coverage run-devserver build-docker-local build-docker run-docker stop-docker restart-docker publish promote
SHELL := /usr/bin/env bash
FLUTTER_DART := $(dir $(shell command -v flutter))dart
TAG_VERSION ?= latest
PLATFORM ?= arm64
DOCKER_TAG_VERSION := $(subst +,_,$(TAG_VERSION))
DOCKER_CACHE_DIR ?= .docker-cache
ENVIRONMENT ?= dev-local
HEADLESS ?= true
INTEGRATION_TARGET ?= integration_test/full_test.dart
INTEGRATION_EMAIL_SUFFIX ?= integration-$(USER)
ifeq ($(ENVIRONMENT),prod)
ENVIRONMENT_PREFIX :=
else
ENVIRONMENT_PREFIX := $(ENVIRONMENT).
endif
ifeq ($(ENVIRONMENT),dev-local)
PROJECT_API_HOST ?= http://localhost:8000
else
PROJECT_API_HOST ?= https://api.$(ENVIRONMENT_PREFIX)heliumedu.com
endif
RELEASE_ARGS :=
ifdef RELEASE_VERSION
RELEASE_ARGS += --dart-define=RELEASE_VERSION=$(RELEASE_VERSION)
endif
ifdef SENTRY_DIST
RELEASE_ARGS += --dart-define=SENTRY_DIST=$(SENTRY_DIST)
endif
ifdef SENTRY_DSN
RELEASE_ARGS += --dart-define=SENTRY_DSN=$(SENTRY_DSN)
endif
ifdef FIREBASE_AUTH_DOMAIN
RELEASE_ARGS += --dart-define=FIREBASE_AUTH_DOMAIN=$(FIREBASE_AUTH_DOMAIN)
endif
ifeq ($(origin PROJECT_API_HOST),command line)
RELEASE_ARGS += --dart-define=PROJECT_API_HOST=$(PROJECT_API_HOST)
else ifndef RELEASE_VERSION
RELEASE_ARGS += --dart-define=PROJECT_API_HOST=$(PROJECT_API_HOST)
endif
ifdef SENTRY_ENVIRONMENT
RELEASE_ARGS += --dart-define=SENTRY_ENVIRONMENT=$(SENTRY_ENVIRONMENT)
endif
SYMBOLS_DIR := build/symbols
IOS_DSYMS_DIR := build/ios/archive/Helium.xcarchive/dSYMs
IOS_SYMBOL_DIRS := $(SYMBOLS_DIR)/ $(IOS_DSYMS_DIR)/
ANDROID_SYMBOL_DIRS := $(SYMBOLS_DIR)/
SENTRY_UPLOAD_ARGS :=
ifdef RELEASE_VERSION
SENTRY_UPLOAD_ARGS += --release $(RELEASE_VERSION)
endif
ifdef SENTRY_DIST
SENTRY_UPLOAD_ARGS += --dist $(SENTRY_DIST)
endif
BUILD_OVERRIDE_ARGS :=
ifdef BUILD_NAME
BUILD_OVERRIDE_ARGS += --build-name=$(BUILD_NAME)
endif
ifdef BUILD_NUMBER
BUILD_OVERRIDE_ARGS += --build-number=$(BUILD_NUMBER)
endif
RUN_ARGS :=
ifneq ($(HEADLESS),false)
RUN_ARGS += -d web-server
endif
RUN_ARGS += --dart-define=PROJECT_API_HOST=$(PROJECT_API_HOST)
ifdef LOG_LEVEL
RUN_ARGS += --dart-define=LOG_LEVEL=$(LOG_LEVEL)
endif
ifdef PORT
RUN_ARGS += --web-port=$(PORT)
else
RUN_ARGS += --web-port=8080
endif
DRIVE_ARGS := --driver=test_driver/integration_test.dart -d web-server --web-port=8080 --browser-name=chrome --profile --dart-define=ENVIRONMENT=$(ENVIRONMENT)
DRIVE_ARGS += --web-browser-flag="--user-data-dir=/tmp/chrome_test_profile"
ifeq ($(HEADLESS),true)
DRIVE_ARGS += --headless
else
DRIVE_ARGS += --no-headless
endif
DRIVE_ARGS += --dart-define=PROJECT_API_HOST=$(PROJECT_API_HOST)
ifdef LOG_LEVEL
DRIVE_ARGS += --dart-define=LOG_LEVEL=$(LOG_LEVEL)
endif
ifdef AWS_INTEGRATION_S3_ACCESS_KEY_ID
DRIVE_ARGS += --dart-define=AWS_INTEGRATION_S3_ACCESS_KEY_ID=$(AWS_INTEGRATION_S3_ACCESS_KEY_ID)
endif
ifdef AWS_INTEGRATION_S3_SECRET_ACCESS_KEY
DRIVE_ARGS += --dart-define=AWS_INTEGRATION_S3_SECRET_ACCESS_KEY=$(AWS_INTEGRATION_S3_SECRET_ACCESS_KEY)
endif
ifdef INTEGRATION_LOG_LEVEL
DRIVE_ARGS += --dart-define=INTEGRATION_LOG_LEVEL=$(INTEGRATION_LOG_LEVEL)
endif
ifdef INTEGRATION_EMAIL_SUFFIX
DRIVE_ARGS += --dart-define=INTEGRATION_EMAIL_SUFFIX=$(INTEGRATION_EMAIL_SUFFIX)
endif
ifdef EMAIL_POLL_TIMEOUT_MINUTES
DRIVE_ARGS += --dart-define=EMAIL_POLL_TIMEOUT_MINUTES=$(EMAIL_POLL_TIMEOUT_MINUTES)
endif
# The browser region integration tests run as; mirrors IntegrationRegion in
# integration_test/helpers/test_config.dart. Chrome only reports the region's
# language with all three of the UI locale, accept-language, and LANGUAGE set.
# Without INTEGRATION_REGION the browser still speaks US English, since the
# tests find widgets by their English text.
REGION_TZ_us := America/Chicago
REGION_UI_LANG_us := en-US
REGION_ACCEPT_LANG_us := en-US
REGION_LANGUAGE_us := en_US
REGION_TZ_de := Europe/Berlin
REGION_UI_LANG_de := de
REGION_ACCEPT_LANG_de := de-DE
REGION_LANGUAGE_de := de_DE
BROWSER_REGION := $(or $(INTEGRATION_REGION),us)
DRIVE_ARGS += --web-browser-flag="--lang=$(REGION_UI_LANG_$(BROWSER_REGION))"
DRIVE_ARGS += --web-browser-flag="--accept-lang=$(REGION_ACCEPT_LANG_$(BROWSER_REGION))"
DRIVE_ENV := LANGUAGE=$(REGION_LANGUAGE_$(BROWSER_REGION)) TZ=$(REGION_TZ_$(BROWSER_REGION))
ifneq ($(INTEGRATION_REGION),)
DRIVE_ARGS += --dart-define=INTEGRATION_REGION=$(INTEGRATION_REGION)
endif
ifdef RELEASE_VERSION
DRIVE_ARGS += --dart-define=RELEASE_VERSION=$(RELEASE_VERSION)
endif
ifdef SENTRY_DIST
DRIVE_ARGS += --dart-define=SENTRY_DIST=$(SENTRY_DIST)
endif
ifdef SENTRY_DSN
DRIVE_ARGS += --dart-define=SENTRY_DSN=$(SENTRY_DSN)
endif
all: build-docker-local run-docker
env:
cp -n .env.example .env | true
install: env
flutter pub get
screenshots:
@command -v brew >/dev/null || { echo "Error: Homebrew not installed"; exit 1; }
@brew list fastlane >/dev/null 2>&1 || brew install fastlane
@brew list imagemagick >/dev/null 2>&1 || brew install imagemagick
@if [ ! -f "$$HOME/.fastlane/frameit/latest/Apple iPhone Duo Inner Night Sky.png" ]; then \
fastlane frameit download_frames; \
fi
@./bin/grab-screenshots.sh
@[ -x .venv/bin/python ] || python3 -m venv .venv
@.venv/bin/python -c 'import playwright, PIL' 2>/dev/null || .venv/bin/pip install -q playwright pillow
@.venv/bin/python bin/grab-screenshots-web.py
screenshots-caption:
@brew list imagemagick >/dev/null 2>&1 || brew install imagemagick
@./bin/recaption-screenshots.sh
clean:
flutter clean
clean-chrome:
@echo "Killing stale Chrome and chromedriver processes ..."
@pkill -f chromedriver || true
@pkill -f "Chrome.*--remote-debugging" || true
@pkill -f "Google Chrome for Testing" || true
@sleep 1
@echo "Done"
build-android: install
flutter build apk --debug
build-android-release: install
flutter build appbundle --release --obfuscate --split-debug-info=$(SYMBOLS_DIR) $(RELEASE_ARGS) $(BUILD_OVERRIDE_ARGS)
build-ios-dev: install
flutter build ios
build-ios: install
flutter build ios --debug --no-codesign
build-ios-release: install
flutter build ipa --release --no-codesign --obfuscate --split-debug-info=$(SYMBOLS_DIR) $(RELEASE_ARGS) $(BUILD_OVERRIDE_ARGS)
./bin/export-ios-signed.sh
# A prod release candidate for the shared Flutter workflows (alexdlaird/.github): VERSION and BUILD name the build and
# tag it for Sentry (release, dist), then its debug symbols go to Sentry. SENTRY_DSN and SENTRY_AUTH_TOKEN come from the
# environment.
build-aab:
$(call require-candidate-vars)
$(MAKE) build-android-release ENVIRONMENT=prod RELEASE_VERSION="$(VERSION)" SENTRY_DIST="$(BUILD)" \
SENTRY_DSN="$(SENTRY_DSN)" BUILD_NAME="$(VERSION)" BUILD_NUMBER="$(BUILD)"
npm install -g @sentry/cli@3.6.2
$(MAKE) upload-android-symbols
build-ipa:
$(call require-candidate-vars)
$(MAKE) build-ios-release ENVIRONMENT=prod RELEASE_VERSION="$(VERSION)" SENTRY_DIST="$(BUILD)" \
SENTRY_DSN="$(SENTRY_DSN)" BUILD_NAME="$(VERSION)" BUILD_NUMBER="$(BUILD)"
npm install -g @sentry/cli@3.6.2
$(MAKE) upload-ios-symbols
require-candidate-vars = $(if $(and $(VERSION),$(BUILD),$(SENTRY_DSN)),,$(error VERSION, BUILD and SENTRY_DSN are required))
build-web: install
flutter build web --release --source-maps --no-tree-shake-icons --pwa-strategy=none $(RELEASE_ARGS) $(BUILD_OVERRIDE_ARGS)
cp -r web/.well-known build/web/
rm -f build/web/.last_build_id
$(MAKE) update-version
upload-ios-symbols: SYMBOL_DIRS := $(IOS_SYMBOL_DIRS)
upload-android-symbols: SYMBOL_DIRS := $(ANDROID_SYMBOL_DIRS)
upload-ios-symbols upload-android-symbols:
@for dir in $(SYMBOL_DIRS); do \
if [ ! -d "$$dir" ] || [ -z "$$(ls -A "$$dir")" ]; then \
echo "No debug symbols in $$dir - refusing to upload."; \
exit 1; \
fi; \
done
SENTRY_PROPERTIES=sentry/sentry.properties sentry-cli debug-files upload $(SYMBOL_DIRS)
upload-web-symbols:
test -f build/web/main.dart.js.map
SENTRY_PROPERTIES=sentry/sentry.properties sentry-cli sourcemaps inject build/web
dart bin/embed_sourcemap_sources.dart
SENTRY_PROPERTIES=sentry/sentry.properties sentry-cli sourcemaps upload \
$(SENTRY_UPLOAD_ARGS) \
--no-rewrite \
--validate \
--url-prefix "~/" \
build/web
icons:
flutter pub run flutter_launcher_icons
@./bin/fanout-icons.sh
sync-assets:
bin/sync-assets.sh
update-version:
dart bin/update_version.dart
firebase-config:
flutterfire config --project=helium-edu --yes
test: install
flutter analyze --no-pub --no-fatal-infos --no-fatal-warnings
flutter test --no-pub --coverage
check-l10n: install
flutter gen-l10n
python3 bin/check-arb-descriptions.py
python3 bin/check-ui-literals.py
$(FLUTTER_DART) bin/generate_forwarding_localizations.dart .dart_tool/forwarding_localizations.dart
@diff -u lib/utils/forwarding_localizations.dart .dart_tool/forwarding_localizations.dart || \
{ echo "lib/utils/forwarding_localizations.dart is out of date: run make generate-forwarding-localizations"; exit 1; }
generate-forwarding-localizations: install
$(FLUTTER_DART) bin/generate_forwarding_localizations.dart
update-ui-literals-baseline:
python3 bin/check-ui-literals.py --update
run-pseudo-locale: install
python3 bin/generate-pseudo-locale.py
@trap 'rm -f lib/l10n/app_en_XA.arb; flutter gen-l10n > /dev/null' EXIT; \
LANGUAGE=en_XA flutter run -d chrome --debug \
--web-browser-flag="--lang=en-XA" --web-browser-flag="--accept-lang=en-XA" \
--dart-define=PROJECT_API_HOST=$(PROJECT_API_HOST)
start-platform:
@if curl -sf http://localhost:8000/status/ > /dev/null 2>&1; then \
echo "Platform already running"; \
else \
echo "Starting platform ..."; \
curl -fsSL "https://raw.githubusercontent.com/HeliumEdu/platform/main/bin/start-platform.sh?$$(date +%s)" | bash; \
fi
@if [ -n "$$PLATFORM_EMAIL_HOST_USER" ] && [ -n "$$PLATFORM_EMAIL_HOST_PASSWORD" ]; then \
WORK_DIR=$${TMPDIR:-/tmp}/helium-platform; \
if grep -q '<SMTP_USERNAME>' "$$WORK_DIR/.env" 2>/dev/null; then \
echo "Injecting SMTP credentials and restarting API ..."; \
sed -i.bak "s/<SMTP_USERNAME>/$$PLATFORM_EMAIL_HOST_USER/" $$WORK_DIR/.env; \
sed -i.bak "s/<SMTP_PASSWORD>/$$PLATFORM_EMAIL_HOST_PASSWORD/" $$WORK_DIR/.env; \
cd $$WORK_DIR && docker compose up -d api worker; \
fi; \
fi
stop-platform:
@curl -fsSL "https://raw.githubusercontent.com/HeliumEdu/platform/main/bin/stop-platform.sh?$$(date +%s)" | bash
install-chromedriver:
npm install -g chromedriver
test-integration:
ifeq ($(ENVIRONMENT),dev-local)
@$(MAKE) start-platform
endif
@$(DRIVE_ENV) chromedriver --port=4444 & CHROME_PID=$$!; sleep 2 && $(DRIVE_ENV) flutter drive --target=$(INTEGRATION_TARGET) $(DRIVE_ARGS); TEST_EXIT=$$?; \
kill $$CHROME_PID 2>/dev/null || true; \
exit $$TEST_EXIT
test-integration-smoke:
@$(DRIVE_ENV) chromedriver --port=4444 & CHROME_PID=$$!; sleep 2 && $(DRIVE_ENV) flutter drive --target=integration_test/smoke_test.dart $(DRIVE_ARGS); TEST_EXIT=$$?; kill $$CHROME_PID 2>/dev/null || true; exit $$TEST_EXIT
test-playwright:
cd canary_test && python3 -m pip install -r requirements.txt -q && python3 -m playwright install chromium && python3 -m pytest -v --screenshot=only-on-failure --output=screenshots
coverage:
dart pub global activate test_cov_console
lcov -o coverage/lcov.info --remove coverage/lcov.info 'lib/config/*' 'lib/utils/app_globals.dart' 'lib/utils/app_style.dart' 'lib/utils/color_helpers.dart' 'lib/data/models/*' 'lib/data/repositories/*' 'lib/presentation/core/*' 'lib/presentation/navigation/*' 'lib/presentation/ui/*' 'lib/presentation/features/auth/views/*' 'lib/presentation/features/courses/dialogs/*' 'lib/presentation/features/courses/views/*' 'lib/presentation/features/courses/widgets/*' 'lib/presentation/features/grades/dialogs/*' 'lib/presentation/features/grades/views/*' 'lib/presentation/features/planner/dialogs/*' 'lib/presentation/features/planner/views/*' 'lib/presentation/features/planner/widgets/*' 'lib/presentation/features/resources/dialogs/*' 'lib/presentation/features/resources/views/*' 'lib/presentation/features/resources/widgets/*' 'lib/presentation/features/settings/dialogs/*' 'lib/presentation/features/settings/views/*' 'lib/presentation/features/shared/widgets/*'
dart pub global run test_cov_console
run-devserver: install
ifeq ($(USE_NGROK),true)
$(eval RUN_ARGS += --release)
@( \
python3 -m pip install pyngrok; \
ngrok start heliumedu --log stdout & \
)
endif
flutter run $(RUN_ARGS)
SENTRY_ENVIRONMENT ?= $(ENVIRONMENT)
FLUTTER_VERSION := $(shell tr -d '[:space:]' < .flutter-version)
build-docker-local: build-web
docker build \
--target frontend_web_local \
-t helium/frontend-web:$(PLATFORM)-latest \
-t helium/frontend-web:$(PLATFORM)-$(DOCKER_TAG_VERSION) \
.
build-docker:
mkdir -p $(DOCKER_CACHE_DIR)
docker buildx build \
--target frontend_web \
--build-arg FLUTTER_VERSION=$(FLUTTER_VERSION) \
--build-arg FIREBASE_AUTH_DOMAIN=$(FIREBASE_AUTH_DOMAIN) \
--build-arg RELEASE_VERSION=$(RELEASE_VERSION) \
--build-arg SENTRY_DIST=$(SENTRY_DIST) \
--build-arg SENTRY_DSN=$(SENTRY_DSN) \
--build-arg SENTRY_ENVIRONMENT=$(SENTRY_ENVIRONMENT) \
--cache-from=type=local,src=$(DOCKER_CACHE_DIR) \
--cache-to=type=local,dest=$(DOCKER_CACHE_DIR),mode=max \
-t helium/frontend-web:$(PLATFORM)-latest \
-t helium/frontend-web:$(PLATFORM)-$(DOCKER_TAG_VERSION) \
--platform=linux/$(PLATFORM) \
--load .
run-docker:
docker compose up -d
stop-docker:
docker compose stop
restart-docker: stop-docker run-docker
publish: build-docker
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/heliumedu
docker tag helium/frontend-web:$(PLATFORM)-$(DOCKER_TAG_VERSION) public.ecr.aws/heliumedu/helium/frontend-web:$(PLATFORM)-$(DOCKER_TAG_VERSION)
docker push public.ecr.aws/heliumedu/helium/frontend-web:$(PLATFORM)-$(DOCKER_TAG_VERSION)
promote:
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws/heliumedu
docker buildx imagetools create --prefer-index=false -t public.ecr.aws/heliumedu/helium/frontend-web:$(PLATFORM)-$(DOCKER_TAG_VERSION) public.ecr.aws/heliumedu/helium/frontend-web:$(PLATFORM)-$(SOURCE_TAG)
docker buildx imagetools create --prefer-index=false -t public.ecr.aws/heliumedu/helium/frontend-web:$(PLATFORM)-latest public.ecr.aws/heliumedu/helium/frontend-web:$(PLATFORM)-$(SOURCE_TAG)