name: android build scripts

on: [ push, pull_request ]

jobs:
  build-main-on-linux:
    name: android main on linux
    runs-on: ubuntu-20.04
    strategy:
      matrix:
        ndk-version: [ 'r21e-linux-x86_64', 'r22b-linux-x86_64', 'r23-linux' ]
    defaults:
      run:
        shell: bash
    steps:
      - uses: actions/checkout@v2
      - name: set up adopt jdk 8
        uses: actions/setup-java@v2.2.0
        with:
          distribution: 'adopt'
          java-version: '8'
      - name: set up android ndk
        run: |
          curl -s "https://dl.google.com/android/repository/android-ndk-${{ matrix.ndk-version }}.zip" -o ndk.zip
          unzip -q -o ndk.zip -d .ndk
          echo "ANDROID_NDK_ROOT=$PWD/.ndk/$(ls .ndk)" >> $GITHUB_ENV
      - name: run the build script
        run: ./android.sh -d --enable-android-media-codec --enable-android-zlib
      - name: print build logs
        if: ${{ always() }}
        run: cat build.log
      - name: print ffbuild logs
        if: ${{ failure() }}
        run: '[[ -f ./src/ffmpeg/ffbuild/config.log ]] && tail -50 ./src/ffmpeg/ffbuild/config.log'
  build-lts-on-linux:
    name: android lts on linux
    runs-on: ubuntu-20.04
    strategy:
      matrix:
        ndk-version: [ 'r21e-linux-x86_64', 'r22b-linux-x86_64', 'r23-linux' ]
    defaults:
      run:
        shell: bash
    steps:
      - uses: actions/checkout@v2
      - name: set up adopt jdk 8
        uses: actions/setup-java@v2.2.0
        with:
          distribution: 'adopt'
          java-version: '8'
      - name: set up android ndk
        run: |
          curl -s "https://dl.google.com/android/repository/android-ndk-${{ matrix.ndk-version }}.zip" -o ndk.zip
          unzip -q -o ndk.zip -d .ndk
          echo "ANDROID_NDK_ROOT=$PWD/.ndk/$(ls .ndk)" >> $GITHUB_ENV
      - name: run the build script
        run: ./android.sh -d --lts --enable-android-media-codec --enable-android-zlib
      - name: print build logs
        if: ${{ always() }}
        run: cat build.log
      - name: print ffbuild logs
        if: ${{ failure() }}
        run: '[[ -f ./src/ffmpeg/ffbuild/config.log ]] && tail -50 ./src/ffmpeg/ffbuild/config.log'
  build-main-on-macos:
    name: android main on macos
    runs-on: macos-10.15
    strategy:
      matrix:
        ndk-version: [ 'r21e-darwin-x86_64', 'r22b-darwin-x86_64', 'r23-darwin' ]
    defaults:
      run:
        shell: bash
    steps:
      - uses: actions/checkout@v2
      - name: set up adopt jdk 8
        uses: actions/setup-java@v2.2.0
        with:
          distribution: 'adopt'
          java-version: '8'
      - name: set up android ndk
        run: |
          curl -s "https://dl.google.com/android/repository/android-ndk-${{ matrix.ndk-version }}.zip" -o ndk.zip
          unzip -q -o ndk.zip -d .ndk
          echo "ANDROID_NDK_ROOT=$PWD/.ndk/$(ls .ndk)" >> $GITHUB_ENV
      - name: run the build script
        run: ./android.sh -d --enable-android-media-codec --enable-android-zlib
      - name: print build logs
        if: ${{ always() }}
        run: cat build.log
      - name: print ffbuild logs
        if: ${{ failure() }}
        run: '[[ -f ./src/ffmpeg/ffbuild/config.log ]] && tail -50 ./src/ffmpeg/ffbuild/config.log'
  build-lts-on-macos:
    name: android lts on macos
    runs-on: macos-10.15
    strategy:
      matrix:
        ndk-version: [ 'r21e-darwin-x86_64', 'r22b-darwin-x86_64', 'r23-darwin' ]
    defaults:
      run:
        shell: bash
    steps:
      - uses: actions/checkout@v2
      - name: set up adopt jdk 8
        uses: actions/setup-java@v2.2.0
        with:
          distribution: 'adopt'
          java-version: '8'
      - name: set up android ndk
        run: |
          curl -s "https://dl.google.com/android/repository/android-ndk-${{ matrix.ndk-version }}.zip" -o ndk.zip
          unzip -q -o ndk.zip -d .ndk
          echo "ANDROID_NDK_ROOT=$PWD/.ndk/$(ls .ndk)" >> $GITHUB_ENV
      - name: run the build script
        run: ./android.sh -d --lts --enable-android-media-codec --enable-android-zlib
      - name: print build logs
        if: ${{ always() }}
        run: cat build.log
      - name: print ffbuild logs
        if: ${{ failure() }}
        run: '[[ -f ./src/ffmpeg/ffbuild/config.log ]] && tail -50 ./src/ffmpeg/ffbuild/config.log'
