Last active
May 24, 2025 14:17
-
-
Save KvRae/b2f6fc34312b8f28033ac19ee32401e9 to your computer and use it in GitHub Desktop.
GitHub Action Android Pipeline
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 and Test | |
on: | |
workflow_dispatch: # Manual trigger from GitHub UI | |
jobs: | |
# ----------------------------------------------------- | |
# 🧪 Local Unit Test Job | |
# ----------------------------------------------------- | |
local_test_job: | |
name: Run Unit Tests | |
runs-on: ubuntu-latest | |
continue-on-error: true | |
steps: | |
- name: Checkout project | |
uses: actions/checkout@v2 | |
- name: Set up JDK 11 | |
uses: actions/setup-java@v1 | |
with: | |
java-version: 11 | |
- name: Print Java version | |
run: javac -version | |
- name: Make Gradle wrapper executable | |
run: chmod +x ./gradlew | |
- name: Restore Gradle Cache | |
uses: actions/cache@v2 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Run Unit Tests | |
run: ./gradlew testDebugUnitTest --continue | |
- name: Upload Unit Test Reports | |
if: ${{ always() }} | |
uses: actions/upload-artifact@v2 | |
with: | |
name: test-reports | |
path: '**/build/reports/tests/' | |
# ----------------------------------------------------- | |
# 📱 Android Instrumentation Test Job | |
# ----------------------------------------------------- | |
android_test_job: | |
name: Run Instrumentation Tests | |
runs-on: macos-latest | |
continue-on-error: true | |
steps: | |
- name: Checkout project | |
uses: actions/checkout@v2 | |
- name: Make Gradle wrapper executable | |
run: chmod +x ./gradlew | |
- name: Restore Gradle Cache | |
uses: actions/cache@v2 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Run Instrumentation Tests on Emulator | |
uses: reactivecircus/android-emulator-runner@v2 | |
with: | |
api-level: 29 | |
script: ./gradlew connectedAndroidTest | |
- name: Upload Android Test Reports | |
if: ${{ always() }} | |
uses: actions/upload-artifact@v2 | |
with: | |
name: android-test-reports | |
path: '**/build/reports/androidTests/' | |
# ----------------------------------------------------- | |
# 🏗️ APK Build Job | |
# ----------------------------------------------------- | |
build_job: | |
name: Build APK | |
runs-on: ubuntu-latest | |
continue-on-error: true | |
steps: | |
- name: Checkout project | |
uses: actions/checkout@v2 | |
- name: Restore Gradle Cache | |
uses: actions/cache@v2 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Make Gradle wrapper executable | |
run: chmod +x ./gradlew | |
- name: Assemble Debug APK | |
run: ./gradlew assembleDebug | |
- name: Upload APK Artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: apk | |
path: app/build/outputs/apk/debug/**.apk | |
# ----------------------------------------------------- | |
# 📣 Notification Job (only after all jobs) | |
# ----------------------------------------------------- | |
notification_job: | |
name: Notify Workflow Results | |
runs-on: ubuntu-latest | |
needs: [local_test_job, android_test_job, build_job] | |
steps: | |
- name: Determine Workflow Conclusion | |
uses: technote-space/workflow-conclusion-action@v1 | |
- name: Send Email Notification (only if failure) | |
if: failure() | |
uses: dawidd6/action-send-mail@v2 | |
with: | |
server_address: smtp.gmail.com | |
server_port: 465 | |
username: ${{ secrets.MAIL_USERNAME }} | |
password: ${{ secrets.MAIL_PASSWORD }} | |
subject: GitHub Actions Job result | |
body: | | |
Workflow: ${{ github.workflow }} | |
Repository: ${{ github.repository }} | |
Result: ${{ env.WORKFLOW_CONCLUSION }} | |
to: [email protected] | |
from: From Github Action |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment