From 9f0a5621a501f93077b9fdf6fe7dbe5250841af6 Mon Sep 17 00:00:00 2001 From: Matt Hills Date: Thu, 3 Jul 2025 19:35:48 -0400 Subject: [PATCH 1/2] adding github action --- .github/workflows/android-release.yml | 163 ++++++++++++++++++++++++++ app/build.gradle.kts | 10 ++ 2 files changed, 173 insertions(+) create mode 100644 .github/workflows/android-release.yml diff --git a/.github/workflows/android-release.yml b/.github/workflows/android-release.yml new file mode 100644 index 0000000..5b5586d --- /dev/null +++ b/.github/workflows/android-release.yml @@ -0,0 +1,163 @@ +# GitHub Actions workflow for building and releasing Android APK +# This workflow builds a release APK and creates a GitHub release with the APK attached + +name: Android Release Build + +# Trigger the workflow only on version tags (e.g., v1.0.0, v2.1.3) +on: + push: + tags: + - 'v*' + +jobs: + build: + name: Build Release APK + runs-on: ubuntu-latest + + steps: + # Step 1: Checkout the repository code + - name: Checkout code + uses: actions/checkout@v4 + + # Step 2: Set up JDK 17 (required for Android Gradle Plugin 8.x) + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: gradle + + # Step 3: Grant execute permission for gradlew + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + # Step 4: Decode and prepare the keystore + # IMPORTANT: You need to configure the following secrets in your GitHub repository: + # - SIGNING_KEY : Base64 encoded keystore file + # - KEYSTORE_PASSWORD: Password for the keystore + # - KEY_ALIAS: Alias of the key in the keystore + # - KEY_PASSWORD: Password for the key + - name: Decode Keystore + env: + ANDROID_KEYSTORE: ${{ secrets.SIGNING_KEY }} + run: | + echo "$ANDROID_KEYSTORE" | base64 --decode > ${{ github.workspace }}/keystore.jks + + # Step 5: Build Release APK with signing + - name: Build Release APK + env: + KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }} + KEY_ALIAS: ${{ secrets.KEY_ALIAS }} + KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} + run: | + ./gradlew assembleRelease \ + -Pandroid.injected.signing.store.file=${{ github.workspace }}/keystore.jks \ + -Pandroid.injected.signing.store.password=$KEYSTORE_PASSWORD \ + -Pandroid.injected.signing.key.alias=$KEY_ALIAS \ + -Pandroid.injected.signing.key.password=$KEY_PASSWORD + + # Step 6: Get the tag name for artifact naming + - name: Get tag name + id: tag + run: echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + + # Step 7: Upload APK as artifact with versioned name + - name: Upload APK + uses: actions/upload-artifact@v4 + with: + name: lchat-${{ steps.tag.outputs.tag }} + path: app/build/outputs/apk/release/app-release.apk + + # Step 8: Clean up keystore + - name: Clean up keystore + if: always() + run: rm -f ${{ github.workspace }}/keystore.jks + + # Step 9: Run tests (optional but recommended) + - name: Run Unit Tests + run: ./gradlew test + + # Step 10: Upload test results + - name: Upload Test Results + uses: actions/upload-artifact@v4 + if: always() + with: + name: test-results + path: app/build/test-results/ + + release: + name: Create GitHub Release + needs: build + runs-on: ubuntu-latest + + steps: + # Step 1: Checkout code for changelog generation + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + # Step 2: Get the tag name + - name: Get tag name + id: tag + run: echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT + + # Step 3: Download APK artifact + - name: Download APK + uses: actions/download-artifact@v4 + with: + name: lchat-${{ steps.tag.outputs.tag }} + path: ./artifacts + + # Step 4: Rename APK file + - name: Rename APK + run: mv ./artifacts/app-release.apk ./artifacts/lchat-${{ steps.tag.outputs.tag }}.apk + + # Step 5: Create GitHub Release + - name: Create Release + uses: softprops/action-gh-release@v1 + with: + tag_name: ${{ steps.tag.outputs.tag }} + name: Release ${{ steps.tag.outputs.tag }} + body: | + ## LChat Release + + ### What's New + - Built from commit: ${{ github.sha }} + - Build number: ${{ github.run_number }} + + ### Download + Download the APK file attached below. + + ### Installation + 1. Enable "Install from Unknown Sources" in your Android settings + 2. Download the APK file + 3. Open the downloaded file to install + + --- + *This release was automatically generated by GitHub Actions* + files: ./artifacts/lchat-${{ steps.tag.outputs.tag }}.apk + draft: false + prerelease: false + + # Step 6: Clean up artifacts + - name: Clean up artifacts + if: always() + run: rm -rf ./artifacts + +# Required Secrets Configuration: +# Go to Settings > Secrets and variables > Actions in your GitHub repository and add: +# +# 1. SIGNING_KEY +# - Generate a keystore: keytool -genkey -v -keystore release-key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias your-alias +# - Convert to base64: base64 -i release-key.jks | pbcopy (on macOS) or base64 release-key.jks | xclip (on Linux) +# - Paste the base64 string as the secret value +# +# 2. KEYSTORE_PASSWORD +# - The password you used when creating the keystore +# +# 3. KEY_ALIAS +# - The alias you specified when creating the keystore (e.g., "your-alias") +# +# 4. KEY_PASSWORD +# - The password for the specific key (often the same as keystore password) \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e0380b5..607d5f4 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -31,6 +31,16 @@ android { ) } } + + applicationVariants.all { + val variant = this + variant.outputs + .map { it as com.android.build.gradle.internal.api.BaseVariantOutputImpl } + .forEach { output -> + val outputFileName = "lchat-${variant.versionName}-${variant.name}.apk" + output.outputFileName = outputFileName + } + } compileOptions { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 From 5c8aba646611b6d707f344b1856e06e8e8b84217 Mon Sep 17 00:00:00 2001 From: Matt Hills Date: Thu, 3 Jul 2025 19:55:45 -0400 Subject: [PATCH 2/2] fixing how apk rename is done --- .github/workflows/android-release.yml | 32 ++++++++++++--------------- app/build.gradle.kts | 2 +- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/.github/workflows/android-release.yml b/.github/workflows/android-release.yml index 5b5586d..0ab870c 100644 --- a/.github/workflows/android-release.yml +++ b/.github/workflows/android-release.yml @@ -65,26 +65,14 @@ jobs: - name: Upload APK uses: actions/upload-artifact@v4 with: - name: lchat-${{ steps.tag.outputs.tag }} - path: app/build/outputs/apk/release/app-release.apk + name: localchat-${{ steps.tag.outputs.tag }} + path: app/build/outputs/apk/release/localchat-*-release.apk # Step 8: Clean up keystore - name: Clean up keystore if: always() run: rm -f ${{ github.workspace }}/keystore.jks - # Step 9: Run tests (optional but recommended) - - name: Run Unit Tests - run: ./gradlew test - - # Step 10: Upload test results - - name: Upload Test Results - uses: actions/upload-artifact@v4 - if: always() - with: - name: test-results - path: app/build/test-results/ - release: name: Create GitHub Release needs: build @@ -106,12 +94,20 @@ jobs: - name: Download APK uses: actions/download-artifact@v4 with: - name: lchat-${{ steps.tag.outputs.tag }} + name: localchat-${{ steps.tag.outputs.tag }} path: ./artifacts # Step 4: Rename APK file - name: Rename APK - run: mv ./artifacts/app-release.apk ./artifacts/lchat-${{ steps.tag.outputs.tag }}.apk + run: | + # Find the APK file (should be localchat-*-release.apk) + APK_FILE=$(find ./artifacts -name "localchat-*-release.apk" | head -n 1) + if [ -z "$APK_FILE" ]; then + echo "Error: No APK file found" + exit 1 + fi + # Rename to include tag version + mv "$APK_FILE" "./artifacts/localchat-${{ steps.tag.outputs.tag }}.apk" # Step 5: Create GitHub Release - name: Create Release @@ -120,7 +116,7 @@ jobs: tag_name: ${{ steps.tag.outputs.tag }} name: Release ${{ steps.tag.outputs.tag }} body: | - ## LChat Release + ## LocalChat Release ### What's New - Built from commit: ${{ github.sha }} @@ -136,7 +132,7 @@ jobs: --- *This release was automatically generated by GitHub Actions* - files: ./artifacts/lchat-${{ steps.tag.outputs.tag }}.apk + files: ./artifacts/localchat-${{ steps.tag.outputs.tag }}.apk draft: false prerelease: false diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 607d5f4..63a67e1 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -37,7 +37,7 @@ android { variant.outputs .map { it as com.android.build.gradle.internal.api.BaseVariantOutputImpl } .forEach { output -> - val outputFileName = "lchat-${variant.versionName}-${variant.name}.apk" + val outputFileName = "localchat-${variant.versionName}-${variant.name}.apk" output.outputFileName = outputFileName } }