Skip to content

Comment in PR with generated builds. #4079

Comment in PR with generated builds.

Comment in PR with generated builds. #4079

Workflow file for this run

name: Android CI
on: [push, pull_request, workflow_dispatch]
permissions:
contents: read
actions: read
pull-requests: write
concurrency:
group: build-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
build:
name: Run tests and generate APK
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- name: Cache packages
id: cache-packages
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-packages-${{ runner.os }}-${{ hashFiles('**/*.gradle', '**/*.gradle.kts', 'gradle.properties') }}
restore-keys: gradle-packages-${{ runner.os }}
- name: Access test login credentials
run: |
echo "TEST_USER_NAME=${{ secrets.TEST_USER_NAME }}" >> local.properties
echo "TEST_USER_PASSWORD=${{ secrets.TEST_USER_PASSWORD }}" >> local.properties
- name: AVD cache
if: github.event_name != 'pull_request'
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-tablet-api-24
- name: Create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true' && github.event_name != 'pull_request'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 24
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: echo "Generated AVD snapshot for caching."
- name: Run Instrumentation tests
if: github.event_name != 'pull_request'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 24
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
profile: Nexus 10
script: |
adb shell content insert --uri content://settings/system --bind name:s:accelerometer_rotation --bind value:i:0
adb shell content insert --uri content://settings/system --bind name:s:user_rotation --bind value:i:0
adb emu geo fix 37.422131 -122.084801
./gradlew connectedBetaDebugAndroidTest --stacktrace
- name: Run Unit tests with unified coverage
if: github.event_name != 'pull_request'
run: ./gradlew -Pcoverage testBetaDebugUnitTestUnifiedCoverage --stacktrace
- name: Run Unit tests without unified coverage
if: github.event_name == 'pull_request'
run: ./gradlew -Pcoverage testBetaDebugUnitTestCoverage --stacktrace
- name: Upload Test Report to Codecov
if: github.event_name != 'pull_request'
run: |
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov -f "app/build/reports/jacoco/testBetaDebugUnitTestUnifiedCoverage/testBetaDebugUnitTestUnifiedCoverage.xml" -Z
- name: Generate betaDebug APK
run: bash ./gradlew assembleBetaDebug --stacktrace
- name: Upload betaDebug APK
uses: actions/upload-artifact@v4
id: beta_artifact
with:
name: betaDebugAPK
path: app/build/outputs/apk/beta/debug/app-*.apk
- name: Generate prodDebug APK
run: bash ./gradlew assembleProdDebug --stacktrace
- name: Upload prodDebug APK
uses: actions/upload-artifact@v4
id: prod_artifact
with:
name: prodDebugAPK
path: app/build/outputs/apk/prod/debug/app-*.apk
- name: Delete Old Comments
if: github.event_name == 'pull_request'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
COMMENTS=$(gh api repos/${{ github.repository }}/issues/$PR_NUMBER/comments --jq '.[] | select(.body | startswith("✅ APKs available for download")) | .id')
if [ -n "$COMMENTS" ]; then
echo "Found old comments, deleting..."
for COMMENT_ID in $COMMENTS; do
gh api --method DELETE repos/${{ github.repository }}/issues/comments/$COMMENT_ID || exit 1
done
fi
- name: Post Updated Comment
if: github.event_name == 'pull_request'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
BETA_APK_URL="${{ steps.beta_artifact.outputs.artifact-url }}"
PROD_APK_URL="${{ steps.prod_artifact.outputs.artifact-url }}"
COMMENT="✅ APKs available for download:
- 🔵 [Download Beta Debug APK]($BETA_APK_URL)
- 🔴 [Download Prod Debug APK]($PROD_APK_URL)"
gh pr comment $PR_NUMBER --body "$COMMENT"