Build APKs (Preview) #202
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build APKs (Preview) | |
| on: | |
| workflow_dispatch: # Allow manual triggering | |
| jobs: | |
| build: | |
| name: Build Preview APK | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Java and Android SDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '21' # Adjust the Java version as needed | |
| distribution: 'temurin' | |
| - name: Decode Keystore | |
| id: decode_keystore | |
| uses: timheuer/base64-to-file@v1 | |
| with: | |
| fileName: 'keystore/key.jks' | |
| encodedString: ${{ secrets.SIGN_KEY }} | |
| - name: Extract Version Name and Version Code | |
| run: | | |
| # Extract versionName and versionCode from build.gradle | |
| BASE_VERSION_NAME=$(cat music/build.gradle | grep -oP 'versionName "\K[^"]*') | |
| VERSION_CODE=$(cat music/build.gradle | grep -oP 'versionCode \K\d+') | |
| # Get the short Git commit SHA (first 7 characters) | |
| COMMIT_ID=$(git rev-parse --short HEAD) | |
| # Append the commit ID to the version name | |
| VERSION_NAME="${BASE_VERSION_NAME}-${COMMIT_ID}" | |
| echo "Version Name: $VERSION_NAME" | |
| echo "Version Code: $VERSION_CODE" | |
| # Set these values as environment variables for later steps | |
| echo "VERSION_NAME=$VERSION_NAME" >> $GITHUB_ENV | |
| echo "VERSION_CODE=$VERSION_CODE" >> $GITHUB_ENV | |
| - name: Accept Android SDK licenses | |
| run: yes | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --licenses | |
| - name: Build Release APK | |
| run: | | |
| chmod +x ./gradlew | |
| ./gradlew clean assembleFossRelease --no-build-cache --rerun-tasks | |
| env: | |
| SIGNING_KEY_ALIAS: ${{ secrets.ALIAS }} | |
| SIGNING_KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} | |
| SIGNING_STORE_PASSWORD: ${{ secrets.KEY_STORE_PASSWORD }} | |
| - name: Move APKs to Temporary Directory | |
| run: | | |
| # Create a dedicated directory for the APKs | |
| mkdir -p ${{ runner.temp }}/apks | |
| # Find all APKs, preserve their architecture prefix/name, and append the version name | |
| find music/ -name "*.apk" | while read -r apk; do | |
| filename=$(basename "$apk") | |
| name_without_ext="${filename%.*}" | |
| new_filename="${name_without_ext}-${{ env.VERSION_NAME }}.apk" | |
| echo "Moving $filename to $new_filename" | |
| mv "$apk" "${{ runner.temp }}/apks/$new_filename" | |
| done | |
| ### Separate Upload Steps for Each Architecture ### | |
| - name: Archive arm64-v8a APK | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.VERSION_NAME }}-arm64-v8a | |
| path: ${{ runner.temp }}/apks/*arm64-v8a*.apk | |
| if-no-files-found: ignore | |
| - name: Archive armeabi-v7a APK | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.VERSION_NAME }}-armeabi-v7a | |
| path: ${{ runner.temp }}/apks/*armeabi-v7a*.apk | |
| if-no-files-found: ignore | |
| - name: Archive x86_64 APK | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.VERSION_NAME }}-x86_64 | |
| path: ${{ runner.temp }}/apks/*x86_64*.apk | |
| if-no-files-found: ignore | |
| - name: Archive x86 APK | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.VERSION_NAME }}-x86 | |
| path: ${{ runner.temp }}/apks/*x86*.apk | |
| if-no-files-found: ignore | |
| - name: Archive Universal APK | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.VERSION_NAME }}-universal | |
| path: ${{ runner.temp }}/apks/*universal*.apk | |
| if-no-files-found: ignore | |
| # Catch-all in case ABI splits aren't enabled and a standard non-arch APK is generated | |
| - name: Archive Base APK | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.VERSION_NAME }}-Base | |
| path: | | |
| ${{ runner.temp }}/apks/*.apk | |
| !${{ runner.temp }}/apks/*arm64-v8a*.apk | |
| !${{ runner.temp }}/apks/*armeabi-v7a*.apk | |
| !${{ runner.temp }}/apks/*x86*.apk | |
| !${{ runner.temp }}/apks/*x86_64*.apk | |
| !${{ runner.temp }}/apks/*universal*.apk | |
| if-no-files-found: ignore |