APK Builder #66
Workflow file for this run
This file contains 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: APK Builder | |
on: | |
workflow_dispatch: | |
inputs: | |
tag_name: | |
required: true | |
type: string | |
description: "Version tag for this release (e.g., v0.1.0)" | |
default: "v0.1.0" | |
build_type: | |
required: true | |
type: choice | |
description: "Select the build type (debug or release)" | |
options: | |
- debug | |
- release | |
default: debug | |
permissions: | |
contents: write | |
jobs: | |
build: | |
name: Build APK | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the repository | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
# Set up the Java Development Kit | |
- name: Set up JDK | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
# Load google-services.json from GitHub Secrets | |
- name: Load Google Services configuration | |
env: | |
DATA: ${{ secrets.GOOGLE_SERVICES }} | |
run: echo "$DATA" | base64 -d > app/google-services.json | |
# Load and decode Google Maps API Key into local.properties | |
- name: Load and Decode Google Maps API Key | |
env: | |
DATA: ${{ secrets.LOCAL_PROPERTIES }} | |
run: | | |
echo "$DATA" | base64 -d | grep "MAPS_API_KEY" >> local.properties | |
# Load the Perspective API Key from GitHub Secrets | |
- name: Load Perspective API Key | |
env: | |
PERSPECTIVE_API_KEY: ${{ secrets.PERSPECTIVE_API_KEY }} | |
run: | | |
echo "::add-mask::$PERSPECTIVE_API_KEY" | |
echo "PERSPECTIVE_API_KEY=${PERSPECTIVE_API_KEY}" >> local.properties | |
# Load the keystore (.jks) file from GitHub Secrets | |
- name: Load Keystore file | |
env: | |
DATA: ${{ secrets.KEYSTORE_BASE64 }} | |
run: echo "$DATA" | base64 -d > keystore.jks | |
# Set environment variables for keystore passwords | |
- name: Set Keystore Environment Variables | |
env: | |
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }} | |
KEYSTORE_ALIAS: ${{ secrets.KEYSTORE_ALIAS }} | |
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} | |
run: | | |
echo "::add-mask::$KEYSTORE_PASSWORD" | |
echo "::add-mask::$KEYSTORE_ALIAS" | |
echo "::add-mask::$KEY_PASSWORD" | |
# Grant execute permission for Gradle wrapper | |
- name: Make gradlew executable | |
run: chmod +x ./gradlew | |
# Build APK with appropriate configuration and detailed logs | |
- name: Build APK with logs | |
env: | |
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }} | |
KEYSTORE_ALIAS: ${{ secrets.KEYSTORE_ALIAS }} | |
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} | |
run: | | |
if [ "${{ inputs.build_type }}" == "release" ]; then | |
./gradlew assembleRelease | |
else | |
./gradlew assembleDebug | |
fi | |
# Locate and list the generated APK files | |
- name: Find and list APK files | |
id: apkpath | |
run: | | |
if [ "${{ inputs.build_type }}" == "release" ]; then | |
find app/build/outputs/apk/release/ -name "*.apk" -exec ls -lh {} \; | |
echo "apk_path=$(find app/build/outputs/apk/release/*.apk)" >> $GITHUB_ENV | |
else | |
find app/build/outputs/apk/debug/ -name "*.apk" -exec ls -lh {} \; | |
echo "apk_path=$(find app/build/outputs/apk/debug/*.apk)" >> $GITHUB_ENV | |
fi | |
# Create a Git tag for the release | |
- name: Create Git Tag | |
id: tag | |
run: | | |
git tag ${{ inputs.tag_name }} | |
git push origin ${{ inputs.tag_name }} | |
# Upload the generated APK as a build artifact | |
- name: Upload APK to GitHub Artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: streetworkapp-${{ inputs.build_type }} | |
path: ${{ env.apk_path }} | |
retention-days: 90 | |
# Release the APK on GitHub with the specified tag | |
- name: Publish Release on GitHub | |
uses: softprops/action-gh-release@v2 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ inputs.tag_name }} | |
files: ${{ env.apk_path }} | |
draft: false | |
token: ${{ secrets.GITHUB_TOKEN }} |