diff --git a/.github/workflows/android_ci.yml b/.github/workflows/android_ci.yml index e40e2d2..e50f709 100644 --- a/.github/workflows/android_ci.yml +++ b/.github/workflows/android_ci.yml @@ -9,21 +9,6 @@ jobs: JAVA_TOOL_OPTIONS: -Xmx4g steps: - - name: Check if PR exists or branch is main - id: check_pr - run: | - branch_name=$(echo ${GITHUB_REF#refs/heads/}) - prs=$(curl -s -X GET -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:${branch_name}") - pr_exists_or_main_branch=0 - if [ $branch_name != 'main' && $(echo "$prs" | jq length) -eq 0 ]; then - echo "Skip instrumented tests (no open PR found for branch $branch_name and not main branch)" - else - echo "Do perform instrumented tests" - pr_exists_or_main_branch=1 - fi - echo "pr_exists_or_main_branch=$pr_exists_or_main_branch" - echo "pr_exists_or_main_branch=$pr_exists_or_main_branch" >> "$GITHUB_OUTPUT" - - name: checkout source uses: actions/checkout@v4 with: @@ -57,7 +42,6 @@ jobs: run: ./gradlew clean build - name: Enable KVM group perms - if: steps.check_pr.outputs.pr_exists_or_main_branch != 0 # https://github.blog/changelog/2023-02-23-hardware-accelerated-android-virtualization-on-actions-windows-and-linux-larger-hosted-runners/ # Starting on February 23, 2023, Actions users of GitHub-hosted larger Linux runners will be able to make use of hardware acceleration for Android testing run: | @@ -65,27 +49,16 @@ jobs: sudo udevadm control --reload-rules sudo udevadm trigger --name-match=kvm - # - name: AVD cache - # uses: actions/cache@v4 - # id: avd-cache - # if: steps.check_pr.outputs.pr_exists_or_main_branch != 0 - # with: - # path: | - # ~/.android/avd/* - # ~/.android/adb* - # key: avd-33-aosp_atd-x86_64 - - - name: Perfom instrumented tests + - name: Perform instrumented API Level 33 Test uses: reactivecircus/android-emulator-runner@v2 id: perform-it continue-on-error: true - if: steps.check_pr.outputs.pr_exists_or_main_branch != 0 with: # run ``sdkmanager --list`` to see available images api-level: 33 target: aosp_atd arch: x86_64 channel: canary - emulator-boot-timeout: 150 + emulator-boot-timeout: 300 emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -logcat-output ${{ github.workspace }}/app/build/reports/avd33.log disable-animations: true script: ./gradlew connectedCheck @@ -101,10 +74,4 @@ jobs: with: name: Reports path: ${{ github.workspace }}/app/build/reports/ - retention-days: 14 - - - name: Check on CI failure - if: steps.perform-it.outcome != 'success' - run: | - echo "Instrumented tests did not finish with success" - exit 1 + retention-days: 14 \ No newline at end of file diff --git a/.github/workflows/connected_check_on_pr.yml b/.github/workflows/connected_check_on_pr.yml new file mode 100644 index 0000000..52c76b0 --- /dev/null +++ b/.github/workflows/connected_check_on_pr.yml @@ -0,0 +1,121 @@ +name: Instrumented Tests + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest # https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md + timeout-minutes: 60 + strategy: + # Allow tests to continue on other devices if they fail on one device. + fail-fast: false + matrix: + api-level: [ 27, 28, 29, 30, 31, 32, 33, 34 ] + env: + JAVA_TOOL_OPTIONS: -Xmx4g + + steps: + - name: Check if PR exists or branch is main + id: check_pr + run: | + branch_name=$(echo ${GITHUB_REF#refs/heads/}) + prs=$(curl -s -X GET -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:${branch_name}") + pr_exists_or_main_branch=0 + if [ $branch_name != 'main' && $(echo "$prs" | jq length) -eq 0 ]; then + echo "Skip instrumented tests (no open PR found for branch $branch_name and not main branch)" + exit 0 + else + echo "Do perform instrumented tests" + pr_exists_or_main_branch=1 + fi + echo "pr_exists_or_main_branch=$pr_exists_or_main_branch" + echo "pr_exists_or_main_branch=$pr_exists_or_main_branch" >> "$GITHUB_OUTPUT" + + - name: checkout source + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: gradle + + - name: Cache Gradle packages + uses: actions/cache@v4 + with: + path: ~/.gradle/caches + key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} + restore-keys: ${{ runner.os }}-gradle + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle + uses: gradle/gradle-build-action@v2 + + - name: Enable KVM group perms + if: steps.check_pr.outputs.pr_exists_or_main_branch != 0 + # https://github.blog/changelog/2023-02-23-hardware-accelerated-android-virtualization-on-actions-windows-and-linux-larger-hosted-runners/ + # Starting on February 23, 2023, Actions users of GitHub-hosted larger Linux runners will be able to make use of hardware acceleration for Android testing + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + + - name: Determine emulator target + id: determine-target + run: | + TARGET="google_apis" + if [[ ${{ matrix.api-level }} -ge 34 ]]; then + TARGET="aosp_atd" + fi + echo "TARGET=$TARGET" >> $GITHUB_OUTPUT + + - name: AVD cache + uses: actions/cache@v4 + id: avd-cache + if: steps.check_pr.outputs.pr_exists_or_main_branch != 0 + with: + path: | + ~/.android/avd/* + ~/.android/adb* + key: avd-ubuntu-${{ matrix.api-level }} + + - name: Create AVD and generate snapshot for caching + if: steps.avd-cache.outputs.cache-hit != 'true' + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: ${{ matrix.api-level }} + target: ${{ steps.determine-target.outputs.TARGET }} + arch: x86_64 + channel: canary + force-avd-creation: false + emulator-boot-timeout: 300 + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -logcat-output ${{ github.workspace }}/app/build/reports/avd${{ matrix.api-level }}.log + disable-animations: true + script: echo "Generated AVD ${{ matrix.api-level }} snapshot for caching." + + - name: Perfom instrumented tests + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: ${{ matrix.api-level }} + target: ${{ steps.determine-target.outputs.TARGET }} + arch: x86_64 + channel: canary + force-avd-creation: false + emulator-boot-timeout: 300 + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -logcat-output ${{ github.workspace }}/app/build/reports/avd${{ matrix.api-level }}.log + disable-animations: true + script: ./gradlew connectedCheck + + - name: Upload test results + uses: actions/upload-artifact@v4 + with: + name: test-results-${{ matrix.api-level }}-${{ steps.determine-target.outputs.TARGET }} + path: | + **/build/reports/* + **/build/outputs/*/connected/* + retention-days: 14