name: Build eismuliplexer-qt for windows
run-name: Building eismuliplexer-qt for windows
on: [push]

jobs:
  BuildWin:
    runs-on: arch-mingw-qt
    steps:
      - name: Install dependancies
        run: pacman -Sy; pacman -S --noconfirm mingw-w64-libusb mingw-w64-pkg-config nodejs zip
      - name: Check out repository code
        uses: ischanx/checkout@8c80eac3058d03dc5301629e8f7d59ae255d6cc3
      - name: Checkout libeismultiplexer
        run: git clone http://192.168.178.27/git/Eismultiplexer/libeismultiplexer.git
      - name: libeismultiplexer version
        id: libeisversion
        run: |
            cd ${{ gitea.workspace }}/libeismultiplexer
            git fetch -a;
            echo "tag=$(git describe --tags `git rev-list --tags --max-count=1`)" >> $GITHUB_OUTPUT
      - name: Version
        id: version
        run: |
            cd ${{ gitea.workspace }}
            git fetch -a;
            echo "tag=$(git describe --tags `git rev-list --tags --max-count=1`)" >> $GITHUB_OUTPUT
      - name: Build libeismultiplexer
        run: |
            mkdir ${{ gitea.workspace }}/libeismultiplexer/build
            cd ${{ gitea.workspace }}/libeismultiplexer/build
            cmake -DCMAKE_INSTALL_PREFIX=/usr/x86_64-w64-mingw32/ -DCMAKE_TOOLCHAIN_FILE=../crossW64.cmake -DCMAKE_BUILD_TYPE=Release -DGIT_TAG=${{ steps.libeisversion.outputs.tag }} ..
            make
            make install
      - name: Build
        run: |
            mkdir ${{ gitea.workspace }}/build
            cd ${{ gitea.workspace }}/build
            cmake -DCMAKE_TOOLCHAIN_FILE=../crossW64.cmake -DCMAKE_BUILD_TYPE=Release -DGIT_TAG=${{ steps.version.outputs.tag }} ..
            make -j $(nproc)
            make package
      - name: Upload Package
        uses: actions/upload-artifact@v3
        with:
            name: eismuliplexer-qt-${{ steps.version.outputs.tag }}-w64
            path: ${{ gitea.workspace }}/build/packaged/${{ steps.version.outputs.tag }}/release/*
