Files
jinzhi/Makefile
T
2026-09-07 09:42:47 +08:00

56 lines
2.6 KiB
Makefile

.PHONY: runner run test lint apk ipa build-web rename_release_apk jinzhi_shorebird_android jinzhi_shorebird_ios jinzhi_shorebird_android_patch jinzhi_shorebird_ios_patch
WEB_API_URL ?= https://jinzhi.api.local
WEB_BASE_HREF ?= /flutter/
SHOREBIRD_TOKEN_FILE ?= $(HOME)/.shorebird_tokens/jinzhi.env
SHOREBIRD = if [ ! -f "$(SHOREBIRD_TOKEN_FILE)" ]; then echo "错误: 缺少 Shorebird token 文件: $(SHOREBIRD_TOKEN_FILE)"; exit 1; fi; set -a; . "$(SHOREBIRD_TOKEN_FILE)"; set +a; shorebird
GITVERSION := $(shell git describe --tags --always --dirty 2>/dev/null || git rev-parse --short HEAD)
RELEASE_VERSION ?= latest
PATCH_TRACK ?= staging
COMMON_DART_DEFINES := --dart-define="GITVERSION=$(GITVERSION)"
APP_VERSION := $(shell sed -n 's/^version: *//p' pubspec.yaml | head -n 1)
APK_VERSION_NAME := $(subst .,,${word 1,$(subst +, ,$(APP_VERSION))})
APK_VERSION_CODE := $(word 2,$(subst +, ,$(APP_VERSION)))
RELEASE_APK := jinzhi-$(APK_VERSION_NAME)-$(APK_VERSION_CODE)-release.apk
RELEASE_APK_DIR := build/app/outputs/flutter-apk
runner:
dart run build_runner build --delete-conflicting-outputs
run:
flutter run $(COMMON_DART_DEFINES) --dart-define=JINZHI_API_BASE_URL=http://localhost:8088
test:
flutter test
lint:
flutter analyze
apk:
flutter build apk --obfuscate --split-debug-info=./build/symbos $(COMMON_DART_DEFINES) --release --target-platform android-arm64
$(MAKE) rename_release_apk
rename_release_apk:
@test -f "$(RELEASE_APK_DIR)/app-release.apk" || (echo "错误: 未找到 release APK: $(RELEASE_APK_DIR)/app-release.apk"; exit 1)
cp "$(RELEASE_APK_DIR)/app-release.apk" "$(RELEASE_APK_DIR)/$(RELEASE_APK)"
@echo "Release APK: $(RELEASE_APK_DIR)/$(RELEASE_APK)"
ipa:
flutter build ipa --obfuscate --split-debug-info=./build/symbos $(COMMON_DART_DEFINES) --release
jinzhi_shorebird_android:
$(SHOREBIRD) release android --flutter-version=3.35.6 --split-debug-info=./build/symbos --target-platform android-arm64 --artifact apk -- --dart-define="GITVERSION=$(GITVERSION)"
$(MAKE) rename_release_apk
jinzhi_shorebird_ios:
$(SHOREBIRD) release ios --flutter-version=3.35.6 --split-debug-info=./build/symbos -- --dart-define="GITVERSION=$(GITVERSION)"
jinzhi_shorebird_android_patch:
$(SHOREBIRD) patch --platforms=android --release-version=$(RELEASE_VERSION) --split-debug-info=./build/symbos --track=$(PATCH_TRACK) -- --dart-define="GITVERSION=$(GITVERSION)"
jinzhi_shorebird_ios_patch:
$(SHOREBIRD) patch --platforms=ios --release-version=$(RELEASE_VERSION) --split-debug-info=./build/symbos --track=$(PATCH_TRACK) -- --dart-define="GITVERSION=$(GITVERSION)"
build-web:
API_BASE_URL=$(WEB_API_URL) BASE_HREF=$(WEB_BASE_HREF) bash scripts/build_web.sh