From 12adc365c99ec60412c7a4ecc0060fd3bf3de789 Mon Sep 17 00:00:00 2001 From: Yawata Date: Sat, 5 Oct 2024 16:27:16 +0800 Subject: [PATCH] Update android.yml --- .github/workflows/android.yml | 88 ++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 42 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index e25ced5..fd48109 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -1,57 +1,61 @@ -name: Android CI +name: Android Release Build and Publish on: push: - branches: - - main - pull_request: - branches: - - main - workflow_dispatch: + tags: + - 'v*' # 当推送一个新的版本标签(例如 v1.0.0)时触发 jobs: build: - name: Build Android App + name: Build APK and Release runs-on: ubuntu-latest steps: - # Step 1: Checkout the repository - - name: Checkout Repository - uses: actions/checkout@v3 + # Step 1: Check out the repository + - name: Checkout repository + uses: actions/checkout@v3 - # Step 2: Set up JDK (Java 17 is required for Android projects) - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - distribution: 'zulu' - java-version: '17' + # Step 2: Set up JDK + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' - # Step 3: Grant execute permission for gradlew - - name: Grant execute permission for gradlew - run: chmod +x ./gradlew + # Step 3: Grant execution permissions for Gradle wrapper + - name: Grant execute permission for gradlew + run: chmod +x ./gradlew - # Step 4: Cache Gradle dependencies - - name: Cache Gradle packages - uses: actions/cache@v3 - with: - path: | - ~/.gradle/caches - ~/.gradle/wrapper - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: | - ${{ runner.os }}-gradle- + # Step 4: Build the release APK + - name: Build release APK + run: ./gradlew assembleRelease - # Step 5: Download Dependencies (Gradle Wrapper) - - name: Download Dependencies - run: ./gradlew --no-daemon clean build + # Step 5: Archive the generated APK + - name: Archive release APK + uses: actions/upload-artifact@v3 + with: + name: app-release.apk + path: app/build/outputs/apk/release/lobe-chat-android-beta.apk - # Step 6: Build APK - - name: Build Debug APK - run: ./gradlew --no-daemon assembleDebug + # Step 6: Create a GitHub Release and upload APK + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: false + prerelease: false - # Step 7: Upload artifact (optional) - - name: Upload APK - uses: actions/upload-artifact@v3 - with: - name: app-debug.apk - path: app/build/outputs/apk/debug/app-debug.apk + # Step 7: Upload APK to the Release + - name: Upload Release Asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: app/build/outputs/apk/release/app-release.apk + asset_name: app-release.apk + asset_content_type: application/vnd.android.package-archive