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

jobs:
  build-ubuntu:
    runs-on: ubuntu-18.04
    steps:
      -
        name: Checkout
        uses: actions/checkout@v2
        with:
          path: hydrus
      - 
        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: APT Install
        run: |
          sudo apt-get update
          sudo apt-get install -y libmpv1
      - 
        name: Pip Installer
        uses: BSFishy/pip-action@v1
        with:
          packages: pyinstaller
          requirements: hydrus/static/build_files/linux/requirements.txt
      - 
        name: Build Hydrus
        run: |
          cp hydrus/static/build_files/linux/client.spec client.spec
          cp hydrus/static/build_files/linux/server.spec server.spec
          pyinstaller server.spec
          pyinstaller client.spec
      - 
        name: Remove Chonk
        run: |
            find dist/client/ -type f -name "*.pyc" -delete
            while read line; do find dist/client/ -type f -name "${line}" -delete ; done < hydrus/static/build_files/linux/files_to_delete.txt
      -
        name: Set Permissions
        run: |
            sudo chown --recursive 1000:1000 dist/client
            sudo find dist/client -type d -exec chmod 0755 {} \;
            sudo chmod +x dist/client/client dist/client/server dist/client/bin/swfrender_linux
      -
        name: Compress Client
        run: |
            mv dist/client "dist/Hydrus Network"
            tar -czvf Ubuntu-Extract.tar.gz -C dist "Hydrus Network"
      - 
        name: Upload a Build Artifact
        uses: actions/upload-artifact@v2
        with:
          name: Ubuntu-Extract
          path: Ubuntu-Extract.tar.gz
          if-no-files-found: error
          retention-days: 2