name: Release
on:
  push:
    tags:
      - 'v*'

jobs:
  build-windows:
    runs-on: [windows-latest]
    steps:
      - 
        name: Checkout
        uses: actions/checkout@v2
        with:
          path: hydrus
      - 
        name: Setup FFMPEG
        uses: FedericoCarboni/setup-ffmpeg@v1
        id: setup_ffmpeg
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
      - 
        name: Setup Python
        uses: actions/setup-python@v2
        with:
          python-version: 3.8
          architecture: x64
      - 
        name: Cache Qt
        id: cache_qt
        uses: actions/cache@v1
        with:
          path: ../Qt
          key: ${{ runner.os }}-QtCache
      - 
        name: Install Qt
        uses: jurplel/install-qt-action@v2
        with:
          install-deps: true
          setup-python: 'false'
          modules: qtcharts qtwidgets qtgui qtcore
          cached: ${{ steps.cache_qt.outputs.cache-hit }}
      - 
        name: PIP Install Packages
        uses: BSFishy/pip-action@v1
        with:
          packages: pyinstaller
          requirements: hydrus\static\build_files\windows\requirements.txt
      - 
        name: Download mpv-dev
        uses: carlosperate/download-file-action@v1.0.3
        id: download_mpv
        with:
            file-url: 'https://sourceforge.net/projects/mpv-player-windows/files/libmpv/mpv-dev-x86_64-20210228-git-d1be8bb.7z'
            file-name: 'mpv-dev-x86_64.7z'
            location: '.'
      - 
        name: Process mpv-dev
        run: |
          7z x ${{ steps.download_mpv.outputs.file-path }}
          move mpv-1.dll hydrus\
      - 
        name: Build Hydrus
        run: |
          move ${{ steps.setup_ffmpeg.outputs.ffmpeg-path }} hydrus\bin\
          move hydrus\static\build_files\windows\sqlite3.dll hydrus\
          move hydrus\static\build_files\windows\client-win.spec client-win.spec
          move hydrus\static\build_files\windows\server-win.spec server-win.spec
          pyinstaller server-win.spec
          pyinstaller client-win.spec
          dir -r
      - 
        name: InnoSetup
        run: |
          move hydrus\static\build_files\windows\InnoSetup.iss InnoSetup.iss
          ISCC.exe InnoSetup.iss /DVersion=${GITHUB_REF##*/v}
      -
        name: Compress Client
        run: |
          cd .\dist
          7z.exe a -tzip -mm=Deflate -mx=5 ..\Windows-Extract.zip 'Hydrus Network'
          cd ..
      - 
        name: Upload a Build Artifact
        uses: actions/upload-artifact@v2
        with:
          name: Windows-Install
          path: dist\HydrusInstaller.exe
          if-no-files-found: error
          retention-days: 2
      - 
        name: Upload a Build Artifact
        uses: actions/upload-artifact@v2
        with:
          name: Windows-Extract
          path: Windows-Extract.zip
          if-no-files-found: error
          retention-days: 2