2222 steps :
2323 - name : Checkout
2424 uses : actions/checkout@v4
25+ with :
26+ # versionCode 由 build.gradle.kts 的 gitCommitCount() 取 git rev-list --count HEAD,
27+ # 浅克隆(默认 depth=1)会得到 1,必须拉完整历史,否则 Release APK 版本号错乱。
28+ fetch-depth : 0
2529
2630 - name : Set up JDK 17
2731 uses : actions/setup-java@v4
5862 fi
5963 echo "✓ tag 与 versionName 一致: $ver_in_code(tag 后缀: ${tag_ver#$tag_base})"
6064
65+ # 校验 versionCode 单调递增:versionCode = git commit count,rebase/squash 改写历史
66+ # 可能让 commit count 变小,导致新版本 versionCode <= 旧版本、升级判定失效。
67+ # 取按提交时间倒序最近的非当前 tag,算其 commit count,要求当前 HEAD 更大。
68+ # 仅打 tag 触发时校验;workflow_dispatch(手动,无 tag)跳过。
69+ - name : Verify versionCode monotonic
70+ if : startsWith(github.ref, 'refs/tags/v')
71+ run : |
72+ set -e
73+ cur_vc=$(git rev-list --count HEAD)
74+ prev_tag=$(git tag --sort=-creatordate | grep -vE "^${GITHUB_REF_NAME}$" | head -1)
75+ if [[ -z "$prev_tag" ]]; then
76+ echo "无历史 tag,跳过 versionCode 单调校验(首次发版)"
77+ echo "当前 versionCode(commit count) = $cur_vc"
78+ exit 0
79+ fi
80+ prev_vc=$(git rev-list --count "$prev_tag")
81+ echo "上个 Release($prev_tag) versionCode = $prev_vc"
82+ echo "当前(${GITHUB_REF_NAME}) versionCode = $cur_vc"
83+ if [[ "$cur_vc" -le "$prev_vc" ]]; then
84+ echo "::error::versionCode 回退: 当前 $cur_vc <= 上个 Release($prev_tag) $prev_vc。通常因 rebase/squash 改写历史使 commit count 变小。请确保新版本在旧 tag 之上线性推进。"
85+ exit 1
86+ fi
87+ echo "✓ versionCode 单调递增: $prev_vc -> $cur_vc"
88+
6189 - name : Restore release keystore
6290 env :
6391 # keystore 文件以 base64 存入 Secret,避免二进制文件被破坏。
@@ -84,6 +112,11 @@ jobs:
84112 - name : Grant execute permission for gradlew
85113 run : chmod +x ./gradlew
86114
115+ # 发版质量门禁:跑单元测试,失败即中止,避免发出回归包。
116+ # 只跑 universal debug 变体:单测逻辑与 flavor 无关,跑全 flavor 6 变体是重复编译。
117+ - name : Run unit tests
118+ run : ./gradlew :app:testUniversalDebugUnitTest
119+
87120 # 一次性构建全部 flavor 的 release APK(universal/armsolo/x86solo)
88121 # --stacktrace:构建失败时输出完整调用栈,便于在 CI 定位 OOM/内存类根因。
89122 - name : Build all flavor Release APKs
0 commit comments