Skip to content

Generate APK AAB and Upload as Artifact #21

Generate APK AAB and Upload as Artifact

Generate APK AAB and Upload as Artifact #21

name: Generate APK AAB and Upload as Artifact
env:
# The name of the main module repository
main_project_module: app
# The name of the app
app_name: Preface
on:
push:
branches:
- 'release/**'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Set Current Date As Env Variable
- name: Set current date as env variable
run: echo "date_today=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
# Set Repository Name As Env Variable
- name: Set repository name as env variable
run: echo "repository_name=$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" >> $GITHUB_ENV
- name: Set Up JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu' # See 'Supported distributions' for available options
java-version: '17'
cache: 'gradle'
# Ensure Android SDK and Build Tools Are Available
- name: Ensure Android SDK in Path
run: |
echo "PATH=$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/build-tools/33.0.0:$PATH" >> $GITHUB_ENV
echo "ANDROID_SDK_ROOT=$ANDROID_HOME" >> $GITHUB_ENV
- name: Load Google Service File
env:
DATA: ${{ secrets.GOOGLE_SERVICES_JSON }}
run: echo $DATA | base64 -di > app/google-services.json
- name: Load Secrets XML File
env:
DATA: ${{ secrets.SECRETS_XML }}
run: echo $DATA | base64 -di > app/src/main/res/values/secrets.xml
- name: Change Wrapper Permissions
run: chmod +x ./gradlew
# Run Tests Build
- name: Run Gradle Tests
run: ./gradlew test
# Run Build Project
- name: Build Gradle Project
run: ./gradlew build
- name: Decode KeyStore
run: echo "${{ secrets.SIGNINGKEYBASE64 }}" | base64 -d > preface-keystore.jks
- name: Build App
run: ./gradlew assembleRelease
# Sign APK
- name: Sign APK
run: |
jarsigner -verbose -sigalg SHA256withRSA -digestalg SHA-256 \
-keystore preface-keystore.jks \
-storepass "${{ secrets.KEYSTORE_PASSWORD }}" \
app/build/outputs/apk/release/app-release-unsigned.apk \
"${{ secrets.KEY_ALIAS }}"
# Align APK
- name: Align APK
run: |
zipalign -v 4 app/build/outputs/apk/release/app-release-unsigned.apk app/build/outputs/apk/release/app-release.apk
# Upload Release APK as Artifact
- name: Upload Release APK
uses: actions/upload-artifact@v4
with:
name: Preface-App
path: app/build/outputs/apk/release/app-release.apk