Skip to content

Commit

Permalink
Testing device farm with Sync
Browse files Browse the repository at this point in the history
  • Loading branch information
nhachicha committed Dec 13, 2023
1 parent 135eca8 commit 831b059
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 3 deletions.
66 changes: 66 additions & 0 deletions .github/actions/run-android-device-farm-sync-test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: 'Run Android tests on Device Farm'
inputs:
apk-path:
required: true
apk-auxiliary-path:
required: true
app-id:
required: true
project-arn:
required: true
device-pool-arn:
required: true
arguments:
default: _
outputs:
test-results-path:
value: ${{ steps.get-test-results.outputs.results-path }}
runs:
using: "composite"
steps:
- name: Run the tests
uses: nhachicha/aws-devicefarm/test-application@034225295b7f7351606f1a752429d50dfbc43d58
id: run-tests
with:
project_arn: ${{ inputs.project-arn }}
device_pool_arn: ${{ inputs.device-pool-arn }}
app_file: ${{ inputs.apk-path }}
auxiliaryApp: ${{ inputs.apk-path }}
app_type: ANDROID_APP
test_type: APPIUM_PYTHON
test_package_file: https://github.com/realm/aws-devicefarm-sample-data/releases/download/0.3/sample_env_python3.zip
test_package_type: APPIUM_PYTHON_TEST_PACKAGE
test_spec_file: test_spec-${{ inputs.app-id }}.yaml
test_spec_type: APPIUM_PYTHON_TEST_SPEC
remote_src: true
test_spec: |
version: 0.1
phases:
install:
commands:
- export PYTHON_VERSION=3
test:
commands:
- adb shell am instrument -w -r io.realm.sync.testapp.test/androidx.test.runner.AndroidJUnitRunner | egrep 'OK \([0-9]+ test[s]?\)'
- run: |
Install-Module -Name AWSPowerShell -Force
echo "::group::Data"
echo (ConvertFrom-Json '${{ steps.run-tests.outputs.data }}' | ConvertTo-Json)
echo "::endgroup::"
Import-Module AWSPowerShell
$runs = Get-DFRunList -Arn ${{ inputs.project-arn }}
$jobs = Get-DFJobList -Arn $runs[0].Arn
$suites = Get-DFSuiteList -Arn $jobs[0].Arn
$fileArtifacts = Get-DFArtifactList -Arn $suites[1].Arn -Type File
echo "All File Artifacts:"
echo $fileArtifacts
$logCatArtifacts = $fileArtifacts | Where-Object { $_.Name -EQ "Logcat" }
echo "LogCat Artifacts:"
echo $logCatArtifacts
echo "::group::Logcat"
Invoke-WebRequest -Uri $logCatArtifacts[0].Url | Select-Object -Expand RawContent
echo "::endgroup::"
shell: pwsh
if: always()
name: Device Farm Output
34 changes: 34 additions & 0 deletions .github/workflows/include-check-cache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ on:
value: ${{ jobs.check-cache.outputs.packages-android-cache-hit }}
android-test-base-apk-cache-hit:
value: ${{ jobs.check-cache.outputs.android-test-base-apk-cache-hit }}
android-test-sync-apk-cache-hit:
value: ${{ jobs.check-cache.outputs.android-test-sync-apk-cache-hit }}
packages-macos-x64-cache-hit:
value: ${{ jobs.check-cache.outputs.packages-macos-x64-cache-hit }}
packages-macos-arm64-cache-hit:
Expand Down Expand Up @@ -63,6 +65,7 @@ jobs:
packages-jvm-cache-hit: ${{ steps.jvm-cache.outputs.cache-hit }}
packages-android-cache-hit: ${{ steps.android-cache.outputs.cache-hit }}
android-test-base-apk-cache-hit: ${{ steps.android-test-base-apk.outputs.cache-hit }}
android-test-sync-apk-cache-hit: ${{ steps.android-test-sync-apk.outputs.cache-hit }}
packages-macos-x64-cache-hit: ${{ steps.macos-x64-cache.outputs.cache-hit }}
packages-macos-arm64-cache-hit: ${{ steps.macos-arm64-cache.outputs.cache-hit }}
packages-ios-x64-cache-hit: ${{ steps.ios-x64-cache.outputs.cache-hit }}
Expand Down Expand Up @@ -276,6 +279,18 @@ jobs:
path: ./packages/test-base/build/outputs/apk/androidTest/debug/test-base-debug-androidTest.apk
key: android-base-test-apk-key-${{ steps.packages-cache-key.outputs.sha }}

#
# Android Sync Test APK
#
- name: Check Android Sync Test APK
id: android-test-sync-apk
uses: cmelchior/cache@main
with:
key: android-sync-test-apk-key-${{ steps.packages-cache-key.outputs.sha }}
path: |
./packages/test-sync/build/outputs/apk/androidTest/debug/test-sync-debug-androidTest.apk
./packages/test-sync/build/outputs/apk/debug/test-sync-debug.apk
- name: Save Android Test APK
uses: actions/upload-artifact@v3
if: always() && !cancelled() && steps.android-test-base-apk.outputs.cache-hit == 'true'
Expand All @@ -284,13 +299,32 @@ jobs:
path: ./packages/test-base/build/outputs/apk/androidTest/debug/test-base-debug-androidTest.apk
retention-days: 1

- name: Save Android Sync Test APK
uses: actions/upload-artifact@v3
if: always() && !cancelled() && steps.android-test-sync-apk.outputs.cache-hit == 'true'
with:
name: android-sync-test-apk-${{ steps.find-library-version.outputs.label }}
retention-days: 1
path: |
./packages/test-sync/build/outputs/apk/androidTest/debug/test-sync-debug-androidTest.apk
./packages/test-sync/build/outputs/apk/debug/test-sync-debug.apk
- name: Delete Android Test APK cache files
id: delete-cache-android-base-test-apk
uses: JesseTG/[email protected]
if: always() && !cancelled() && steps.android-test-base-apk.outputs.cache-hit == 'true'
with:
path: ./packages/test-base/build/outputs/apk/androidTest/debug/test-base-debug-androidTest.apk

- name: Delete Android Sync Test APK cache files
id: delete-cache-android-sync-test-apk
uses: JesseTG/[email protected]
if: always() && !cancelled() && steps.android-test-sync-apk.outputs.cache-hit == 'true'
with:
path: |
./packages/test-sync/build/outputs/apk/androidTest/debug/test-sync-debug-androidTest.apk
./packages/test-sync/build/outputs/apk/debug/test-sync-debug.apk
#
# MacOS arm64
#
Expand Down
36 changes: 33 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,10 @@ jobs:
working-directory: packages
run: ./gradlew :test-base:assembleAndroidTest -PignoreNativeLibs=true

- name: Build Android Sync Test Apk
working-directory: packages
run: ./gradlew :test-sync:packageDebug :test-sync:assembleAndroidTest -PignoreNativeLibs=true

- name: Build packages
working-directory: packages
run: ./gradlew publishCIPackages -Prealm.kotlin.targets=android -PignoreNativeLibs=true -Prealm.kotlin.mainHost=false
Expand All @@ -609,6 +613,14 @@ jobs:
path: ./packages/test-base/build/outputs/apk/androidTest/debug/test-base-debug-androidTest.apk
key: android-base-test-apk-key-${{ needs.check-cache.outputs.packages-sha }}

- name: Store build cache for Android Sync Test APK
uses: actions/cache@v3
with:
key: android-sync-test-apk-key-${{ needs.check-cache.outputs.packages-sha }}
path: |
./packages/test-sync/build/outputs/apk/androidTest/debug/test-sync-debug-androidTest.apk
./packages/test-sync/build/outputs/apk/debug/test-sync-debug.apk
# TODO Must match naming found in include-check-cache.yml
- name: Upload artifacts
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -1081,18 +1093,36 @@ jobs:
name: android-base-test-apk-${{ needs.check-cache.outputs.version-label }}
path: ./packages/test-base/build/outputs/apk/androidTest/debug/test-base-debug-androidTest.apk

- name: Restore Android Sync Test APK
uses: actions/download-artifact@v3
with:
name: android-sync-test-apk-${{ needs.check-cache.outputs.version-label }}
path: |
./packages/test-sync/build/outputs/apk/androidTest/debug/test-sync-debug-androidTest.apk
./packages/test-sync/build/outputs/apk/debug/test-sync-debug.apk
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_DEVICEFARM_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_DEVICEFARM_SECRET_ACCESS_KEY }}
aws-region: us-west-2

- name: Run the tests
uses: ./.github/actions/run-android-device-farm-test
# - name: Run the tests
# uses: ./.github/actions/run-android-device-farm-test
# id: run_android_tests
# with:
# apk-path: ${{ github.workspace }}/packages/test-base/build/outputs/apk/androidTest/debug/test-base-debug-androidTest.apk/test-base-debug-androidTest.apk
# app-id: io.realm.testapp.test
# project-arn: ${{ secrets.DEVICEFARM_PROJECT_ARN }}
# device-pool-arn: ${{ secrets.DEVICEFARM_POOL_ARN }}

- name: Run the Sync tests
uses: ./.github/actions/run-android-device-farm-sync-test
id: run_android_tests
with:
apk-path: ${{ github.workspace }}/packages/test-base/build/outputs/apk/androidTest/debug/test-base-debug-androidTest.apk/test-base-debug-androidTest.apk
apk-path: ${{ github.workspace }}/packages/test-sync/build/outputs/apk/androidTest/debug/test-sync-debug-androidTest.apk
apk-auxiliary-path: ${{ github.workspace }}/packages/test-sync/build/outputs/apk/debug/test-sync-debug.apk
app-id: io.realm.testapp.test
project-arn: ${{ secrets.DEVICEFARM_PROJECT_ARN }}
device-pool-arn: ${{ secrets.DEVICEFARM_POOL_ARN }}
Expand Down

0 comments on commit 831b059

Please sign in to comment.