5555 echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_ENV
5656 echo "Extracted versionName: $VERSION_NAME"
5757
58- # 7. 检查目标 Release 是否存在
59- - name : Check if Release exists
58+ # 7. 检查目标 Release 是否存在以及是否已有 APK
59+ - name : Check if Release exists and has APK
6060 id : check_release
6161 run : |
6262 TAG_NAME="v${{ env.VERSION_NAME }}"
@@ -65,16 +65,33 @@ jobs:
6565 if echo "$RESPONSE" | grep -q '"id":'; then
6666 echo "Release $TAG_NAME exists"
6767 echo "release_exists=true" >> $GITHUB_ENV
68+
69+ # 检查是否已有 APK 文件
70+ ASSETS_URL=$(echo "$RESPONSE" | jq -r '.assets_url')
71+ if [ "$ASSETS_URL" != "null" ]; then
72+ ASSETS_RESPONSE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" "$ASSETS_URL")
73+ APK_COUNT=$(echo "$ASSETS_RESPONSE" | jq '[.[] | select(.name | endswith(".apk"))] | length')
74+ if [ "$APK_COUNT" -gt 0 ]; then
75+ echo "Release already has $APK_COUNT APK file(s), skipping upload"
76+ echo "has_apk=true" >> $GITHUB_ENV
77+ else
78+ echo "Release has no APK files"
79+ echo "has_apk=false" >> $GITHUB_ENV
80+ fi
81+ else
82+ echo "has_apk=false" >> $GITHUB_ENV
83+ fi
6884 else
6985 echo "Release $TAG_NAME does not exist"
7086 echo "release_exists=false" >> $GITHUB_ENV
87+ echo "has_apk=false" >> $GITHUB_ENV
7188 fi
7289 env :
7390 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
7491
75- # 8. 上传 APK 到现有 Release(如果存在 )
92+ # 8. 上传 APK 到现有 Release(仅当 Release 存在且没有 APK 时 )
7693 - name : Upload APK to Existing Release
77- if : env.release_exists == 'true'
94+ if : env.release_exists == 'true' && env.has_apk == 'false'
7895 uses : softprops/action-gh-release@v2
7996 with :
8097 tag_name : v${{ env.VERSION_NAME }}
84101
85102 # 9. 删除 Release 中的旧 APK(保留最新上传的)
86103 - name : Clean up old APKs from Release
87- if : env.release_exists == 'true'
104+ if : env.release_exists == 'true' && env.has_apk == 'false'
88105 run : |
89106 TAG_NAME="v${{ env.VERSION_NAME }}"
90107 # 获取 release 中的 assets
0 commit comments