From 2979a2cf3471464fa3159320d31bb6a129c563ea Mon Sep 17 00:00:00 2001 From: "G.Reijn" Date: Sat, 28 Dec 2024 14:55:53 +0100 Subject: [PATCH 1/7] Create function to submit WinGet manifest --- .vscode/settings.json | 3 +- build.ps1 | 112 +++++++++++++++++++++++++----------------- 2 files changed, 69 insertions(+), 46 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 24bf5814d..9a3c6627d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -26,5 +26,6 @@ "vscode-nmake-tools.workspaceBuildDirectories": [ "." ], - "azure-pipelines.1ESPipelineTemplatesSchemaFile": true + "azure-pipelines.1ESPipelineTemplatesSchemaFile": true, + "powershell.codeFormatting.preset": "OTBS" } \ No newline at end of file diff --git a/build.ps1 b/build.ps1 index aed317c30..da719184f 100644 --- a/build.ps1 +++ b/build.ps1 @@ -3,11 +3,11 @@ param( [switch]$Release, - [ValidateSet('current','aarch64-pc-windows-msvc','x86_64-pc-windows-msvc','aarch64-apple-darwin','x86_64-apple-darwin','aarch64-unknown-linux-gnu','aarch64-unknown-linux-musl','x86_64-unknown-linux-gnu','x86_64-unknown-linux-musl')] + [ValidateSet('current', 'aarch64-pc-windows-msvc', 'x86_64-pc-windows-msvc', 'aarch64-apple-darwin', 'x86_64-apple-darwin', 'aarch64-unknown-linux-gnu', 'aarch64-unknown-linux-musl', 'x86_64-unknown-linux-gnu', 'x86_64-unknown-linux-musl')] $architecture = 'current', [switch]$Clippy, [switch]$SkipBuild, - [ValidateSet('msix','msix-private','msixbundle','tgz','zip')] + [ValidateSet('msix', 'msix-private', 'msixbundle', 'tgz', 'zip')] $packageType, [switch]$Test, [switch]$GetPackageVersion, @@ -16,7 +16,9 @@ param( [switch]$UseCratesIO, [switch]$UpdateLockFile, [switch]$Audit, - [switch]$UseCFSAuth + [switch]$UseCFSAuth, + [switch]$SubmitWinGetManifest, + [string]$GitToken ) if ($GetPackageVersion) { @@ -107,8 +109,7 @@ function Find-LinkExe { $linkexe = (Get-Location).Path Write-Verbose -Verbose "Using $linkexe" $linkexe - } - finally { + } finally { Pop-Location } } @@ -128,8 +129,7 @@ if ($null -ne $packageType) { if (!$IsWindows) { curl https://sh.rustup.rs -sSf | sh -s -- -y $env:PATH += ":$env:HOME/.cargo/bin" - } - else { + } else { Invoke-WebRequest 'https://static.rust-lang.org/rustup/dist/i686-pc-windows-gnu/rustup-init.exe' -OutFile 'temp:/rustup-init.exe' Write-Verbose -Verbose "Use the default settings to ensure build works" & 'temp:/rustup-init.exe' -y @@ -147,9 +147,9 @@ if (!$SkipBuild -and !$SkipLinkCheck -and $IsWindows -and !(Get-Command 'link.ex if (!(Test-Path $BuildToolsPath)) { Write-Verbose -Verbose "link.exe not found, installing C++ build tools" Invoke-WebRequest 'https://aka.ms/vs/17/release/vs_BuildTools.exe' -OutFile 'temp:/vs_buildtools.exe' - $arg = @('--passive','--add','Microsoft.VisualStudio.Workload.VCTools','--includerecommended') + $arg = @('--passive', '--add', 'Microsoft.VisualStudio.Workload.VCTools', '--includerecommended') if ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64') { - $arg += '--add','Microsoft.VisualStudio.Component.VC.Tools.ARM64' + $arg += '--add', 'Microsoft.VisualStudio.Component.VC.Tools.ARM64' } Start-Process -FilePath 'temp:/vs_buildtools.exe' -ArgumentList $arg -Wait Remove-Item temp:/vs_installer.exe -ErrorAction Ignore @@ -179,8 +179,7 @@ $flags = @($Release ? '-r' : $null) if ($architecture -eq 'current') { $path = ".\target\$configuration" $target = Join-Path $PSScriptRoot 'bin' $configuration -} -else { +} else { & $rustup target add $architecture $flags += '--target' $flags += $architecture @@ -220,8 +219,7 @@ if (!$SkipBuild) { $env:CARGO_REGISTRIES_POWERSHELL_TOKEN = $header $env:CARGO_REGISTRIES_POWERSHELL_CREDENTIAL_PROVIDER = 'cargo:token' } - } - else { + } else { Write-Warning "Azure CLI not found, proceeding with anonymous access." } } @@ -274,8 +272,7 @@ if (!$SkipBuild) { if ($project -eq 'tree-sitter-dscexpression') { if ($UpdateLockFile) { cargo generate-lockfile - } - else { + } else { if ($Audit) { if ($null -eq (Get-Command cargo-audit -ErrorAction Ignore)) { cargo install cargo-audit --features=fix @@ -288,26 +285,21 @@ if (!$SkipBuild) { } } - if (Test-Path "./Cargo.toml") - { + if (Test-Path "./Cargo.toml") { if ($Clippy) { if ($clippy_unclean_projects -contains $project) { Write-Verbose -Verbose "Skipping clippy for $project" - } - elseif ($pedantic_unclean_projects -contains $project) { + } elseif ($pedantic_unclean_projects -contains $project) { Write-Verbose -Verbose "Running clippy for $project" cargo clippy @flags -- -Dwarnings - } - else { + } else { Write-Verbose -Verbose "Running clippy with pedantic for $project" cargo clippy @flags --% -- -Dwarnings -Dclippy::pedantic } - } - else { + } else { if ($UpdateLockFile) { cargo generate-lockfile - } - else { + } else { if ($Audit) { if ($null -eq (Get-Command cargo-audit -ErrorAction Ignore)) { cargo install cargo-audit --features=fix @@ -330,8 +322,7 @@ if (!$SkipBuild) { if ($IsWindows) { Copy-Item "$path/$binary.exe" $target -ErrorAction Ignore - } - else { + } else { Copy-Item "$path/$binary" $target -ErrorAction Ignore } @@ -383,8 +374,7 @@ if (!$Clippy -and !$SkipBuild) { $dirSeparator = [System.IO.Path]::DirectorySeparatorChar if ($Release) { $oldTarget = $target.Replace($dirSeparator + 'release', $dirSeparator + 'debug') - } - else { + } else { $oldTarget = $target.Replace($dirSeparator + 'debug', $dirSeparator + 'release') } $env:PATH = $env:PATH.Replace($oldTarget, '') @@ -423,15 +413,14 @@ if ($Test) { if ($IsWindows) { # PSDesiredStateConfiguration module is needed for Microsoft.Windows/WindowsPowerShell adapter - $FullyQualifiedName = @{ModuleName="PSDesiredStateConfiguration";ModuleVersion="2.0.7"} - if (-not(Get-Module -ListAvailable -FullyQualifiedName $FullyQualifiedName)) - { + $FullyQualifiedName = @{ModuleName = "PSDesiredStateConfiguration"; ModuleVersion = "2.0.7" } + if (-not(Get-Module -ListAvailable -FullyQualifiedName $FullyQualifiedName)) { Install-PSResource -Name PSDesiredStateConfiguration -Version 2.0.7 -Repository $repository -TrustRepository } } - if (-not(Get-Module -ListAvailable -Name Pester)) - { "Installing module Pester" + if (-not(Get-Module -ListAvailable -Name Pester)) { + "Installing module Pester" Install-PSResource Pester -WarningAction Ignore -Repository $repository -TrustRepository } @@ -444,8 +433,7 @@ if ($Test) { Write-Host -ForegroundColor Cyan "Testing $project ..." try { Push-Location "$PSScriptRoot/$project" - if (Test-Path "./Cargo.toml") - { + if (Test-Path "./Cargo.toml") { cargo test if ($LASTEXITCODE -ne 0) { @@ -474,8 +462,8 @@ if ($Test) { "Updated PSModulePath is:" $env:PSModulePath - if (-not(Get-Module -ListAvailable -Name Pester)) - { "Installing module Pester" + if (-not(Get-Module -ListAvailable -Name Pester)) { + "Installing module Pester" $InstallTargetDir = ($env:PSModulePath -split ";")[0] Find-PSResource -Name 'Pester' -Repository $repository | Save-PSResource -Path $InstallTargetDir -TrustRepository } @@ -493,8 +481,7 @@ function Find-MakeAppx() { # try to find if (!$UseX64MakeAppx -and $architecture -eq 'aarch64-pc-windows-msvc') { $arch = 'arm64' - } - else { + } else { $arch = 'x64' } @@ -539,8 +526,7 @@ if ($packageType -eq 'msixbundle') { Write-Verbose -Verbose "Preview version detected" if ($isPrivate) { $productName += "-Private" - } - else { + } else { $productName += "-Preview" } # save preview number @@ -552,8 +538,7 @@ if ($packageType -eq 'msixbundle') { if ($isPrivate) { $displayName += "-Private" - } - else { + } else { $displayName += "-Preview" } } @@ -697,4 +682,41 @@ if ($packageType -eq 'msixbundle') { Write-Host -ForegroundColor Green "`nGz file is created at $gzFile" } -$env:RUST_BACKTRACE=1 +function Submit-DSCWinGetAssets { + param( + [string]$GitToken + ) + + $project = 'PowerShell/DSC' + # TODO: Package identifier might change in the future + $packageId = 'Microsoft.DSC.Preview' + $restParameters = @{ + SslProtocol = 'Tls13' + Headers = @{'X-GitHub-Api-Version' = '2022-11-28' } + } + + $assets = (Invoke-RestMethod -uri "https://api.github.com/repos/$Project/releases" -Headers $restParameters)[0].assets # Get the latest version + # Grab the download URLs for supported WinGet + $downloadUrls = $assets.Where({ $_.content_type -in @('application/zip', 'application/octet-stream') }).browser_download_url + + if (-not (Get-Command wingetcreate -ErrorAction SilentlyContinue)) { + Invoke-RestMethod https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe + } + + # TODO: Version number might change in the future + $url = $downloadUrls[0] + if ($url -match 'v(\d+\.\d+\.\d+)-preview\.(\d+)') { + $firstPart = $matches[1].Remove(3) # Remove the last digit + $lastPart = $matches[2] + ".0" + $version = "$firstPart.$lastPart" + } + + + & wingetcreate.exe update $packageId --version $version --urls $downloadUrls --submit --token $GitToken +} + +if ($SubmitWinGetManifest) { + Submit-DSCWinGetAssets -GitToken $GitToken +} + +$env:RUST_BACKTRACE = 1 From 90a5c5adefaed54029469ffd1415c36b272d2cd5 Mon Sep 17 00:00:00 2001 From: "G.Reijn" Date: Sat, 28 Dec 2024 14:55:53 +0100 Subject: [PATCH 2/7] Create function to submit WinGet manifest --- .vscode/settings.json | 3 +- build.ps1 | 112 +++++++++++++++++++++++++----------------- 2 files changed, 69 insertions(+), 46 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 24bf5814d..9a3c6627d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -26,5 +26,6 @@ "vscode-nmake-tools.workspaceBuildDirectories": [ "." ], - "azure-pipelines.1ESPipelineTemplatesSchemaFile": true + "azure-pipelines.1ESPipelineTemplatesSchemaFile": true, + "powershell.codeFormatting.preset": "OTBS" } \ No newline at end of file diff --git a/build.ps1 b/build.ps1 index f0a9210dd..46bb46f8d 100644 --- a/build.ps1 +++ b/build.ps1 @@ -3,11 +3,11 @@ param( [switch]$Release, - [ValidateSet('current','aarch64-pc-windows-msvc','x86_64-pc-windows-msvc','aarch64-apple-darwin','x86_64-apple-darwin','aarch64-unknown-linux-gnu','aarch64-unknown-linux-musl','x86_64-unknown-linux-gnu','x86_64-unknown-linux-musl')] + [ValidateSet('current', 'aarch64-pc-windows-msvc', 'x86_64-pc-windows-msvc', 'aarch64-apple-darwin', 'x86_64-apple-darwin', 'aarch64-unknown-linux-gnu', 'aarch64-unknown-linux-musl', 'x86_64-unknown-linux-gnu', 'x86_64-unknown-linux-musl')] $architecture = 'current', [switch]$Clippy, [switch]$SkipBuild, - [ValidateSet('msix','msix-private','msixbundle','tgz','zip')] + [ValidateSet('msix', 'msix-private', 'msixbundle', 'tgz', 'zip')] $packageType, [switch]$Test, [switch]$GetPackageVersion, @@ -16,7 +16,9 @@ param( [switch]$UseCratesIO, [switch]$UpdateLockFile, [switch]$Audit, - [switch]$UseCFSAuth + [switch]$UseCFSAuth, + [switch]$SubmitWinGetManifest, + [string]$GitToken ) if ($GetPackageVersion) { @@ -110,8 +112,7 @@ function Find-LinkExe { $linkexe = (Get-Location).Path Write-Verbose -Verbose "Using $linkexe" $linkexe - } - finally { + } finally { Pop-Location } } @@ -131,8 +132,7 @@ if ($null -ne $packageType) { if (!$IsWindows) { curl https://sh.rustup.rs -sSf | sh -s -- -y $env:PATH += ":$env:HOME/.cargo/bin" - } - else { + } else { Invoke-WebRequest 'https://static.rust-lang.org/rustup/dist/i686-pc-windows-gnu/rustup-init.exe' -OutFile 'temp:/rustup-init.exe' Write-Verbose -Verbose "Use the default settings to ensure build works" & 'temp:/rustup-init.exe' -y @@ -150,9 +150,9 @@ if (!$SkipBuild -and !$SkipLinkCheck -and $IsWindows -and !(Get-Command 'link.ex if (!(Test-Path $BuildToolsPath)) { Write-Verbose -Verbose "link.exe not found, installing C++ build tools" Invoke-WebRequest 'https://aka.ms/vs/17/release/vs_BuildTools.exe' -OutFile 'temp:/vs_buildtools.exe' - $arg = @('--passive','--add','Microsoft.VisualStudio.Workload.VCTools','--includerecommended') + $arg = @('--passive', '--add', 'Microsoft.VisualStudio.Workload.VCTools', '--includerecommended') if ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64') { - $arg += '--add','Microsoft.VisualStudio.Component.VC.Tools.ARM64' + $arg += '--add', 'Microsoft.VisualStudio.Component.VC.Tools.ARM64' } Start-Process -FilePath 'temp:/vs_buildtools.exe' -ArgumentList $arg -Wait Remove-Item temp:/vs_installer.exe -ErrorAction Ignore @@ -182,8 +182,7 @@ $flags = @($Release ? '-r' : $null) if ($architecture -eq 'current') { $path = ".\target\$configuration" $target = Join-Path $PSScriptRoot 'bin' $configuration -} -else { +} else { & $rustup target add $architecture $flags += '--target' $flags += $architecture @@ -223,8 +222,7 @@ if (!$SkipBuild) { $env:CARGO_REGISTRIES_POWERSHELL_TOKEN = $header $env:CARGO_REGISTRIES_POWERSHELL_CREDENTIAL_PROVIDER = 'cargo:token' } - } - else { + } else { Write-Warning "Azure CLI not found, proceeding with anonymous access." } } @@ -277,8 +275,7 @@ if (!$SkipBuild) { if ($project -eq 'tree-sitter-dscexpression') { if ($UpdateLockFile) { cargo generate-lockfile - } - else { + } else { if ($Audit) { if ($null -eq (Get-Command cargo-audit -ErrorAction Ignore)) { cargo install cargo-audit --features=fix @@ -291,26 +288,21 @@ if (!$SkipBuild) { } } - if (Test-Path "./Cargo.toml") - { + if (Test-Path "./Cargo.toml") { if ($Clippy) { if ($clippy_unclean_projects -contains $project) { Write-Verbose -Verbose "Skipping clippy for $project" - } - elseif ($pedantic_unclean_projects -contains $project) { + } elseif ($pedantic_unclean_projects -contains $project) { Write-Verbose -Verbose "Running clippy for $project" cargo clippy @flags -- -Dwarnings - } - else { + } else { Write-Verbose -Verbose "Running clippy with pedantic for $project" cargo clippy @flags --% -- -Dwarnings -Dclippy::pedantic } - } - else { + } else { if ($UpdateLockFile) { cargo generate-lockfile - } - else { + } else { if ($Audit) { if ($null -eq (Get-Command cargo-audit -ErrorAction Ignore)) { cargo install cargo-audit --features=fix @@ -333,8 +325,7 @@ if (!$SkipBuild) { if ($IsWindows) { Copy-Item "$path/$binary.exe" $target -ErrorAction Ignore - } - else { + } else { Copy-Item "$path/$binary" $target -ErrorAction Ignore } @@ -386,8 +377,7 @@ if (!$Clippy -and !$SkipBuild) { $dirSeparator = [System.IO.Path]::DirectorySeparatorChar if ($Release) { $oldTarget = $target.Replace($dirSeparator + 'release', $dirSeparator + 'debug') - } - else { + } else { $oldTarget = $target.Replace($dirSeparator + 'debug', $dirSeparator + 'release') } $env:PATH = $env:PATH.Replace($oldTarget, '') @@ -426,15 +416,14 @@ if ($Test) { if ($IsWindows) { # PSDesiredStateConfiguration module is needed for Microsoft.Windows/WindowsPowerShell adapter - $FullyQualifiedName = @{ModuleName="PSDesiredStateConfiguration";ModuleVersion="2.0.7"} - if (-not(Get-Module -ListAvailable -FullyQualifiedName $FullyQualifiedName)) - { + $FullyQualifiedName = @{ModuleName = "PSDesiredStateConfiguration"; ModuleVersion = "2.0.7" } + if (-not(Get-Module -ListAvailable -FullyQualifiedName $FullyQualifiedName)) { Install-PSResource -Name PSDesiredStateConfiguration -Version 2.0.7 -Repository $repository -TrustRepository } } - if (-not(Get-Module -ListAvailable -Name Pester)) - { "Installing module Pester" + if (-not(Get-Module -ListAvailable -Name Pester)) { + "Installing module Pester" Install-PSResource Pester -WarningAction Ignore -Repository $repository -TrustRepository } @@ -447,8 +436,7 @@ if ($Test) { Write-Host -ForegroundColor Cyan "Testing $project ..." try { Push-Location "$PSScriptRoot/$project" - if (Test-Path "./Cargo.toml") - { + if (Test-Path "./Cargo.toml") { cargo test if ($LASTEXITCODE -ne 0) { @@ -477,8 +465,8 @@ if ($Test) { "Updated PSModulePath is:" $env:PSModulePath - if (-not(Get-Module -ListAvailable -Name Pester)) - { "Installing module Pester" + if (-not(Get-Module -ListAvailable -Name Pester)) { + "Installing module Pester" $InstallTargetDir = ($env:PSModulePath -split ";")[0] Find-PSResource -Name 'Pester' -Repository $repository | Save-PSResource -Path $InstallTargetDir -TrustRepository } @@ -496,8 +484,7 @@ function Find-MakeAppx() { # try to find if (!$UseX64MakeAppx -and $architecture -eq 'aarch64-pc-windows-msvc') { $arch = 'arm64' - } - else { + } else { $arch = 'x64' } @@ -542,8 +529,7 @@ if ($packageType -eq 'msixbundle') { Write-Verbose -Verbose "Preview version detected" if ($isPrivate) { $productName += "-Private" - } - else { + } else { $productName += "-Preview" } # save preview number @@ -560,8 +546,7 @@ if ($packageType -eq 'msixbundle') { if ($isPrivate) { $displayName += "-Private" - } - else { + } else { $displayName += "-Preview" } } @@ -705,4 +690,41 @@ if ($packageType -eq 'msixbundle') { Write-Host -ForegroundColor Green "`nGz file is created at $gzFile" } -$env:RUST_BACKTRACE=1 +function Submit-DSCWinGetAssets { + param( + [string]$GitToken + ) + + $project = 'PowerShell/DSC' + # TODO: Package identifier might change in the future + $packageId = 'Microsoft.DSC.Preview' + $restParameters = @{ + SslProtocol = 'Tls13' + Headers = @{'X-GitHub-Api-Version' = '2022-11-28' } + } + + $assets = (Invoke-RestMethod -uri "https://api.github.com/repos/$Project/releases" -Headers $restParameters)[0].assets # Get the latest version + # Grab the download URLs for supported WinGet + $downloadUrls = $assets.Where({ $_.content_type -in @('application/zip', 'application/octet-stream') }).browser_download_url + + if (-not (Get-Command wingetcreate -ErrorAction SilentlyContinue)) { + Invoke-RestMethod https://aka.ms/wingetcreate/latest -OutFile wingetcreate.exe + } + + # TODO: Version number might change in the future + $url = $downloadUrls[0] + if ($url -match 'v(\d+\.\d+\.\d+)-preview\.(\d+)') { + $firstPart = $matches[1].Remove(3) # Remove the last digit + $lastPart = $matches[2] + ".0" + $version = "$firstPart.$lastPart" + } + + + & wingetcreate.exe update $packageId --version $version --urls $downloadUrls --submit --token $GitToken +} + +if ($SubmitWinGetManifest) { + Submit-DSCWinGetAssets -GitToken $GitToken +} + +$env:RUST_BACKTRACE = 1 From 044729335f2730bd7adb02a46f337f29a6be3d1a Mon Sep 17 00:00:00 2001 From: "G.Reijn" Date: Fri, 6 Jun 2025 19:40:52 +0200 Subject: [PATCH 3/7] Remove unnecessary line --- build.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/build.ps1 b/build.ps1 index f4428754e..f8e2ce4a9 100644 --- a/build.ps1 +++ b/build.ps1 @@ -205,7 +205,6 @@ if ($architecture -eq 'current') { $path = ".\target\$configuration" $target = Join-Path $PSScriptRoot 'bin' $configuration } else { - & $rustup target add $architecture $flags += '--target' $flags += $architecture $path = ".\target\$architecture\$configuration" From 69c76849e011fef1d9646c319d59e9241f0d33d9 Mon Sep 17 00:00:00 2001 From: "G.Reijn" Date: Fri, 6 Jun 2025 19:44:36 +0200 Subject: [PATCH 4/7] Resolve merge conflicts --- build.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/build.ps1 b/build.ps1 index f8e2ce4a9..3d1fe94a9 100644 --- a/build.ps1 +++ b/build.ps1 @@ -353,9 +353,10 @@ if (!$SkipBuild) { $binary = Split-Path $project -Leaf if ($IsWindows) { - Copy-Item "$path/$binary.exe" $target -ErrorAction Ignore + Copy-Item "$path/$binary.exe" $target -ErrorAction Ignore -Verbose + Copy-Item "$path/$binary.pdb" $target -ErrorAction Ignore -Verbose } else { - Copy-Item "$path/$binary" $target -ErrorAction Ignore + Copy-Item "$path/$binary" $target -ErrorAction Ignore -Verbose } if (Test-Path "./copy_files.txt") { From 1ca6e8d470791d5aeeb2dd2d7b58546bd48a45f7 Mon Sep 17 00:00:00 2001 From: "G.Reijn" Date: Fri, 6 Jun 2025 19:55:07 +0200 Subject: [PATCH 5/7] Support two versions --- build.ps1 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/build.ps1 b/build.ps1 index 3d1fe94a9..80cee4690 100644 --- a/build.ps1 +++ b/build.ps1 @@ -20,6 +20,7 @@ param( [switch]$Audit, [switch]$UseCFSAuth, [switch]$SubmitWinGetManifest, + [switch]$PreRelease, [string]$GitToken, [switch]$Clean, [switch]$Verbose @@ -733,18 +734,21 @@ if ($packageType -eq 'msixbundle') { function Submit-DSCWinGetAssets { param( - [string]$GitToken + [string]$GitToken, + [switch] $IsPreRelease ) $project = 'PowerShell/DSC' # TODO: Package identifier might change in the future - $packageId = 'Microsoft.DSC.Preview' + $packageId = 'Microsoft.DSC' $restParameters = @{ SslProtocol = 'Tls13' Headers = @{'X-GitHub-Api-Version' = '2022-11-28' } } - $assets = (Invoke-RestMethod -uri "https://api.github.com/repos/$Project/releases" -Headers $restParameters)[0].assets # Get the latest version + $assets = ((Invoke-RestMethod -uri "https://api.github.com/repos/$Project/releases" -Headers $restParameters) | + Where-Object -Property prerelease -EQ $IsPreRelease.IsPresent | + Select-Object -First 1 -Property assets).assets # ExpandProperty did not work # Grab the download URLs for supported WinGet $downloadUrls = $assets.Where({ $_.content_type -in @('application/zip', 'application/octet-stream') }).browser_download_url @@ -758,6 +762,8 @@ function Submit-DSCWinGetAssets { $firstPart = $matches[1].Remove(3) # Remove the last digit $lastPart = $matches[2] + ".0" $version = "$firstPart.$lastPart" + + $packageId = "$packageId.Preview" } @@ -765,7 +771,7 @@ function Submit-DSCWinGetAssets { } if ($SubmitWinGetManifest) { - Submit-DSCWinGetAssets -GitToken $GitToken + Submit-DSCWinGetAssets -GitToken $GitToken -IsPreRelease:$PreRelease } $env:RUST_BACKTRACE = 1 From e5f3d295f8a1a82e4ffa2d3ec4679493650d0e13 Mon Sep 17 00:00:00 2001 From: "G.Reijn" Date: Sat, 7 Jun 2025 03:28:05 +0200 Subject: [PATCH 6/7] Rebuild with workflow --- .github/workflows/winget.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/winget.yml diff --git a/.github/workflows/winget.yml b/.github/workflows/winget.yml new file mode 100644 index 000000000..cfa096f3d --- /dev/null +++ b/.github/workflows/winget.yml @@ -0,0 +1,21 @@ +name: Publish to Winget + +on: + push: + pull_request: + workflow_dispatch: + +jobs: + publish: + runs-on: windows-latest # Action can only run on Windows + steps: + - name: Publish Microsoft.DSC ${{ github.event.release.prerelease && 'Preview' || 'Stable' }} + run: | + $assets = '${{ toJSON(github.event.release.assets) }}' | ConvertFrom-Json + $wingetRelevantAsset = $assets | Where-Object { $_.name -like '*.zip' } | Select-Object -First 1 + $regex = [Regex]::New($env:REGEX) + $version = $regex.Match($wingetRelevantAsset.name).Groups[1].Value + + $assets + + $wingetPackage = "Microsoft.DSC${{ github.event.release.prerelease && '.Preview' || '' }}" \ No newline at end of file From 4b7c7f7eaa4eda05243c182bad69a5bdb765fbbc Mon Sep 17 00:00:00 2001 From: "G.Reijn" Date: Sat, 7 Jun 2025 03:44:41 +0200 Subject: [PATCH 7/7] Update workflow file --- .github/workflows/winget.yml | 18 ++++++++++++------ build.ps1 | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/winget.yml b/.github/workflows/winget.yml index cfa096f3d..6630aa997 100644 --- a/.github/workflows/winget.yml +++ b/.github/workflows/winget.yml @@ -1,9 +1,12 @@ name: Publish to Winget on: - push: - pull_request: - workflow_dispatch: + release: + types: [published] + + +env: + REGEX: 'DSC-(\d+\.\d+\.\d+(?:-preview\.\d+)?)-(?:x86_64|aarch64)-pc-windows-msvc\.zip' jobs: publish: @@ -12,10 +15,13 @@ jobs: - name: Publish Microsoft.DSC ${{ github.event.release.prerelease && 'Preview' || 'Stable' }} run: | $assets = '${{ toJSON(github.event.release.assets) }}' | ConvertFrom-Json - $wingetRelevantAsset = $assets | Where-Object { $_.name -like '*.zip' } | Select-Object -First 1 + $wingetRelevantAsset = $assets | Where-Object { $_.name -like '*.zip' -and $_.name -like '*.msixbundle' } | Select-Object -First 1 $regex = [Regex]::New($env:REGEX) $version = $regex.Match($wingetRelevantAsset.name).Groups[1].Value - $assets + $wingetPackage = "Microsoft.DSC${{ github.event.release.prerelease && '.Preview' || '' }}" + + & curl.exe -JLO https://aka.ms/wingetcreate/latest + & .\wingetcreate.exe update $wingetPackage -s -v $version -u $wingetRelevantAsset.browser_download_url -t "${{ secrets.WINGET_TOKEN }}" + - $wingetPackage = "Microsoft.DSC${{ github.event.release.prerelease && '.Preview' || '' }}" \ No newline at end of file diff --git a/build.ps1 b/build.ps1 index 80cee4690..a40dfe523 100644 --- a/build.ps1 +++ b/build.ps1 @@ -739,7 +739,6 @@ function Submit-DSCWinGetAssets { ) $project = 'PowerShell/DSC' - # TODO: Package identifier might change in the future $packageId = 'Microsoft.DSC' $restParameters = @{ SslProtocol = 'Tls13' @@ -750,6 +749,7 @@ function Submit-DSCWinGetAssets { Where-Object -Property prerelease -EQ $IsPreRelease.IsPresent | Select-Object -First 1 -Property assets).assets # ExpandProperty did not work # Grab the download URLs for supported WinGet + $downloadUrls = $assets.Where({ $_.content_type -in @('application/zip', 'application/octet-stream') }).browser_download_url if (-not (Get-Command wingetcreate -ErrorAction SilentlyContinue)) {