@@ -49,32 +49,80 @@ jobs:
4949 # Set JVM max heap via GRADLE_OPTS to avoid shell/PowerShell parsing issues with -Porg.gradle.jvmargs
5050 GRADLE_OPTS="-Xmx3g" ./gradlew assembleDebug
5151
52+ - name : Decode keystore (if provided)
53+ shell : bash
54+ env :
55+ RELEASE_KEYSTORE_BASE64 : ${{ secrets.RELEASE_KEYSTORE_BASE64 }}
56+ run : |
57+ set -euo pipefail
58+ if [ -n "${RELEASE_KEYSTORE_BASE64:-}" ]; then
59+ mkdir -p app/release
60+ echo "$RELEASE_KEYSTORE_BASE64" | base64 --decode > app/release/release-keystore.jks
61+ ls -l app/release/release-keystore.jks
62+ else
63+ echo "RELEASE_KEYSTORE_BASE64 not set; skipping keystore decode"
64+ fi
65+
5266 - name : Build Release APK
67+ env :
68+ RELEASE_KEYSTORE_BASE64 : ${{ secrets.RELEASE_KEYSTORE_BASE64 }}
69+ RELEASE_KEYSTORE_KEY : ${{ secrets.RELEASE_KEYSTORE_KEY }}
70+ RELEASE_KEYSTORE_SUBKEY : ${{ secrets.RELEASE_KEYSTORE_SUBKEY }}
5371 run : |
72+ set -euo pipefail
5473 # Set JVM max heap via GRADLE_OPTS to avoid shell/PowerShell parsing issues with -Porg.gradle.jvmargs
55- GRADLE_OPTS="-Xmx3g" ./gradlew assembleRelease
74+ GRADLE_OPTS="-Xmx3g"
75+
76+ # If keystore secret is present but file missing, decode it now (defensive)
77+ if [ -n "${RELEASE_KEYSTORE_BASE64:-}" ] && [ ! -f app/release/release-keystore.jks ]; then
78+ mkdir -p app/release
79+ echo "$RELEASE_KEYSTORE_BASE64" | base64 --decode > app/release/release-keystore.jks
80+ chmod 600 app/release/release-keystore.jks
81+ fi
82+
83+ # Build with signing properties if keystore exists and passwords provided
84+ if [ -f app/release/release-keystore.jks ] && [ -n "${RELEASE_KEYSTORE_KEY:-}" ] && [ -n "${RELEASE_KEYSTORE_SUBKEY:-}" ]; then
85+ echo "Keystore found — building signed release APK"
86+ ./gradlew assembleRelease -Pandroid.injected.signing.store.file=app/release/release-keystore.jks -Pandroid.injected.signing.store.password="${RELEASE_KEYSTORE_KEY}" -Pandroid.injected.signing.key.password="${RELEASE_KEYSTORE_SUBKEY}" -Pandroid.injected.signing.key.alias=release
87+ else
88+ echo "No keystore/passwords provided — building release APK without injected signing properties"
89+ ./gradlew assembleRelease
90+ fi
5691
5792 - name : Prepare artifacts
5893 run : |
94+ set -euo pipefail
5995 mkdir -p release_artifacts
60- # Paths from the repo
96+ # Standard apk paths
6197 DEBUG_APK=app/build/outputs/apk/debug/app-debug.apk
62- RELEASE_APK=app/release/app-release.apk
63- # Copy the same APK to ABI-labeled files. If your project generates ABI-specific APKs, replace these with the real files.
98+ RELEASE_APK=app/build/outputs/apk/release/app-release.apk
99+ RELEASE_APK_UNSIGN=app/build/outputs/apk/release/app-release-unsigned.apk
100+
101+
102+ COPIED=0
64103 if [ -f "$DEBUG_APK" ]; then
65- cp "$DEBUG_APK" release_artifacts/app-debug-universe.apk
66- cp "$DEBUG_APK" release_artifacts/app-debug-arm.apk
67- cp "$DEBUG_APK" release_artifacts/app-debug-arm64.apk
104+ cp "$DEBUG_APK" release_artifacts/app-debug.apk
105+ COPIED=$((COPIED+1))
68106 else
69- echo "Debug APK not found at $DEBUG_APK" && ls -R app/build/outputs || exit 1
107+ echo "Debug APK not found at $DEBUG_APK"
70108 fi
71109
72110 if [ -f "$RELEASE_APK" ]; then
73- cp "$RELEASE_APK" release_artifacts/app-release-universe.apk
74- cp "$RELEASE_APK" release_artifacts/app-release-arm.apk
75- cp "$RELEASE_APK" release_artifacts/app-release-arm64.apk
111+ cp "$RELEASE_APK" release_artifacts/app-release.apk
112+ COPIED=$((COPIED+1))
76113 else
77- echo "Release APK not found at $RELEASE_APK" && ls -R app || exit 1
114+ echo "Release APK not found at $RELEASE_APK"
115+ if [ -f "$RELEASE_APK" ]; then
116+ cp "$RELEASE_APK_UNSIGN" release_artifacts/app-release.apk
117+ COPIED=$((COPIED+1))
118+ else
119+ echo "Release APK not found at $RELEASE_APK_UNSIGN"
120+ fi
121+ fi
122+
123+ if [ $COPIED -ne 2 ]; then
124+ echo "Missing apk. Listing outputs for debugging:"
125+ ls -R app/build || true
78126 fi
79127
80128 - name : Create GitHub Release (use Gradle version, commit history and commit id)
84132 run : |
85133 set -euo pipefail
86134
87- # 1) 获取版本号(优先:app/build.gradle -> app/build.gradle.kts -> gradle.properties)
88135 VERSION=""
89136 if [ -f app/build.gradle ]; then
90137 VERSION=$(grep -m1 "versionName" app/build.gradle | sed -E "s/.*versionName[[:space:]]+['\"]([^'\"]+)['\"].*/\1/" || true)
@@ -97,31 +144,25 @@ jobs:
97144 fi
98145 VERSION=${VERSION:-"build-${GITHUB_RUN_ID}"}
99146
100- # 2) commit id(短 sha)和 commit history 作为 body
101147 COMMIT_ID=$(git rev-parse --short HEAD)
102148 BODY=$(git log --pretty=format:"%h %ad - %s (%an)" --date=short --no-merges -n 200)
103149
104- # 3) 构造 JSON payload(使用 jq 确保正确的 JSON 转义)
105150 if ! command -v jq >/dev/null 2>&1; then
106151 echo "jq is required but not installed in runner. Exiting."
107152 exit 1
108153 fi
109154 PAYLOAD=$(jq -n --arg tag "${COMMIT_ID}" --arg name "${VERSION}" --arg body "${BODY}" \
110155 '{ tag_name: $tag, name: $name, body: $body, draft: false, prerelease: false }')
111156
112- # 4) 调用 GitHub Releases API 创建 release(创建时为最新)
113157 RESPONSE=$(curl -s -X POST \
114158 -H "Authorization: token ${GITHUB_TOKEN}" \
115159 -H "Accept: application/vnd.github+json" \
116160 -H "Content-Type: application/json" \
117161 -d "${PAYLOAD}" \
118162 "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases")
119-
120- # 输出响应以便日志可见
121163 echo "GitHub release response:"
122164 echo "${RESPONSE}" | jq .
123165
124- # 5) 从响应中取 upload_url 并导出为步骤输出,供后续 upload-release-asset 使用
125166 UPLOAD_URL=$(echo "${RESPONSE}" | jq -r '.upload_url // empty')
126167 if [ -z "$UPLOAD_URL" ] || [ "$UPLOAD_URL" = "null" ]; then
127168 echo "Failed to create release or upload_url missing. Full response above."
@@ -132,50 +173,18 @@ jobs:
132173 - name : Skip turnstyle (not required)
133174 run : echo "Skipping turnstyle wrapper; uploading directly using upload-release-asset"
134175
135- - name : Upload APKs to release
136- uses : actions/upload-release-asset@v1
137- with :
138- upload_url : ${{ steps.create_release.outputs.upload_url }}
139- asset_path : release_artifacts/app-debug-arm.apk
140- asset_name : app-debug-arm.apk
141- asset_content_type : application/vnd.android.package-archive
142-
143- - name : Upload APKs to release (arm64)
144- uses : actions/upload-release-asset@v1
145- with :
146- upload_url : ${{ steps.create_release.outputs.upload_url }}
147- asset_path : release_artifacts/app-debug-arm64.apk
148- asset_name : app-debug-arm64.apk
149- asset_content_type : application/vnd.android.package-archive
150-
151- - name : Upload APKs to release (universe debug)
152- uses : actions/upload-release-asset@v1
153- with :
154- upload_url : ${{ steps.create_release.outputs.upload_url }}
155- asset_path : release_artifacts/app-debug-universe.apk
156- asset_name : app-debug-universe.apk
157- asset_content_type : application/vnd.android.package-archive
158-
159- - name : Upload Release APKs (arm)
160- uses : actions/upload-release-asset@v1
161- with :
162- upload_url : ${{ steps.create_release.outputs.upload_url }}
163- asset_path : release_artifacts/app-release-arm.apk
164- asset_name : app-release-arm.apk
165- asset_content_type : application/vnd.android.package-archive
166-
167- - name : Upload Release APKs (arm64)
176+ - name : Upload Debug APK to release
168177 uses : actions/upload-release-asset@v1
169178 with :
170179 upload_url : ${{ steps.create_release.outputs.upload_url }}
171- asset_path : release_artifacts/app-release-arm64 .apk
172- asset_name : app-release-arm64 .apk
180+ asset_path : release_artifacts/app-debug .apk
181+ asset_name : app-debug .apk
173182 asset_content_type : application/vnd.android.package-archive
174183
175- - name : Upload Release APKs (universe)
184+ - name : Upload Release APK to release
176185 uses : actions/upload-release-asset@v1
177186 with :
178187 upload_url : ${{ steps.create_release.outputs.upload_url }}
179- asset_path : release_artifacts/app-release-universe .apk
180- asset_name : app-release-universe .apk
188+ asset_path : release_artifacts/app-release.apk
189+ asset_name : app-release.apk
181190 asset_content_type : application/vnd.android.package-archive
0 commit comments