# This will only run automatically when releases have been created, 
# and will only upload binaries to previously-created releases.
# When run manually, it will overwrite the previous reelease binary

name: Upload release artifacts

on: 
  release:
    types:
      - created
  workflow_dispatch:

jobs:
  build-standalone:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [windows-latest]
        py: [3.9]
        arch: [x86, x64]
    steps:
      - uses: actions/checkout@v1
        with:
          fetch-depth: 20
      - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
      - name: Set up Python
        uses: actions/setup-python@v1
        with:
          python-version: ${{ matrix.py }}
          architecture: ${{ matrix.arch }}

      - name: Build standalone binary
        run: |
          ci/build_standalone.bat
          cp .gravitybee\dist\latest\aqt.exe .gravitybee\dist\latest\aqt_${{ matrix.arch }}.exe

      - name: Upload to Release
        uses: svenstaro/upload-release-action@v2
        with: 
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          file: .gravitybee\dist\latest\aqt.exe
          tag: ${{ github.ref }}
          overwrite: true
        if: matrix.arch=='x64'

      - name: Upload to Release for all architectures
        uses: svenstaro/upload-release-action@v2
        with: 
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          file: .gravitybee\dist\latest\aqt_${{ matrix.arch }}.exe
          tag: ${{ github.ref }}
          overwrite: true
          
      - name: Update continuous build
        uses: svenstaro/upload-release-action@v2
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          overwrite: true
          prerelease: true
          tag: Continuous
          file: .gravitybee\dist\latest\aqt.exe
        if: matrix.arch=='x64'
          
      - name: Update continuous build for all architectures
        uses: svenstaro/upload-release-action@v2
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          overwrite: true
          prerelease: true
          tag: Continuous
          file: .gravitybee\dist\latest\aqt_${{ matrix.arch }}.exe
