name: ci-linux

on:
  push:
    paths:
      - "**"
      - "!android/**"
      - "!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-linux.yml"
  pull_request:
    paths:
      - "**"
      - "!android/**"
      - "!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-linux.yml"

jobs:
  notify:
    name: Exult-CI (IRC & Discord notification)
    runs-on: ubuntu-latest
    continue-on-error: true
    needs:
      - ci-linux
    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-linux.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 Linux 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-linux.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 Linux build \x034failed\x03."
      - name: Discord success notification
        uses: rjstone/discord-webhook-notify@master
        continue-on-error: true
        if: needs.ci-linux.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 Linux 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-linux.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 Linux build failed:](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})**'
  ci-linux:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        compiler: [gcc, clang]
        include:
          - compiler: gcc
            cc: gcc
            cxx: g++
          - compiler: clang
            cc: clang
            cxx: clang++
    steps:
      - 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 \
            zlib1g-dev libogg-dev libvorbis-dev libasound2-dev libfluidsynth-dev libsdl2-dev libpng-dev libfreetype6-dev libgtk2.0-dev libgtk-3-dev \
            libgdk-pixbuf2.0-dev libxml2-dev bison flex timidity libgimp2.0-dev libicu-dev autoconf-archive
      - name: Checkout code
        uses: actions/checkout@v4
      - name: Run autoreconf
        run: |
          autoreconf -v -i
      - name: Configure
        env:
          OVERRIDE_CC: ${{ matrix.cc }}
          OVERRIDE_CXX: ${{ matrix.cxx }}
        run: |
          ./configure --with-debug=extreme --enable-exult-studio --enable-exult-studio-support --enable-compiler --enable-gimp-plugin \
            --enable-zip-support --enable-shared --enable-midi-sfx --enable-gnome-shp-thumbnailer --enable-data --enable-mods \
            --with-usecode-debugger=yes --enable-usecode-container --enable-nonreadied-objects --disable-oggtest --disable-vorbistest \
            CXX=${OVERRIDE_CXX} CC=${OVERRIDE_CC}
      - name: Build
        run: make -j 2
