name: Bump Dolt on winget

on:
  workflow_dispatch:
    inputs:
      version:
        description: 'SemVer format release tag, i.e. 0.24.5'
        required: true
  repository_dispatch:
    types: [ bump-winget ]

jobs:
  get-version:
    name: Get Version
    runs-on: ubuntu-18.04
    outputs:
      version: ${{ steps.get_version.outputs.version }}
    steps:
      - name: Get version
        id: get_version
        run: |
          version=""

          if [ "${{ github.event_name }}" == "repository_dispatch" ]
          then
            version="${{ github.event.client_payload.version }}"
          else
            version="${{ github.event.inputs.version }}"
          fi

          echo "::set-output name=version::$version"

  winget-bump:
    needs: get-version
    name: Bump Dolt winget
    runs-on: windows-2019
    defaults:
      run:
        shell: powershell
    steps:
      - name: Create winget PR
        run: |
          iwr https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe
          .\wingetcreate.exe update DoltHub.Dolt -u $Env:URL -v $Env:VERSION -t $Env:TOKEN --submit
        env:
          TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
          VERSION: ${{ needs.get-version.outputs.version }}
          URL: ${{ format('https://github.com/dolthub/dolt/releases/download/v{0}/dolt-windows-amd64.msi', needs.get-version.outputs.version) }}
