From 4e1e2007ae3d526bbbe64ec7979b27bd543dec96 Mon Sep 17 00:00:00 2001
From: Merrick Zhang <anphorea@gmail.com>
Date: Thu, 7 Nov 2024 16:23:38 +0800
Subject: [PATCH] Create winget-publish.yml

Publish to winget after release
---
 .github/workflows/winget-publish.yml | 31 ++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 .github/workflows/winget-publish.yml

diff --git a/.github/workflows/winget-publish.yml b/.github/workflows/winget-publish.yml
new file mode 100644
index 00000000..0e5d6a2e
--- /dev/null
+++ b/.github/workflows/winget-publish.yml
@@ -0,0 +1,31 @@
+name: WinGet submission on release
+# based off of https://github.com/nushell/nushell/blob/main/.github/workflows/winget-submission.yml
+# inspired by https://github.com/microsoft/PowerToys/blob/main/.github/workflows/package-submissions.yml
+# Modified by @MerrickZ https://github.com/anpho
+
+on:
+  workflow_dispatch:
+  release:
+    types: [published]
+
+jobs:
+  winget:
+    name: Publish winget package
+    runs-on: windows-latest
+    steps:
+      - name: Submit v2ray package to Windows Package Manager Community Repository
+        run: |
+
+          $wingetPackage = "2dust.v2rayN"
+          $gitToken = "${{ secrets.PT_WINGET }}"
+
+          $github = Invoke-RestMethod -uri "https://api.github.com/repos/2dust/v2rayN/releases" 
+
+          $targetRelease = $github | Where-Object -Property prerelease -match 'False' | Select -First 1
+          $installerUrl  = $targetRelease | Select -ExpandProperty assets -First 1 | Where-Object -Property name -match 'v2rayN-With-Core\.zip*' | Select -ExpandProperty browser_download_url
+
+          $ver = $targetRelease.tag_name
+
+          # getting latest wingetcreate file
+          iwr https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe
+          .\wingetcreate.exe update $wingetPackage -s -v $ver -u "$installerUrl|x64" -t $gitToken