Skip to content

Publish Netbird to Winget #13

Publish Netbird to Winget

Publish Netbird to Winget #13

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@v4
- 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
}