name: Build

on: 
  push:
  workflow_dispatch: {}


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

      - name: Install build tools
        run: |
          # echo "deb [signed-by=/usr/share/keyrings/ubuntu-archive-keyring.gpg] http://archive.ubuntu.com/ubuntu noble main" | sudo tee /tmp/only.list
          # sudo apt-get update -o Dir::Etc::sourcelist=/tmp/only.list -o Dir::Etc::sourceparts="-" -qq
          sudo apt update
          sudo apt install -y build-essential cmake zip unzip make libxrandr-dev g++-mingw-w64-x86-64 gcc-mingw-w64-x86-64 libxinerama-dev libxcursor-dev libxi-dev libgl-dev

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

      - name: Fetch libraries
        run: |
          cd ${{ gitea.workspace }}/src/libraries
          rm enet -r
          rm Lua -r
          rm raylib -r
          rm yaml-cpp -r

          wget https://github.com/zpl-c/enet/archive/refs/heads/master.zip
          unzip master.zip
          mv enet-master enet
          rm master.zip

          wget https://github.com/walterschell/Lua/archive/refs/heads/master.zip
          unzip master.zip
          mv Lua-master Lua
          rm master.zip

          wget https://github.com/raysan5/raylib/archive/refs/heads/master.zip
          unzip master.zip
          mv raylib-master raylib
          rm master.zip

          wget https://github.com/jbeder/yaml-cpp/archive/refs/heads/master.zip
          unzip master.zip
          mv yaml-cpp-master yaml-cpp
          rm master.zip

          ls -r
          
          cd ../..


      - name: Compile
        run: |
          chmod +x ${{ gitea.workspace }}/compile.sh
          sh ${{ gitea.workspace }}/compile.sh

      - name: Upload Linux Release
        uses: actions/upload-artifact@v3
        with:
          name: OUTPUT-Linux
          path: release-linux.zip

      - name: Upload Windows64 Release
        uses: actions/upload-artifact@v3
        with:
          name: OUTPUT-w64
          path: release-w64.zip

      - name: Upload Windows32 Release
        uses: actions/upload-artifact@v3
        with:
          name: OUTPUT-w32
          path: release-w32.zip
