name: CI

on:
  push:
    branches:
      - master
    paths-ignore:
      - 'README.md'
  pull_request:
    branches:
      - master
    paths-ignore:
      - 'README.md'

jobs:
  build:
    runs-on: windows-latest

    env:
      FFMPEG_DIR: ffmpeg-n5.1-latest-win64-gpl-shared-5.1

    steps:
    - name: Checkout
      uses: actions/checkout@v2
      with:
        fetch-depth: 0

    - name: Install Developer Command Prompt for Microsoft Visual C++
      uses: ilammy/msvc-dev-cmd@v1

    - name: Install Qt
      uses: jurplel/install-qt-action@v3
      with:
        version: '6.6'
        modules: 'qtmultimedia'

    - name: Install FFmpeg
      shell: bash
      run: |
        curl -fLOSs https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/$FFMPEG_DIR.zip
        7z x $FFMPEG_DIR.zip

    - name: Build
      shell: bash
      run: |
        cmake . -G Ninja -DCMAKE_BUILD_TYPE=Release -DFFMPEG_ROOT=$FFMPEG_DIR
        ninja

    - name: Deploy
      shell: bash
      run: |
        mkdir deploy
        cp app/*.exe deploy
        cp lib/*.dll deploy
        cp $FFMPEG_DIR/bin/*.dll deploy
        cd deploy
        windeployqt si-edit.exe libweaver.dll

    - name: Upload Build Artifact
      uses: actions/upload-artifact@v4
      with:
        path:
          deploy

    - name: Upload to Releases
      shell: bash
      if: github.event_name == 'push'
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        TRAVIS_REPO_SLUG: isledecomp/siedit
        TRAVIS_COMMIT: ${{ github.sha }}
      run: |
        cd deploy
        7z a si-edit.zip *
        curl -fLOSs --retry 2 --retry-delay 60 https://github.com/probonopd/uploadtool/raw/master/upload.sh
        ./upload.sh si-edit.zip