-
Notifications
You must be signed in to change notification settings - Fork 0
123 lines (106 loc) · 4.96 KB
/
publish-winget.yml
File metadata and controls
123 lines (106 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
name: Publish Netbird to Winget
on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: 'Netbird version to publish (e.g., 0.59.8)'
required: true
type: string
jobs:
publish-winget:
runs-on: windows-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up WingetCreate
shell: pwsh
run: |
Invoke-WebRequest https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe
- name: Determine version
id: version
shell: pwsh
run: |
if ("${{ github.event_name }}" -eq "workflow_dispatch") {
$version = "${{ github.event.inputs.version }}"
} else {
$version = "${{ github.event.release.tag_name }}".TrimStart('v')
}
"VERSION=$version" >> $env:GITHUB_ENV
"version=$version" >> $env:GITHUB_OUTPUT
- name: Fetch release info & collect installer URLs
id: release_info
shell: pwsh
env:
GH_API: https://api.github.com
WINGET_PAT: ${{ secrets.WINGET_PAT }}
run: |
$ErrorActionPreference = 'Stop'
$headers = @{
Authorization = "Bearer $env:WINGET_PAT"
"User-Agent" = "netbird-winget-action"
Accept = "application/vnd.github+json"
"X-GitHub-Api-Version" = "2022-11-28"
}
if ("${{ github.event_name }}" -eq "workflow_dispatch") {
$release = Invoke-RestMethod -Headers $headers -Uri "$env:GH_API/repos/netbirdio/netbird/releases/tags/v${{ env.VERSION }}"
} else {
$release = Invoke-RestMethod -Headers $headers -Uri "${{ github.event.release.url }}"
}
# IMPORTANT: set $assets
$assets = $release.assets
if (-not $assets) {
throw "Release v${{ env.VERSION }} has no assets (is the tag correct and the build finished?)."
}
# Collect MSI & EXE installers for x64 and arm64
$msi_x64 = $assets | Where-Object { $_.name -like "*windows_amd64.msi" } | Select-Object -ExpandProperty browser_download_url -First 1
$exe_x64 = $assets | Where-Object { $_.name -like "*windows_amd64.exe" } | Select-Object -ExpandProperty browser_download_url -First 1
$msi_arm = $assets | Where-Object { $_.name -like "*windows_arm64.msi" } | Select-Object -ExpandProperty browser_download_url -First 1
$exe_arm = $assets | Where-Object { $_.name -like "*windows_arm64.exe" } | Select-Object -ExpandProperty browser_download_url -First 1
# At least one installer must exist
$any = @($msi_x64, $exe_x64, $msi_arm, $exe_arm) | Where-Object { $_ }
if (-not $any -or $any.Count -eq 0) {
throw "No Windows installers (MSI/EXE) found in v${{ env.VERSION }}."
}
# Qualify with architecture to help WingetCreate match correctly
# (WingetCreate also matches by installer type automatically)
$qualified = @()
if ($msi_x64) { $qualified += "$msi_x64|x64" }
if ($exe_x64) { $qualified += "$exe_x64|x64" }
if ($msi_arm) { $qualified += "$msi_arm|arm64" }
if ($exe_arm) { $qualified += "$exe_arm|arm64" }
# Persist for next step; also expose a primary for logs
Set-Content -Path installer_urls.txt -Value ($qualified -join "`n")
"installer_urls_file=installer_urls.txt" >> $env:GITHUB_OUTPUT
"installer_url=$($any[0])" >> $env:GITHUB_OUTPUT
# (Optional) release notes, normalized to LF
$notes = ($release.body ?? "") -replace "`r",""
$delimNotes = "EOF_$([Guid]::NewGuid().ToString('N'))"
Add-Content $env:GITHUB_OUTPUT "release_notes<<$delimNotes"
Add-Content $env:GITHUB_OUTPUT $notes
Add-Content $env:GITHUB_OUTPUT $delimNotes
- name: Update Winget Manifest
shell: pwsh
env:
WINGET_PAT: ${{ secrets.WINGET_PAT }}
run: |
Write-Host "Updating Winget manifest for Netbird ${{ env.VERSION }}"
Write-Host "Example installer: ${{ steps.release_info.outputs.installer_url }}"
$urls = Get-Content "${{ steps.release_info.outputs.installer_urls_file }}" | Where-Object { $_.Trim() }
if (-not $urls) { throw "No installer URLs to submit." }
# Pass ALL MSI+EXE installers to match the existing multi-installer manifest
.\wingetcreate.exe update Netbird.Netbird `
--version $env:VERSION `
--urls $urls `
--submit `
--token $env:WINGET_PAT
- name: Verify submission
shell: pwsh
run: |
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ Successfully submitted Winget manifest update for Netbird ${{ env.VERSION }}"
} else {
Write-Error "❌ Failed to submit Winget manifest update"
exit 1
}