webbrowser 1.2.1

Open URLs in web browsers available on a platform
Documentation
name: Android

on:
  push:
    branches-ignore: [ '**win**', '**linux**', '**macos**', '**bsd**', '**haiku**', '**wasm**', '**ios**' ]
  pull_request:
    branches: [ main ]
  schedule:
    - cron: '0 0 * * SUN'

env:
  CARGO_TERM_COLOR: always
  RUST_BACKTRACE: 1
  RUST_LOG: webbrowser=TRACE,tests=TRACE
  CARGO_APK_VERSION: '0.9.7'
  ANDROID_ARCH: x86_64
  ANDROID_TARGET: x86_64-linux-android

jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    if: ${{ !contains(github.event.head_commit.message, '#build-') || contains(github.event.head_commit.message, '#build-android') }}
    strategy:
      matrix:
        rust: [ stable ]
        api-level: [ 34 ]
        ndk-version: [ '27.1.12297006' ]
        cmake-version: [ '3.30.4' ]
    continue-on-error: ${{ matrix.rust != 'stable' && matrix.rust != 'beta' }}
    steps:
      - uses: actions/checkout@v3
        name: Checkout
      - name: Install rust version
        run: |
          rustup install ${{ matrix.rust }} --profile minimal
          rustup component add --toolchain ${{ matrix.rust }} rustfmt clippy
          rustup target add ${{ env.ANDROID_TARGET }}

      # Install cargo-apk
      - uses: actions/cache@v3
        name: Fetch cargo-apk from cache
        id: cargo-apk-cache
        with:
          path: ~/.cargo/bin/cargo-apk
          key: cargo-apk-${{ env.CARGO_APK_VERSION }}
      - name: Install cargo-apk
        if: steps.cargo-apk-cache.outputs.cache-hit != 'true'
        run: cargo install cargo-apk --version ${{ env.CARGO_APK_VERSION }}

      # Pre-build
      - name: Compile
        run: rustup run ${{ matrix.rust }} cargo apk build --target ${{ env.ANDROID_TARGET }}
        working-directory: tests/test-android-app
      - name: Compile tests
        run: rustup run ${{ matrix.rust }} cargo build --test test_android

      # Check if AVD is in cache, else create AVD
      - 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: AVD cache
        uses: actions/cache@v3
        id: avd-cache
        with:
          path: |
            ~/.android/avd/*
            ~/.android/adb*
          key: avd-${{ matrix.api-level }}
      - name: Create AVD
        if: steps.avd-cache.outputs.cache-hit != 'true'
        uses: reactivecircus/android-emulator-runner@v2
        with:
          arch: ${{ env.ANDROID_ARCH }}
          api-level: ${{ matrix.api-level }}
          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."

      # Run tests on emulator
      - name: Run tests
        uses: reactivecircus/android-emulator-runner@v2
        with:
          arch: ${{ env.ANDROID_ARCH }}
          api-level: ${{ matrix.api-level }}
          ndk: ${{ matrix.ndk-version }}
          cmake: ${{ matrix.cmake-version }}
          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: bash -c 'ANDROID_TARGET=${{ env.ANDROID_TARGET }} ANDROID_NDK_ROOT=$ANDROID_SDK_ROOT/ndk/${{ matrix.ndk-version }} rustup run ${{ matrix.rust }} cargo test --test test_android -- --ignored'

      # Code format, linting etc.
      - name: Check Code Formatting
        if: ${{ matrix.rust == 'stable' || matrix.rust == 'beta' }}
        run: cargo +${{ matrix.rust }} fmt --all -- --check
      - name: Lints
        if: ${{ matrix.rust == 'stable' || matrix.rust == 'beta' }}
        run: cargo +${{ matrix.rust }} clippy --target ${{ env.ANDROID_TARGET }} -- -D warnings