--- name: Android - Build and test on: pull_request: paths: - '**' - '!.github/workflows/**' - '.github/workflows/android-app.yml' - '!audits/**' - '!ci/**' - '!dist-assets/**' - '!docs/**' - '!graphics/**' - '!gui/**' - '!ios/**' - '!scripts/**' - '!windows/**' - '!**/**.md' workflow_dispatch: inputs: override_container_image: description: Override container image type: string required: false # Build if master is updated to ensure up-to-date caches are available push: branches: [master] jobs: prepare: name: Prepare runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v3 - name: Use custom container image if specified if: ${{ github.event.inputs.override_container_image != '' }} run: echo "inner_container_image=${{ github.event.inputs.override_container_image }}" >> $GITHUB_ENV - name: Use default container image and resolve digest if: ${{ github.event.inputs.override_container_image == '' }} run: | echo "inner_container_image=$(cat ./building/android-container-image.txt)" >> $GITHUB_ENV outputs: container_image: ${{ env.inner_container_image }} build: name: Build app and run unit tests needs: prepare runs-on: ubuntu-latest container: image: ${{ needs.prepare.outputs.container_image }} steps: # Fix for HOME path overridden by GH runners when building in containers, see: # https://github.com/actions/runner/issues/863 - name: Fix HOME path run: echo "HOME=/root" >> $GITHUB_ENV - name: Checkout repository uses: actions/checkout@v3 - name: Calculate native lib cache hash id: native-lib-cache-hash shell: bash run: | non_android_hash="$(git grep --cached -l '' -- ':!android/' \ | xargs -d '\n' sha1sum \ | sha1sum \ | awk '{print $1}')" echo "native_lib_hash=$non_android_hash" >> $GITHUB_OUTPUT - name: Cache native libraries uses: actions/cache@v3 id: cache-native-libs with: path: | ./android/app/build/extraJni ./build/relays.json key: android-native-libs-${{ runner.os }}-x86_64-${{ steps.native-lib-cache-hash.outputs.native_lib_hash}} - name: Build native libraries if: steps.cache-native-libs.outputs.cache-hit != 'true' env: RUSTFLAGS: --deny warnings ABI: x86_64 TARGET: x86_64-linux-android BUILD_TYPE: debug run: | ARCHITECTURES="$ABI" UNSTRIPPED_LIB_PATH="$CARGO_TARGET_DIR/$TARGET/$BUILD_TYPE/libmullvad_jni.so" STRIPPED_LIB_PATH="./android/app/build/extraJni/$ABI/libmullvad_jni.so" NDK_TOOLCHAIN_STRIP_TOOL="$NDK_TOOLCHAIN_DIR/x86_64-linux-android-strip" ./wireguard/build-wireguard-go.sh --android --no-docker cargo build --target $TARGET --verbose --package mullvad-jni --features api-override cargo run --bin relay_list > build/relays.json $NDK_TOOLCHAIN_STRIP_TOOL --strip-debug --strip-unneeded -o "$STRIPPED_LIB_PATH" "$UNSTRIPPED_LIB_PATH" - name: Build Android app uses: burrunan/gradle-cache-action@v1 with: job-id: jdk11 arguments: assembleDebug gradle-version: wrapper build-root-directory: android - name: Run unit tests uses: burrunan/gradle-cache-action@v1 with: job-id: jdk11 arguments: testDebugUnitTest gradle-version: wrapper build-root-directory: android execution-only-caches: true - name: Assemble instrumented test apk (app) uses: burrunan/gradle-cache-action@v1 with: job-id: jdk11 arguments: assembleAndroidTest gradle-version: wrapper build-root-directory: android execution-only-caches: true - name: Assemble instrumented test apk (mockapi) uses: burrunan/gradle-cache-action@v1 with: job-id: jdk11 arguments: :test:mockapi:assemble gradle-version: wrapper build-root-directory: android execution-only-caches: true - name: Upload apks uses: actions/upload-artifact@v3 with: name: apks path: | android/app/build/outputs/apk android/test/mockapi/build/outputs/apk if-no-files-found: error retention-days: 1 instrumented-tests: name: Run instrumented tests runs-on: [self-hosted, android-emulator] timeout-minutes: 30 needs: [build] strategy: fail-fast: false matrix: test-type: [app, mockapi] steps: - name: Checkout repository uses: actions/checkout@v3 - uses: actions/download-artifact@v3 with: name: apks path: android - name: Run instrumented test script shell: bash -ieo pipefail {0} env: AUTO_FETCH_TEST_HELPER_APKS: true run: | ./android/scripts/run-instrumented-tests.sh ${{ matrix.test-type }} - name: Upload instrumentation report (${{ matrix.test-type }}) uses: actions/upload-artifact@v3 if: always() with: name: ${{ matrix.test-type }}-instrumentation-report path: /tmp/mullvad-${{ matrix.test-type }}-instrumentation-report if-no-files-found: ignore retention-days: 1