Skip to content

Commit 709204a

Browse files
Lessley Denningtonmjcheetham
authored andcommitted
Adding winget workflows
1 parent d5f8c52 commit 709204a

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

.github/workflows/release-winget.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: "release-winget"
2+
on:
3+
release:
4+
types: [released]
5+
6+
workflow_dispatch:
7+
inputs:
8+
tag:
9+
description: 'Tag name to release'
10+
required: true
11+
12+
permissions:
13+
id-token: write # required for Azure login via OIDC
14+
15+
env:
16+
TAG_NAME: ${{ github.event.inputs.tag }}
17+
18+
jobs:
19+
release:
20+
runs-on: windows-latest
21+
environment: release
22+
steps:
23+
- name: Log into Azure
24+
uses: azure/login@v2
25+
with:
26+
client-id: ${{ secrets.AZURE_CLIENT_ID }}
27+
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
28+
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
29+
30+
- name: Publish manifest with winget-create
31+
run: |
32+
# Enabling stop on error and tracing
33+
Set-PSDebug -Trace 2
34+
$ErrorActionPreference = "Stop"
35+
$PSNativeCommandErrorActionPreference = "Stop"
36+
37+
if ($env:TAG_NAME -eq "") {
38+
$env:TAG_NAME = $github.release.tag_name
39+
40+
# Get latest release
41+
$github = Get-Content '${{ github.event_path }}' | ConvertFrom-Json
42+
43+
# Get download URLs
44+
$asset_x64 = $github.release.assets | Where-Object -Property name -match '64-bit.exe$'
45+
$asset_arm64 = $github.release.assets | Where-Object -Property name -match 'arm64.exe$'
46+
$asset_x64_url = $asset_x64.browser_download_url
47+
$asset_arm64_url = $asset_arm64.browser_download_url
48+
} else {
49+
# Get release object by its tag
50+
$env:GH_TOKEN = ${{ toJson(secrets.GITHUB_TOKEN) }}
51+
$github = (gh release view -R microsoft/git $env:TAG_NAME --json tagName,assets --jq '{tag_name: .tagName, assets: .assets}') | ConvertFrom-Json
52+
53+
# Get download URLs
54+
$asset_x64 = $github.assets | Where-Object -Property name -match '64-bit.exe$'
55+
$asset_arm64 = $github.assets | Where-Object -Property name -match 'arm64.exe$'
56+
$asset_x64_url = $asset_x64.url
57+
$asset_arm64_url = $asset_arm64.url
58+
}
59+
60+
# Remove 'v' and 'vfs' from the version
61+
$env:TAG_NAME -match 'v(.*?)vfs\.(.*)'
62+
$version = $Matches[1] + $Matches[2]
63+
64+
# Download wingetcreate and create manifests
65+
Invoke-WebRequest https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe
66+
.\wingetcreate.exe update Microsoft.Git `
67+
-v $version `
68+
-o manifests `
69+
-u "$($asset_x64_url)|x64|machine" `
70+
"$($asset_x64_url)|x64|user" `
71+
"$($asset_arm64_url)|arm64|machine" `
72+
"$($asset_arm64_url)|arm64|user"
73+
74+
# Manually substitute the name of the default branch in the License
75+
# and Copyright URLs since the tooling cannot do that for us.
76+
$shortenedVersion = $version -replace ".{4}$"
77+
$manifestPath = dir -Path ./manifests -Filter Microsoft.Git.locale.en-US.yaml -Recurse | %{$_.FullName}
78+
sed -i "s/vfs-[.0-9]*/vfs-$shortenedVersion/g" "$manifestPath"
79+
80+
# Download the token from Azure Key Vault and mask it in the logs
81+
az keyvault secret download --name ${{ secrets.WINGET_TOKEN_SECRET_NAME }} --vault-name ${{ secrets.AZURE_VAULT }} --file token.txt
82+
Write-Host -NoNewLine "::add-mask::$(Get-Content token.txt)"
83+
84+
# Submit the manifest to the winget-pkgs repository
85+
$manifestDirectory = Split-Path "$manifestPath"
86+
.\wingetcreate.exe submit -t "$(Get-Content token.txt)" $manifestDirectory
87+
shell: powershell

0 commit comments

Comments
 (0)