Skip to content

Android Release Build #41

Android Release Build

Android Release Build #41

Workflow file for this run

name: Android Release Build
on:
workflow_dispatch:
inputs:
name:
description: "Android APK Release"
default: "Android Release"
required: true
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
build:
name: Build APK
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'
# Load google-services.json
- name: Decode google-services.json and google maps api key and add to system env
env:
GOOGLE_MAPS_API_KEY: ${{secrets.GOOGLE_MAPS_API_KEY}}
GOOGLE_SERVICES: ${{ secrets.GOOGLE_SERVICES }}
run: |
echo "$GOOGLE_SERVICES" | base64 --decode > ./app/google-services.json
MAPS_API_KEY=$(echo "$GOOGLE_MAPS_API_KEY" | base64 --decode)
echo "MAPS_API_KEY=$MAPS_API_KEY" >> $GITHUB_ENV
- name: Set permissions for google-services.json
run: chmod 644 ./app/google-services.json
# Decode the private key and certificate, then create the keystore
- name: Decode private key and certificate, create keystore
env:
SIGNING_PRIVATE_KEY: ${{ secrets.SIGNING_PRIVATE_KEY }}
SIGNING_CERTIFICATE: ${{ secrets.SIGNING_CERTIFICATE }}
run: |
# Create a temporary directory for the keystore
mkdir -p ~/.keystore
# Decode the private key and certificate from the secrets and save them as PEM files
echo "$SIGNING_PRIVATE_KEY" > ~/.keystore/private_key.pem
echo "$SIGNING_CERTIFICATE" > ~/.keystore/certificate.pem
# Create a PKCS12 keystore from the private key and certificate
openssl pkcs12 -export \
-inkey ~/.keystore/private_key.pem \
-in ~/.keystore/certificate.pem \
-out ~/.keystore/test-release.p12 \
-name testalias \
-passout pass:testpass
# Convert the PKCS12 keystore to JKS format (which Android uses)
keytool -importkeystore \
-srckeystore ~/.keystore/test-release.p12 \
-srcstorepass testpass \
-srcstoretype PKCS12 \
-destkeystore ~/.keystore/test-release.keystore \
-deststoretype JKS \
-storepass testpass \
-keypass testpass \
-alias testalias
# Set the path to the keystore as an environment variable
echo "KEYSTORE_FILE=$(readlink -f ~/.keystore/test-release.keystore)" >> $GITHUB_ENV
- name: Build APK Release with Custom Key
env:
KEYSTORE_PASSWORD: testpass
KEY_ALIAS: testalias
KEY_PASSWORD: testpass
run: |
echo "Keystore_file is: $KEYSTORE_FILE" && \
echo $(readlink -f ~/.keystore/test-release.keystore) &&
./gradlew clean assembleRelease --info
- name: Extract SHA-1 Fingerprint from Release Keystore
id: extract_sha
run: |
SHA1=$(keytool -list -v \
-keystore $KEYSTORE_FILE \
-alias testalias \
-storepass testpass | grep 'SHA1' | awk '{print $2}')
echo "SHA1=${SHA1}" >> $GITHUB_ENV
echo "SHA1 fingerprint: ${SHA1}"
- name: List APK files
run: |
find app/build/outputs/apk -type f
- name: Upload APK
uses: actions/upload-artifact@v3
with:
name: "${{ github.event.inputs.name }}-Release-APK"
path: app/build/outputs/apk/release/*.apk
- name: Create GitHub release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.run_number }}
release_name: ${{ github.event.inputs.name }} (#${{ github.run_number }})
draft: false
prerelease: false
- name: Upload Release Asset
id: 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: TravelPouch-Release.apk
asset_content_type: application/vnd.android.package-archive