Repository: microsoft/terminal (language: cpp)

Issue:
Automatically submit winget packages when we release a new version
We don't currently. We should.

PowerToys has this handy script for automating their release to winget. We could probably copypasta with minimal changes.

https://github.com/microsoft/PowerToys/blob/main/.github/workflows/package-submissions.yml




Discussion / hints:
FWIW I haven't done this yet because we do post-release-build vetting and release on a schedule, rather than "every time the release pipeline builds."

That is: We build the final releases on Thursdays or Fridays (as if 🤣) and then publish them the following Tuesday.

WinGet requires a durable public asset URL, which for us would be GitHub.

We may prefer to automate this off the tail end of a GitHub Action that fires when a release is published...
You know, that's right, the script above might actually just work based off a GH action on publishing the _release_. It's been so long since I opened that tab, I had forgotten. I'll clarify. 

Fix patch:
diff --git a/.github/workflows/winget.yml b/.github/workflows/winget.yml
new file mode 100644
index 00000000000..9bf6910cafc
--- /dev/null
+++ b/.github/workflows/winget.yml
@@ -0,0 +1,27 @@
+name: Publish to Winget
+
+on:
+  release:
+    types: [published]
+
+env:
+  REGEX: 'Microsoft\.WindowsTerminal(?:Preview)?_Win10_([\d.]+)_8wekyb3d8bbwe\.msixbundle$'
+
+jobs:
+  publish:
+    runs-on: windows-latest # Action can only run on Windows
+    steps:
+      - name: Extract version from release asset
+        id: extract-version
+        run: |
+          $version = '${{ toJSON(github.event.release.assets.*.name) }}' | ConvertFrom-Json | Select-String -Pattern $env:REGEX | ForEach-Object { $_.Matches.Groups[1].Value }
+          Write-Output "version=$version" >> $env:GITHUB_OUTPUT
+
+      - name: Publish ${{ github.event.release.prerelease && 'Preview' || 'Stable' }}
+        uses: vedantmgoyal2009/winget-releaser@v2
+        with:
+          identifier: Microsoft.WindowsTerminal${{ github.event.release.prerelease && '.Preview' || '' }}
+          version: ${{ steps.extract-version.outputs.version }}
+          installers-regex: ${{ env.REGEX }}
+          token: ${{ secrets.WINGET_TOKEN }}
+          fork-user: DHowett


Test patch: