-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#9: refactored using using reactivecircus with matrix test for API Le…
- Loading branch information
Showing
2 changed files
with
189 additions
and
75 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
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 }}" | sed 's/refs\/heads\///' | sed 's/#/%23/')" | ||
giturl="https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:$branch_name" | ||
echo "check for PR or main branch using API: $giturl" | ||
prs=$(curl -s -X GET -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" $giturl) | ||
if [ $branch_name != 'main' ] && [ $(echo "$prs" | jq length) -eq 0 ]; then | ||
message_summary="Skip instrumented tests (no open PR found for branch $branch_name and not main branch)" | ||
echo "$message_summary" | ||
echo "$message_summary" >> $GITHUB_STEP_SUMMARY | ||
echo "PERFORM_TEST=0" >> "$GITHUB_OUTPUT" | ||
else | ||
echo "Do perform instrumented tests" | ||
echo "PERFORM_TEST=1" >> "$GITHUB_OUTPUT" | ||
fi | ||
- name: checkout source | ||
if: steps.check_pr.outputs.PERFORM_TEST != 0 | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: set up JDK 17 | ||
if: steps.check_pr.outputs.PERFORM_TEST != 0 | ||
uses: actions/setup-java@v4 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
cache: gradle | ||
|
||
- name: Cache Gradle packages | ||
if: steps.check_pr.outputs.PERFORM_TEST != 0 | ||
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 | ||
if: steps.check_pr.outputs.PERFORM_TEST != 0 | ||
run: chmod +x gradlew | ||
|
||
- name: Build with Gradle | ||
if: steps.check_pr.outputs.PERFORM_TEST != 0 | ||
uses: gradle/gradle-build-action@v3 | ||
|
||
- name: Enable KVM group perms | ||
if: steps.check_pr.outputs.PERFORM_TEST != 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 | ||
if: steps.check_pr.outputs.PERFORM_TEST != 0 | ||
id: determine-target | ||
run: | | ||
TARGET="google_apis" | ||
if [[ ${{ matrix.api-level }} -ge 30 ]]; then | ||
TARGET="aosp_atd" | ||
elif [[ ${{ matrix.api-level }} -le 27 ]]; then | ||
TARGET="default" | ||
fi | ||
echo "TARGET=$TARGET" >> "$GITHUB_OUTPUT" | ||
- name: AVD cache | ||
if: steps.check_pr.outputs.PERFORM_TEST != 0 | ||
uses: actions/cache@v4 | ||
id: avd-cache | ||
with: | ||
path: | | ||
~/.android/avd/* | ||
~/.android/adb* | ||
key: avd-ubuntu-${{ matrix.api-level }} | ||
|
||
- name: Create AVD and generate snapshot for caching | ||
if: steps.check_pr.outputs.PERFORM_TEST != 0 && 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 | ||
if: steps.check_pr.outputs.PERFORM_TEST != 0 | ||
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 | ||
if: always() | ||
with: | ||
name: test-results-${{ matrix.api-level }}-${{ steps.determine-target.outputs.TARGET }} | ||
path: | | ||
**/build/reports/* | ||
**/build/outputs/*/connected/* | ||
retention-days: 14 |