name: Build

on:
  push:
  workflow_dispatch: {}

jobs:
  build:
    runs-on: ubuntu-latest-lite
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Prepare minimal system and install prerequisites
        run: |
          set -e
          sudo apt-get update -y
          sudo apt-get install -y --no-install-recommends \
            ca-certificates gnupg wget curl unzip zip software-properties-common \
            build-essential cmake make libxrandr-dev mingw-w64
          sudo apt-get install -y --no-install-recommends apt-transport-https

      - name: Add Ubuntu archive (if needed) and update
        run: |
          set -e
          echo "deb [signed-by=/usr/share/keyrings/ubuntu-archive-keyring.gpg] http://archive.ubuntu.com/ubuntu noble main" | sudo tee /etc/apt/sources.list.d/noble.list
          sudo apt-get update -o Dir::Etc::sourcelist=/etc/apt/sources.list.d/noble.list -o Dir::Etc::sourceparts="-" -qq || true

      - name: Install mingw-w64 from .deb packages
        run: |
          set -e
          wget -q http://ftp.ru.debian.org/debian/pool/main/g/gcc-mingw-w64/g++-mingw-w64-x86-64_14.2.0-17+27_all.deb -O /tmp/gpp-mingw.deb
          wget -q http://ftp.ru.debian.org/debian/pool/main/g/gcc-mingw-w64/gcc-mingw-w64-x86-64_14.2.0-17+27_all.deb -O /tmp/gcc-mingw.deb
          sudo dpkg -i /tmp/gpp-mingw.deb /tmp/gcc-mingw.deb || sudo apt-get -f install -y --no-install-recommends
          rm -f /tmp/gpp-mingw.deb /tmp/gcc-mingw.deb

      - name: Build makeheaders
        run: |
          set -e
          cd makeheaders
          make
          cd ..

      - name: Fetch libraries
        run: |
          set -e
          cd ${{ gitea.workspace }}/src/libraries

          curl -L -o enet.zip https://github.com/lsalzman/enet/archive/refs/heads/master.zip
          unzip -q enet.zip
          mv enet-master enet
          rm enet.zip

          curl -L -o Lua.zip https://github.com/walterschell/Lua/archive/refs/heads/master.zip
          unzip -q Lua.zip
          mv Lua-master Lua
          rm Lua.zip

          curl -L -o raylib.zip https://github.com/raysan5/raylib/archive/refs/heads/master.zip
          unzip -q raylib.zip
          mv raylib-master raylib
          rm raylib.zip

          curl -L -o yaml-cpp.zip https://github.com/jbeder/yaml-cpp/archive/refs/heads/master.zip
          unzip -q yaml-cpp.zip
          mv yaml-cpp-master yaml-cpp
          rm yaml-cpp.zip

          ls -la
          cd ../..

      - name: Compile
        run: |
          set -e
          chmod +x ${{ gitea.workspace }}/compile.sh
          sh ${{ gitea.workspace }}/compile.sh
          zip -r release-linux.zip OUTPUT-Linux || true
          zip -r release-w64.zip OUTPUT-w64 || true

      - name: Upload artifacts
        uses: actions/upload-artifact@v7
        with:
          name: build-artifacts
          path: |
            release-linux.zip
            release-w64.zip
```