From d615f5d0308d3e3e4e8e8ccdeeed2f12df65ed5d Mon Sep 17 00:00:00 2001 From: LZX <1820455493@qq.com> Date: Tue, 20 Oct 2026 00:10:17 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E6=B7=BB=E5=8A=A0=20GitHub=20Actions=20?= =?UTF-8?q?=E5=AE=98=E6=96=B9=E8=87=AA=E5=8A=A8=E5=8C=96=20Release=20?= =?UTF-8?q?=E5=8F=91=E7=89=88=E6=B5=81=E6=B0=B4=E7=BA=BF=E4=B8=8E=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E5=85=9C=E5=BA=95=E7=AD=BE=E5=90=8D=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 76 +++++++++++++++++++++++++++++++++++ .gitignore | 1 + app/build.gradle.kts | 7 ++++ 3 files changed, 84 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8ab6695 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,76 @@ +name: Release OpenLoc APKs + +on: + push: + tags: + - 'v*' + workflow_dispatch: + +permissions: + contents: write + +jobs: + build: + name: Build & Publish Release + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: '21' + cache: 'gradle' + + - name: Grant Execute Permission for Gradlew + run: chmod +x gradlew + + - name: Restore Keystore from Secrets (If Configured) + env: + KEYSTORE_BASE64: ${{ secrets.KEYSTORE_BASE64 }} + KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }} + KEY_ALIAS: ${{ secrets.KEY_ALIAS }} + KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} + run: | + if [ -n "$KEYSTORE_BASE64" ]; then + echo "Restoring official keystore..." + echo "$KEYSTORE_BASE64" | base64 -d > app/openloc.jks + cat < keystore.properties + storeFile=openloc.jks + storePassword=${KEYSTORE_PASSWORD} + keyAlias=${KEY_ALIAS} + keyPassword=${KEY_PASSWORD} + EOF + else + echo "No custom keystore secret provided, fallback signing will be used." + fi + + - name: Run Tests & Build Release APKs + run: ./gradlew testDebugUnitTest assembleRelease --stacktrace + + - name: Prepare Architecture Assets + run: | + TAG_NAME="${GITHUB_REF_NAME:-latest}" + cd app/build/outputs/apk/release/ + cp app-universal-release.apk "OpenLoc-${TAG_NAME}-universal.apk" + cp app-arm64-v8a-release.apk "OpenLoc-${TAG_NAME}-arm64-v8a.apk" + cp app-armeabi-v7a-release.apk "OpenLoc-${TAG_NAME}-armeabi-v7a.apk" + cp app-x86_64-release.apk "OpenLoc-${TAG_NAME}-x86_64.apk" + cp app-x86-release.apk "OpenLoc-${TAG_NAME}-x86.apk" + ls -la OpenLoc-*.apk + + - name: Publish GitHub Release & Upload Assets + uses: softprops/action-gh-release@v2 + with: + files: | + app/build/outputs/apk/release/OpenLoc-*-universal.apk + app/build/outputs/apk/release/OpenLoc-*-arm64-v8a.apk + app/build/outputs/apk/release/OpenLoc-*-armeabi-v7a.apk + app/build/outputs/apk/release/OpenLoc-*-x86_64.apk + app/build/outputs/apk/release/OpenLoc-*-x86.apk + generate_release_notes: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 70a4214..dac21e4 100644 --- a/.gitignore +++ b/.gitignore @@ -54,6 +54,7 @@ captures/ *.jks *.keystore keystore.properties +keystore_base64.txt # OS-specific files .DS_Store diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 86d933c..3644ffe 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -46,6 +46,13 @@ android { storePassword = props.getProperty("storePassword") keyAlias = props.getProperty("keyAlias") keyPassword = props.getProperty("keyPassword") + } else { + // CI/CD 或未配置密钥时平滑降级,确保构建永远不抛错中断 + val debugConfig = getByName("debug") + storeFile = debugConfig.storeFile + storePassword = debugConfig.storePassword + keyAlias = debugConfig.keyAlias + keyPassword = debugConfig.keyPassword } } }