From 2146ffd1e811627edda311170ab9cff8422fc326 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=A4nge?= Date: Thu, 5 Sep 2024 15:27:43 +0200 Subject: [PATCH 1/6] Update github workflows --- .github/workflows/android-test.yml | 98 ++++++++++++++++++++++++++++++ .github/workflows/changelog.yml | 2 +- .github/workflows/ci.yml | 39 +++--------- 3 files changed, 107 insertions(+), 32 deletions(-) create mode 100644 .github/workflows/android-test.yml diff --git a/.github/workflows/android-test.yml b/.github/workflows/android-test.yml new file mode 100644 index 00000000..8a738466 --- /dev/null +++ b/.github/workflows/android-test.yml @@ -0,0 +1,98 @@ +name: Android Emulator Tests +on: [ push, pull_request ] + +jobs: + check-if-tests-exist: + runs-on: ubuntu-latest + outputs: + status: ${{ steps.check-androidTest.outputs.NOT_EMPTY }} + min-sdk-version: ${{ steps.get-sdk-version.outputs.MIN_SDK_VERSION }} + target-sdk-version: ${{ steps.get-sdk-version.outputs.TARGET_SDK_VERSION }} + app-id: ${{ steps.get-app-id.outputs.APP_ID }} + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: "recursive" + - name: Check if androidTest folder is not empty + run: | + echo "NOT_EMPTY=$([ "$(ls -A app/src/androidTest)" ] && echo 'true' || echo 'false')" + echo "NOT_EMPTY=$([ "$(ls -A app/src/androidTest)" ] && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT + id: check-androidTest + - name: Get min and target sdk + if: steps.check-androidTest.outputs.NOT_EMPTY == 'true' + id: get-sdk-version + run: | + echo "MIN_SDK_VERSION=$(cat app/build.gradle | grep minSdkVersion | rev | cut -d' ' -f 1 | rev)" >> $GITHUB_OUTPUT + echo "TARGET_SDK_VERSION=$(cat app/build.gradle | grep targetSdkVersion | rev | cut -d' ' -f 1 | rev)" >> $GITHUB_OUTPUT + - name: Get app ID + id: get-app-id + run: | + echo "APP_ID=$(cat app/build.gradle | grep applicationId | rev | cut -d' ' -f 1 | rev | tr -d '"')" >> $GITHUB_OUTPUT + + test: + needs: check-if-tests-exist + if: needs.check-if-tests-exist.outputs.status == 'true' + runs-on: ubuntu-latest + strategy: + matrix: + api-level: [34, "${{ needs.check-if-tests-exist.outputs.min-sdk-version }}", "${{ needs.check-if-tests-exist.outputs.target-sdk-version }}"] + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: 'recursive' + + - name: Enable KVM group perms + 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: Gradle cache + uses: gradle/gradle-build-action@v3 + + - name: AVD cache + uses: actions/cache@v4 + id: avd-cache + with: + path: | + ~/.android/avd/* + ~/.android/adb* + key: avd-${{ matrix.api-level }} + + - name: Set up JDK environment + uses: actions/setup-java@v3 + with: + distribution: 'zulu' + java-version: 17 + + - 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: ${{ matrix.api-level >= 30 && 'google_apis' || 'default' }} + arch: ${{ matrix.api-level < 21 && 'x86' || 'x86_64' }} + force-avd-creation: false + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none + disable-animations: false + script: echo "Generated AVD snapshot for caching." + + - name: Run connected tests + uses: ReactiveCircus/android-emulator-runner@v2 + with: + api-level: ${{ matrix.api-level }} + target: ${{ matrix.api-level >= 30 && 'google_apis' || 'default' }} + arch: ${{ matrix.api-level < 21 && 'x86' || 'x86_64' }} + force-avd-creation: false + emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none + disable-animations: true + script: | + adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}} || true + adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}}.test || true + adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}}.androidTest || true + ./gradlew :app:connectedCheck --stacktrace + adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}} || true + adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}}.test || true + adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}}.androidTest || true diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index b20a40da..6e50db11 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -2,7 +2,7 @@ name: Changelog Generation on: release: - types: [released] + types: [published] workflow_dispatch: jobs: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 694228ee..9e60fe60 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,55 +1,32 @@ -name: Continuous integration - +name: Continuous Integration on: [push, pull_request] jobs: test: - name: Unit Tests runs-on: ubuntu-20.04 steps: - name: Checkout uses: actions/checkout@v3 with: submodules: "recursive" + - name: Set up JDK environment uses: actions/setup-java@v3 with: distribution: "zulu" java-version: 17 + - name: Make gradlew executable run: chmod +x ./gradlew + - name: Setup Gradle uses: gradle/gradle-build-action@v2 + - name: Run local unit tests run: bash ./gradlew test --stacktrace - - name: Android Test Report - uses: asadmansr/android-test-report-action@v1.2.0 - - #androidTest: - # name: Instrumented Tests - # runs-on: macOS-latest - # steps: - # - uses: actions/checkout@v2 - # with: - # submodules: 'recursive' - # - name: Set up JDK 1.8 - # uses: actions/setup-java@v1 - # with: - # java-version: 1.8 - # - name: Make gradlew executable - # run: chmod +x ./gradlew - # - name: Run Instrumented Tests - # uses: reactivecircus/android-emulator-runner@v1 - # with: - # api-level: 29 - # arch: x86 - # disable-animations: true - # script: ./gradlew connectedAndroidTest --stacktrace - apk: - name: Build APK + build: runs-on: ubuntu-20.04 - steps: - name: Checkout uses: actions/checkout@v3 @@ -68,5 +45,5 @@ jobs: - name: Setup Gradle uses: gradle/gradle-build-action@v2 - - name: Build debug APK - run: ./gradlew assembleDebug + - name: Build the app + run: bash ./gradlew build --stacktrace From 6757bd0a28ce7b6389b25b395d101ae7dc9efdb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=A4nge?= Date: Thu, 5 Sep 2024 15:33:41 +0200 Subject: [PATCH 2/6] Set the severity of missing translations to warning instead of error --- app/build.gradle | 4 ++++ app/lint.xml | 5 +++++ 2 files changed, 9 insertions(+) create mode 100644 app/lint.xml diff --git a/app/build.gradle b/app/build.gradle index d0212794..e631ad57 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -58,6 +58,10 @@ android { jvmTarget = JavaVersion.VERSION_17.toString() } + lint { + lintConfig = file("lint.xml") + } + room { schemaDirectory "$projectDir/schemas" } diff --git a/app/lint.xml b/app/lint.xml new file mode 100644 index 00000000..9dc3b537 --- /dev/null +++ b/app/lint.xml @@ -0,0 +1,5 @@ + + + + + From 20f19f179d39e10734bcff15a9aa3661e738725b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=A4nge?= Date: Thu, 5 Sep 2024 15:51:31 +0200 Subject: [PATCH 3/6] Fix file permission in `android-test.yml` --- .github/workflows/android-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/android-test.yml b/.github/workflows/android-test.yml index 8a738466..e499e2f5 100644 --- a/.github/workflows/android-test.yml +++ b/.github/workflows/android-test.yml @@ -92,6 +92,7 @@ jobs: adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}} || true adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}}.test || true adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}}.androidTest || true + chmod +x gradlew ./gradlew :app:connectedCheck --stacktrace adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}} || true adb uninstall ${{needs.check-if-tests-exist.outputs.app-id}}.test || true From c8d98985d456256515660cc5aa66966beb70f287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=A4nge?= Date: Thu, 5 Sep 2024 15:53:32 +0200 Subject: [PATCH 4/6] Change file permission for `gradlew` from `644` to `755` --- gradlew | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 gradlew diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 From e45f596bf07d91df9f3b1dc6d6e203dc2df87f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=A4nge?= Date: Thu, 5 Sep 2024 16:02:38 +0200 Subject: [PATCH 5/6] Update `ci.yml` to upload the debug apk --- .github/workflows/ci.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e60fe60..4998731f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,3 +47,12 @@ jobs: - name: Build the app run: bash ./gradlew build --stacktrace + + - name: Build debug apk + run: bash ./gradlew assembleDebug + + - name: Upload debug apk + uses: actions/upload-artifact@v4 + with: + name: debug-apk + path: app/build/outputs/apk/debug/*.apk \ No newline at end of file From 62950aafad0e381a0a6ce19904b30485710fbdeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=A4nge?= Date: Thu, 5 Sep 2024 16:11:52 +0200 Subject: [PATCH 6/6] Explicitly include lint check in `ci.yml` --- .github/workflows/ci.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4998731f..fe5b0a92 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,6 +45,15 @@ jobs: - name: Setup Gradle uses: gradle/gradle-build-action@v2 + - name: Run lint check + run: bash ./gradlew lint + + - name: Upload lint result + uses: actions/upload-artifact@v4 + with: + name: lint-results-debug + path: app/build/reports/lint-results-debug.html + - name: Build the app run: bash ./gradlew build --stacktrace