name: Release Builds
on: push
env:
  GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
  build-and-store-artifact:
    name: Build
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        #os: [ windows-latest, ubuntu-latest, macos-latest ]
        os: [ macos-latest ]
    steps:
    - uses: actions/checkout@v1
    - uses: ilammy/msvc-dev-cmd@v1
    - name: Install Qt
      uses: jurplel/install-qt-action@v2
    - name: Make GNU
      if: matrix.os != 'windows-latest'
      working-directory: ./buckshot
      run: qmake ; make ; ls -al
      shell: bash
    - name: Make Windows
      if: matrix.os == 'windows-latest'
      working-directory: ./buckshot
      run: |
        dir
        qmake
        dir
        #mingw32-make
        #dir
        nmake
        dir
        dir release

    - name: Package OSX Test
      if: matrix.os == 'macos-latest'
      run: |
        ./package_mac.sh
        pip3 install dmgbuild
        dmgbuild -s dmg-settings.json "buckshot" buckshot.dmg
        
   # EVERYTHING BELOW IS ONLY WHEN VERSION TAGS PUSHED (i.e. tag like "v0.1")
    - name: Create Release
      id: create_release
      if: startsWith(github.ref, 'refs/tags/v')
      uses: actions/create-release@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        tag_name: ${{ github.ref }}
        release_name: Release ${{ github.ref }}

    - name: Upload Mac Release
      if: startsWith(github.ref, 'refs/tags/v') && matrix.os == 'macos-latest'
      uses: actions/upload-release-asset@v1.0.1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ steps.create_release.outputs.upload_url }}
        asset_path: ./buckshot.dmg
        asset_name: buckshot.dmg
        asset_content_type: application/octet-stream
