name: Submit to Windows Package Manager Community Repository

on:
  release:
    types: [ released ]
  workflow_dispatch:
    inputs:
      tag_name:
        description: "Specific tag name"
        required: true
        type: string

jobs:
  winget:
    name: Publish winget package
    runs-on: ubuntu-latest
    steps:
      - name: Set winget version env
        env:
          TAG_NAME: ${{ inputs.tag_name || github.event.release.tag_name }}
        run: echo "WINGET_TAG_NAME=$(echo ${TAG_NAME#v})" >> $GITHUB_ENV
      - name: Submit package to Windows Package Manager Community Repository
        uses: vedantmgoyal2009/winget-releaser@main
        with:
          identifier: th-ch.YouTubeMusic
          installers-regex: '^YouTube-Music-Web-Setup-[\d\.]+\.exe$'
          version: ${{ env.WINGET_TAG_NAME }}
          release-tag: ${{ inputs.tag_name || github.event.release.tag_name }}
          token: ${{ secrets.WINGET_ACC_TOKEN }}
          fork-user: youtube-music-winget
