Skip to content

Android APK Build and Upload to Telegram & Artifacts #81

Android APK Build and Upload to Telegram & Artifacts

Android APK Build and Upload to Telegram & Artifacts #81

Workflow file for this run

name: Android APK Build and Upload to Telegram & Artifacts
on:
push:
branches:
- 'master'
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '17'
cache: 'gradle'
- name: Make gradlew executable
run: chmod +x ./gradlew
- name: Get Version Info
id: version_info
run: |
VERSION_INFO=$(./gradlew printVersionInfo --quiet | grep 'VERSION_INFO:' | sed 's/VERSION_INFO: //;s/ (.*)//')
echo "VERSION_INFO=$VERSION_INFO" >> $GITHUB_ENV
- name: Get Commit SHA and URL
run: |
COMMIT_SHA=$(git rev-parse --short HEAD)
REPO_URL="https://github.com/${{ github.repository }}"
COMMIT_URL="${REPO_URL}/commit/${COMMIT_SHA}"
echo "COMMIT_SHA=$COMMIT_SHA" >> $GITHUB_ENV
echo "COMMIT_URL=$COMMIT_URL" >> $GITHUB_ENV
- name: Build APK (Debug)
run: ./gradlew assembleDebug
- name: Build APK (Release)
run: ./gradlew assembleRelease
- name: Find APK filenames
id: find_apks
run: |
DEBUG_APK=$(find app/build/outputs/apk/debug/ -name "*.apk")
RELEASE_APK=$(find app/build/outputs/apk/release/ -name "*.apk")
echo "DEBUG_APK=$DEBUG_APK" >> $GITHUB_ENV
echo "RELEASE_APK=$RELEASE_APK" >> $GITHUB_ENV
- name: Decode and Save Keystore
run: |
echo "${{ secrets.KEYSTORE_BASE64 }}" | base64 --decode > /tmp/keystore.jks
- name: Sign the Release APK
run: |
${ANDROID_HOME}/build-tools/$(ls "${ANDROID_HOME}/build-tools/" | sort -V | tail -n 1)/apksigner sign \
--ks /tmp/keystore.jks \
--ks-key-alias ${{ secrets.KEY_ALIAS }} \
--ks-pass pass:${{ secrets.KEYSTORE_PASSWORD }} \
--key-pass pass:${{ secrets.KEY_PASSWORD }} \
--out "${{ env.RELEASE_APK }}" \
"${{ env.RELEASE_APK }}"
- name: Verify the signed APK
run: |
${ANDROID_HOME}/build-tools/$(ls "${ANDROID_HOME}/build-tools/" | sort -V | tail -n 1)/apksigner verify \
"${{ env.RELEASE_APK }}"
- name: Upload Debug APK to Telegram
run: |
curl -F document=@"${{ env.DEBUG_APK }}" \
-F chat_id=${{ secrets.TELEGRAM_CHAT_ID }} \
-F parse_mode=Markdown \
https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendDocument
- name: Upload Signed Release APK to Telegram
run: |
curl -F document=@"${{ env.RELEASE_APK }}" \
-F chat_id=${{ secrets.TELEGRAM_CHAT_ID }} \
-F parse_mode=Markdown \
https://api.telegram.org/bot${{ secrets.TELEGRAM_BOT_TOKEN }}/sendDocument
- name: Upload Debug APK as Artifact
uses: actions/upload-artifact@v3
with:
name: "Debug APK - ${{ env.DATE_TODAY }}"
path: ${{ env.DEBUG_APK }}
- name: Upload Signed Release APK as Artifact
uses: actions/upload-artifact@v3
with:
name: "Signed Release APK - ${{ env.DATE_TODAY }}"
path: "${{ env.RELEASE_APK }}"