修复 pubspbec.lock 文件编译的时候被修改的 bug,必须要保持锁定,除非主动升级

This commit is contained in:
Cody
2026-03-06 17:57:42 +08:00
parent b3b0b9cf05
commit 7ffaee7469
5 changed files with 65 additions and 0 deletions

View File

@@ -47,6 +47,7 @@ if [ "$FORMAT" = "aab" ]; then
cd "$APP_DIR"
flutter build appbundle \
--release \
--no-pub \
--dart-define-from-file=config/config.json \
--split-debug-info="$DEBUG_INFO_DIR" \
--obfuscate
@@ -57,6 +58,7 @@ else
cd "$APP_DIR"
flutter build apk \
--release \
--no-pub \
--dart-define-from-file=config/config.json \
--split-debug-info="$DEBUG_INFO_DIR" \
--obfuscate

View File

@@ -41,6 +41,7 @@ cd "$APP_DIR"
flutter build ipa \
--release \
--no-pub \
--dart-define-from-file=config/config.json \
--split-debug-info="$DEBUG_INFO_DIR" \
--obfuscate

View File

@@ -37,6 +37,7 @@ cd "$APP_DIR"
flutter build macos \
--release \
--no-pub \
--dart-define-from-file=config/config.json \
--split-debug-info="$DEBUG_INFO_DIR" \
--obfuscate

View File

@@ -39,6 +39,7 @@ cd "$APP_DIR"
flutter build windows \
--release \
--no-pub \
--dart-define-from-file=config/config.json \
--split-debug-info="$DEBUG_INFO_DIR" \
--obfuscate

60
scripts/pre-commit Normal file
View File

@@ -0,0 +1,60 @@
#!/bin/bash
# Git pre-commit hook提交前自动 formatanalyze 有 error 则拦截提交
#
# 安装bash scripts/setup.shsetup.sh 自动把本文件复制到 .git/hooks/pre-commit
# 手动安装cp scripts/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit
set -euo pipefail
ROOT_DIR="$(git rev-parse --show-toplevel)"
DART="$(command -v dart 2>/dev/null || echo "")"
if [[ -z "$DART" ]]; then
echo "[pre-commit] dart not found, skipping checks."
exit 0
fi
# ── pubspec.lock 保护 ────────────────────────────────────────────────────────
# flutter run / flutter build 会在未经授权的情况下触发 pub get 并修改 lock。
# 规则lock 有未暂存的改动(意外修改)→ 自动还原;
# 开发者主动 git add pubspec.lock 后(暂存)→ 正常放行。
LOCK_UNSTAGED=$(git diff --name-only pubspec.lock 2>/dev/null || true)
LOCK_STAGED=$(git diff --cached --name-only pubspec.lock 2>/dev/null || true)
if [[ -n "$LOCK_UNSTAGED" && -z "$LOCK_STAGED" ]]; then
git checkout HEAD -- pubspec.lock
echo "[pre-commit] pubspec.lock was auto-modified by flutter, restored to HEAD."
echo " To intentionally update: run 'dart pub get' or 'dart pub upgrade',"
echo " then 'git add pubspec.lock' before committing."
fi
# ── dart format + analyze ────────────────────────────────────────────────────
STAGED_DART=$(git diff --cached --name-only --diff-filter=ACM | grep '\.dart$' || true)
if [[ -z "$STAGED_DART" ]]; then
exit 0
fi
echo "[pre-commit] formatting staged dart files..."
echo "$STAGED_DART" | xargs dart format --line-length=80
echo "$STAGED_DART" | xargs git add
echo "[pre-commit] running dart analyze..."
cd "$ROOT_DIR"
ANALYZE_OUTPUT=$(dart analyze 2>&1)
if echo "$ANALYZE_OUTPUT" | grep -q "^ error"; then
echo "[pre-commit] dart analyze found errors, commit blocked."
echo "$ANALYZE_OUTPUT" | grep "^ error"
exit 1
fi
if echo "$ANALYZE_OUTPUT" | grep -q "^ warning"; then
echo "[pre-commit] dart analyze found warnings, commit blocked."
echo "$ANALYZE_OUTPUT" | grep "^ warning"
exit 1
fi
echo "[pre-commit] all checks passed."
exit 0