name: Nightly Releases

on:
  schedule:
    - cron:  '1 1 * * *'

jobs:
  check:
    runs-on: ubuntu-latest
    
    outputs:
      status: ${{ steps.check.outputs.status }}
      version: ${{ steps.check.outputs.version }}
    
    steps:
    - uses: actions/checkout@v2
      name: checkout
      with:
        fetch-depth: 0
    
    - name: nightly-check
      id: check
      shell: bash {0}
      run: |
        ver=$(./.github/workflows/nightly_check.sh)
        echo "::set-output name=status::$?"
        echo "::set-output name=version::${ver}"

    - name: create-release
      id: create
      if: steps.check.outputs.status == 0
      uses: justdan96/release-action@main
      with:
        tag: nightly-${{ steps.check.outputs.version }}
        name: Nightly build from ${{ steps.check.outputs.version }}
        prerelease: true
        commit: ${{ env.GITHUB_SHA }}
        token: ${{ secrets.GITHUB_TOKEN }}
    
    - name: obs-trigger
      id: obs
      if: steps.check.outputs.status == 0
      run: ./.github/workflows/obs_trigger.sh
      env:
        OBS_USER: justdan96
        OBS_SECRET: ${{ secrets.OBS_SECRET }}
  
  build-docker:
  
    needs: check

    if: needs.check.outputs.status == 0
  
    runs-on: ubuntu-latest
    
    container:
      image: docker://justdan96/tsmuxer_build:latest
      volumes:
      - /workspace:/github/workspace
    
    steps:
    - uses: actions/checkout@v2
      name: checkout
      
    - run: rm -f bin/.gitkeep
      name: clean-bin-folder
      
    - run: ./scripts/rebuild_linux_with_gui_docker.sh
      name: build-for-linux
      
    - run: ./scripts/rebuild_mxe_with_gui_docker.sh
      name: build-for-win64
      
    - run: ./scripts/rebuild_mxe32_with_gui_docker.sh
      name: build-for-win32

    - name: Upload Win32/Win64/Linux Builds
      id: upload-builds
      uses: justdan96/release-action@main
      with:
        token: ${{ secrets.GITHUB_TOKEN }}
        artifacts: ./bin/*.zip
        tag: nightly-${{ needs.check.outputs.version }}
        allowUpdates: true
        omitPrereleaseDuringUpdate: true
        omitNameDuringUpdate: true
        omitBodyDuringUpdate: true 

  build-macos:
  
    needs: check
    if: needs.check.outputs.status == 0
    
    runs-on: macos-latest
    
    steps:
    - uses: actions/checkout@v2
      name: checkout
    
    - name: Install Qt
      uses: jurplel/install-qt-action@v2
      with:
        setup-python: false
        py7zrversion: '==0.20.*'
      
    - run: ./scripts/build_macos_native.sh
      name: build-for-mac
    
    - name: Upload Mac Build
      id: upload-mac
      uses: justdan96/release-action@main
      with:
        token: ${{ secrets.GITHUB_TOKEN }}
        artifacts: ./build/bin/mac.zip
        tag: nightly-${{ needs.check.outputs.version }}
        allowUpdates: true
        omitPrereleaseDuringUpdate: true
        omitNameDuringUpdate: true
        omitBodyDuringUpdate: true        
