name: ci-android

on:
  push:
    paths:
      - "**"
      - "!docs/**"
      - "docs/Makefile.am"
      - "!ios/**"
      - "!macosx/**"
      - "!msvcstuff/**"
      - "!win32/**"
      - "!AUTHORS"
      - "!ChangeLog"
      - "!COPYING"
      - "!FAQ"
      - "!INSTALL"
      - "!NEWS"
      - "!**README**"
      - "!**.ico"
      - "!**.md"
      - "!**.png"
      - "!**.txt"
      - "!.clang*"
      - "!.gitignore"
      - "!.gitattributes"
      - "!.github/workflows/*"
      - ".github/workflows/ci-android.yml"
  pull_request:
    paths:
      - "**"
      - "!docs/**"
      - "docs/Makefile.am"
      - "!ios/**"
      - "!macosx/**"
      - "!msvcstuff/**"
      - "!win32/**"
      - "!AUTHORS"
      - "!ChangeLog"
      - "!COPYING"
      - "!FAQ"
      - "!INSTALL"
      - "!NEWS"
      - "!**README**"
      - "!**.ico"
      - "!**.md"
      - "!**.png"
      - "!**.txt"
      - "!.clang*"
      - "!.gitignore"
      - "!.gitattributes"
      - "!.github/workflows/*"
      - ".github/workflows/ci-android.yml"

jobs:
  notify:
    name: Exult-CI (IRC & Discord notification)
    runs-on: ubuntu-latest
    continue-on-error: true
    needs:
      - ci-android
    if: ${{ always() && (github.repository_owner == 'exult' && github.event_name != 'pull_request') }}
    steps:
      - name: IRC success notification (ircs://irc.libera.chat:6697/#exult)
        uses: Gottox/irc-message-action@v2
        continue-on-error: true
        if: needs.ci-android.result == 'success'
        with:
          server: irc.libera.chat
          port: 6697
          channel: "#exult"
          nickname: github-actions
          tls: true
          message: "\x0313exult\x03/\x0306${{ github.ref }}\x03 \x0314${{ github.sha }}\x03 https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} The Android build \x033succeeded\x03."
      - name: IRC failure notification (ircs://irc.libera.chat:6697/#exult)
        uses: Gottox/irc-message-action@v2
        continue-on-error: true
        if: needs.ci-android.result != 'success'
        with:
          server: irc.libera.chat
          port: 6697
          channel: "#exult"
          nickname: github-actions
          tls: true
          message: "\x0313exult\x03/\x0306${{ github.ref }}\x03 \x0314${{ github.sha }}\x03 https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }} The Android build \x034failed\x03."
      - name: Discord success notification
        uses: rjstone/discord-webhook-notify@master
        continue-on-error: true
        if: needs.ci-android.result == 'success'
        with:
          severity: info
          webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
          username: Exult github-actions
          avatarUrl: https://avatars.githubusercontent.com/u/15114538?s=200&v=4
          text: '**[The Android build succeeded:](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})**'
      - name: Discord failure notification
        uses: rjstone/discord-webhook-notify@master
        continue-on-error: true
        if: needs.ci-android.result != 'success'
        with:
          severity: error
          webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
          username: Exult github-actions
          avatarUrl: https://avatars.githubusercontent.com/u/15114538?s=200&v=4
          text: '**[The Android build failed:](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})**'
  ci-android:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/setup-java@v4
        with:
          java-version: 17
          distribution: "temurin"
      - name: Setup Android SDK
        uses: android-actions/setup-android@v3
      - name: Setup Gradle
        uses: gradle/actions/setup-gradle@v3
        with:
          gradle-version: 8.7
      - name: Install dependencies
        run: |
          if ! apt-fast -- help &> /dev/null; then
            sudo add-apt-repository -u -y ppa:apt-fast/stable
            sudo apt-get update
            echo debconf apt-fast/maxdownloads string 16 | sudo debconf-set-selections
            echo debconf apt-fast/dlflag boolean true | sudo debconf-set-selections
            echo debconf apt-fast/aptmanager string apt-get | sudo debconf-set-selections
            DEBIAN_FRONTEND=noninteractive sudo apt install -y apt-fast
          else
            sudo apt-fast update
          fi
          sudo apt-fast install -y autoconf-archive
      - name: Checkout code
        uses: actions/checkout@v4
      - name: Run autoreconf
        run: |
          mkdir ./../build
          autoreconf -v -i
      - name: Configure
        run: |
          cd ./../build
          ./../exult/configure --enable-data --enable-android-apk=debug \
            --disable-exult --disable-tools --disable-timidity-midi --disable-alsa \
            --disable-fluidsynth --disable-mt32emu --disable-all-hq-scalers \
            --disable-nxbr --disable-zip-support --disable-sdl-parachute
      - name: Build
        run: |
          cd ./../build/files && make -j2
          cd ./../data && make -j2
          cd ./../android && make -j2
