Skip to content

Commit

Permalink
#9: second try using reactivecircus emulated runner for API 33 only
Browse files Browse the repository at this point in the history
  • Loading branch information
arburk committed Feb 4, 2024
1 parent 01e0b34 commit cf910d1
Showing 1 changed file with 98 additions and 121 deletions.
219 changes: 98 additions & 121 deletions .github/workflows/android_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,129 +3,106 @@ name: Android CI
on: [push]

jobs:
prepare:
name: prepare actions
runs-on: ubuntu-latest # https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md

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"
build:
runs-on: ubuntu-latest
env:
JAVA_TOOL_OPTIONS: -Xmx4g

steps:
- 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
run: ./gradlew clean build


instrumented-tests:
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
api-level: [ 27, 28, 30, 33 ]
runs-on: ubuntu-latest # https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md
env:
JAVA_TOOL_OPTIONS: -Xmx4g

steps:
- name: SDKs - accept licenses
if: steps.check_pr.outputs.pr_exists_or_main_branch != 0
run: /bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null"

- 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: AVD cache
if: steps.check_pr.outputs.pr_exists_or_main_branch != 0
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ matrix.api-level }}

- name: Perfom instrumented tests
if: steps.check_pr.outputs.pr_exists_or_main_branch != 0
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.target }}
arch: x86_64
profile: Nexus 6
script: ./gradlew supportedSdksGroupDebugAndroidTest -Pandroid.testoptions.manageddevices.emulator.gpu="swiftshader_indirect" -Pandroid.experimental.testOptions.managedDevices.emulators.emulator.showKernelLogging=true --info --stacktrace --scan

quality-check:
runs-on: ubuntu-latest
needs: [build, instrumented-tests]

steps:
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Sonar checks
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew jacocoTestReport sonar

- name: Upload test results
uses: actions/upload-artifact@v4
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
- 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:
fetch-depth: 0

- name: set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: gradle

- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- 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
run: ./gradlew clean build

- name: SDKs - accept licenses
if: steps.check_pr.outputs.pr_exists_or_main_branch != 0
run: /bin/bash -c "yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses > /dev/null"

- 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: 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

- name: Perfom instrumented tests
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:
api-level: 33
script: ./gradlew connectedCheck

- name: Sonar checks
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew jacocoTestReport sonar

- name: Upload test results
uses: actions/upload-artifact@v4
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

0 comments on commit cf910d1

Please sign in to comment.