Last active
October 21, 2025 10:46
-
-
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: | |
| # ----------------------------------------------------- | |
| # 🧪 Unit Test Job | |
| # ----------------------------------------------------- | |
| unit_tests: | |
| name: Run Unit Tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK 11 | |
| uses: actions/setup-java@v3 | |
| with: | |
| distribution: temurin | |
| 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@v3 | |
| 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@v4 | |
| with: | |
| name: unit-test-reports | |
| path: '**/build/reports/tests/' | |
| # ----------------------------------------------------- | |
| # 📱 Instrumentation Test Job | |
| # ----------------------------------------------------- | |
| instrumentation_tests: | |
| name: Run Instrumentation Tests | |
| runs-on: macos-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Make Gradle wrapper executable | |
| run: chmod +x ./gradlew | |
| - name: Restore Gradle Cache | |
| uses: actions/cache@v3 | |
| 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 Instrumentation Test Reports | |
| if: always() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: instrumentation-test-reports | |
| path: '**/build/reports/androidTests/' | |
| # ----------------------------------------------------- | |
| # 🏗️ Build APK Job | |
| # ----------------------------------------------------- | |
| build_apk: | |
| name: Build APK | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Make Gradle wrapper executable | |
| run: chmod +x ./gradlew | |
| - name: Restore Gradle Cache | |
| uses: actions/cache@v3 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} | |
| restore-keys: ${{ runner.os }}-gradle- | |
| - name: Assemble Debug APK | |
| run: ./gradlew assembleDebug | |
| - name: Upload APK Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: debug-apk | |
| path: app/build/outputs/apk/debug/*.apk | |
| # ----------------------------------------------------- | |
| # 📣 Notification Job | |
| # ----------------------------------------------------- | |
| notify: | |
| name: Notify Workflow Results | |
| runs-on: ubuntu-latest | |
| needs: [unit_tests, instrumentation_tests, build_apk] | |
| steps: | |
| - name: Determine Workflow Conclusion | |
| uses: technote-space/workflow-conclusion-action@v1 | |
| - name: Send Email Notification (on failure) | |
| if: failure() | |
| uses: dawidd6/action-send-mail@v3 | |
| with: | |
| server_address: smtp.gmail.com | |
| server_port: 465 | |
| username: ${{ secrets.MAIL_USERNAME }} | |
| password: ${{ secrets.MAIL_PASSWORD }} | |
| subject: GitHub Actions - Build Failed | |
| body: | | |
| Workflow: ${{ github.workflow }} | |
| Repository: ${{ github.repository }} | |
| Branch: ${{ github.ref }} | |
| Status: ${{ env.WORKFLOW_CONCLUSION }} | |
| Commit: ${{ github.sha }} | |
| to: ${{ secrets.MAIL_RECIPIENT }} | |
| from: ${{ secrets.MAIL_USERNAME }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment