|
| 1 | +<# |
| 2 | +
|
| 3 | +.NOTES |
| 4 | +Copyright (c) Microsoft Corporation. |
| 5 | +Licensed under the MIT License. |
| 6 | +
|
| 7 | +.SYNOPSIS |
| 8 | +Updates the winget manifests for texassemble, texconv, and texdiag to match a GitHub release. |
| 9 | +
|
| 10 | +.DESCRIPTION |
| 11 | +This script creates new winget manifest versions for texassemble, texconv, and texdiag under |
| 12 | +D:\winget-pkgs based on the most recent release date in README.md. It copies the previous |
| 13 | +version's manifests, then updates PackageVersion, ReleaseDate, InstallerSha256, InstallerUrl, |
| 14 | +and ReleaseNotesUrl to match the new release. |
| 15 | +
|
| 16 | +.PARAMETER Tag |
| 17 | +The GitHub release tag (e.g., 'may2026', 'mar2026'). Defaults to the latest tag. |
| 18 | +
|
| 19 | +.LINK |
| 20 | +https://github.com/microsoft/DirectXTex/wiki |
| 21 | +
|
| 22 | +#> |
| 23 | + |
| 24 | +param( |
| 25 | + [string]$Tag = "" |
| 26 | +) |
| 27 | + |
| 28 | +$repoRoot = Split-Path -Path $PSScriptRoot -Parent |
| 29 | +$readme = Join-Path $repoRoot "README.md" |
| 30 | +$wingetPkgs = "D:\winget-pkgs" |
| 31 | + |
| 32 | +if (-Not (Test-Path $readme)) { |
| 33 | + Write-Error "ERROR: Cannot find README.md at $readme" -ErrorAction Stop |
| 34 | +} |
| 35 | + |
| 36 | +if (-Not (Test-Path $wingetPkgs)) { |
| 37 | + Write-Error "ERROR: Cannot find winget-pkgs at $wingetPkgs" -ErrorAction Stop |
| 38 | +} |
| 39 | + |
| 40 | +# Determine tag from latest git tag if not provided |
| 41 | +if ($Tag.Length -eq 0) { |
| 42 | + $Tag = (git --no-pager -C $repoRoot tag --sort=-creatordate | Select-Object -First 1).Trim() |
| 43 | + if ($Tag.Length -eq 0) { |
| 44 | + Write-Error "ERROR: Failed to determine latest tag!" -ErrorAction Stop |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +Write-Host "Release Tag: $Tag" |
| 49 | + |
| 50 | +# Parse release date from README.md (format: "## Month Day, Year") |
| 51 | +$rawReleaseDate = (Get-Content $readme) | Select-String -Pattern "^##\s+[A-Z][a-z]+\s+\d+,?\s+\d{4}" | Select-Object -First 1 |
| 52 | +if ([string]::IsNullOrEmpty($rawReleaseDate)) { |
| 53 | + Write-Error "ERROR: Failed to find release date in README.md!" -ErrorAction Stop |
| 54 | +} |
| 55 | + |
| 56 | +$releaseDateStr = ($rawReleaseDate -replace '^##\s+', '').Trim() |
| 57 | +$releaseDate = [datetime]::Parse($releaseDateStr, [System.Globalization.CultureInfo]::InvariantCulture) |
| 58 | + |
| 59 | +# winget version format: YYYY.M.D (no leading zeros) |
| 60 | +$packageVersion = $releaseDate.ToString("yyyy.M.d") |
| 61 | + |
| 62 | +# winget ReleaseDate format: YYYY-MM-DD |
| 63 | +$releaseDateYaml = $releaseDate.ToString("yyyy-MM-dd") |
| 64 | + |
| 65 | +Write-Host "Release Date: $releaseDateStr" |
| 66 | +Write-Host "Package Version: $packageVersion" |
| 67 | +Write-Host "Release Date (YAML): $releaseDateYaml" |
| 68 | + |
| 69 | +# --- Tool definitions --- |
| 70 | +# Each tool has a manifest base path and a list of release assets (name + architecture) |
| 71 | +$tools = @( |
| 72 | + @{ |
| 73 | + Name = "Texassemble" |
| 74 | + ManifestBase = Join-Path $wingetPkgs "manifests\m\Microsoft\DirectXTex\Texassemble" |
| 75 | + PackageId = "Microsoft.DirectXTex.Texassemble" |
| 76 | + Assets = @( |
| 77 | + @{ FileName = "texassemble.exe"; Arch = "x64" }, |
| 78 | + @{ FileName = "texassemble_arm64.exe"; Arch = "arm64" } |
| 79 | + ) |
| 80 | + }, |
| 81 | + @{ |
| 82 | + Name = "Texconv" |
| 83 | + ManifestBase = Join-Path $wingetPkgs "manifests\m\Microsoft\DirectXTex\Texconv" |
| 84 | + PackageId = "Microsoft.DirectXTex.Texconv" |
| 85 | + Assets = @( |
| 86 | + @{ FileName = "texconv.exe"; Arch = "x64" }, |
| 87 | + @{ FileName = "texconv_arm64.exe"; Arch = "arm64" } |
| 88 | + ) |
| 89 | + }, |
| 90 | + @{ |
| 91 | + Name = "Texdiag" |
| 92 | + ManifestBase = Join-Path $wingetPkgs "manifests\m\Microsoft\DirectXTex\Texdiag" |
| 93 | + PackageId = "Microsoft.DirectXTex.Texdiag" |
| 94 | + Assets = @( |
| 95 | + @{ FileName = "texdiag.exe"; Arch = "x64" }, |
| 96 | + @{ FileName = "texdiag_arm64.exe"; Arch = "arm64" } |
| 97 | + ) |
| 98 | + } |
| 99 | +) |
| 100 | + |
| 101 | +# --- Find previous version directory --- |
| 102 | +function Get-LatestVersionDir { |
| 103 | + param([string]$BasePath) |
| 104 | + $dirs = Get-ChildItem -Path $BasePath -Directory | Sort-Object Name |
| 105 | + if ($dirs.Count -eq 0) { |
| 106 | + Write-Error "ERROR: No existing version directories found in $BasePath" -ErrorAction Stop |
| 107 | + } |
| 108 | + return $dirs[-1] |
| 109 | +} |
| 110 | + |
| 111 | +# --- Download release assets and compute SHA256 hashes --- |
| 112 | +$ProgressPreference = 'SilentlyContinue' |
| 113 | +$tempDir = Join-Path $Env:Temp $(New-Guid) |
| 114 | +New-Item -Type Directory -Path $tempDir | Out-Null |
| 115 | + |
| 116 | +$hashes = @{} |
| 117 | + |
| 118 | +# Collect all unique asset filenames across tools |
| 119 | +$allAssets = $tools | ForEach-Object { $_.Assets } | ForEach-Object { $_ } |
| 120 | + |
| 121 | +foreach ($asset in $allAssets) { |
| 122 | + $url = "https://github.com/microsoft/DirectXTex/releases/download/$Tag/$($asset.FileName)" |
| 123 | + $outPath = Join-Path $tempDir $asset.FileName |
| 124 | + Write-Host "`nDownloading $($asset.FileName) from $url..." |
| 125 | + try { |
| 126 | + Invoke-WebRequest -Uri $url -OutFile $outPath -ErrorAction Stop |
| 127 | + } |
| 128 | + catch { |
| 129 | + Write-Error "ERROR: Failed to download $($asset.FileName)!" -ErrorAction Stop |
| 130 | + } |
| 131 | + $hash = (Get-FileHash -Path $outPath -Algorithm SHA256).Hash.ToLower() |
| 132 | + $hashes[$asset.FileName] = $hash |
| 133 | + Write-Host " SHA256: $hash" |
| 134 | +} |
| 135 | + |
| 136 | +# --- Create new manifests for each tool --- |
| 137 | +$newDirs = @() |
| 138 | + |
| 139 | +foreach ($tool in $tools) { |
| 140 | + $prevDir = Get-LatestVersionDir $tool.ManifestBase |
| 141 | + $newDir = Join-Path $tool.ManifestBase $packageVersion |
| 142 | + |
| 143 | + Write-Host "`nPrevious $($tool.Name) version: $($prevDir.Name)" |
| 144 | + |
| 145 | + if (Test-Path $newDir) { |
| 146 | + Write-Error "ERROR: $($tool.Name) version $packageVersion already exists at $newDir" -ErrorAction Stop |
| 147 | + } |
| 148 | + |
| 149 | + Write-Host "Creating $($tool.Name) $packageVersion manifests..." |
| 150 | + Copy-Item -Path $prevDir.FullName -Destination $newDir -Recurse |
| 151 | + |
| 152 | + foreach ($file in Get-ChildItem -Path $newDir -Filter "*.yaml") { |
| 153 | + $content = Get-Content $file.FullName -Raw |
| 154 | + $content = $content -replace "PackageVersion:\s+\S+", "PackageVersion: $packageVersion" |
| 155 | + |
| 156 | + if ($file.Name -match "installer") { |
| 157 | + $content = $content -replace "ReleaseDate:\s+\S+", "ReleaseDate: $releaseDateYaml" |
| 158 | + |
| 159 | + # Update installer URLs |
| 160 | + foreach ($asset in $tool.Assets) { |
| 161 | + $escapedFileName = [regex]::Escape($asset.FileName) |
| 162 | + $content = $content -replace "(InstallerUrl:\s+).+$escapedFileName", "`${1}https://github.com/microsoft/DirectXTex/releases/download/$Tag/$($asset.FileName)" |
| 163 | + } |
| 164 | + |
| 165 | + # Update SHA256 hashes per architecture block |
| 166 | + $lines = $content -split "`n" |
| 167 | + $currentArch = "" |
| 168 | + for ($i = 0; $i -lt $lines.Count; $i++) { |
| 169 | + if ($lines[$i] -match "Architecture:\s+(\S+)") { |
| 170 | + $currentArch = $Matches[1] |
| 171 | + } |
| 172 | + |
| 173 | + if ($lines[$i] -match "InstallerSha256:") { |
| 174 | + $matchingAsset = $tool.Assets | Where-Object { $_.Arch -eq $currentArch } |
| 175 | + if ($matchingAsset) { |
| 176 | + $lines[$i] = " InstallerSha256: $($hashes[$matchingAsset.FileName])" |
| 177 | + } |
| 178 | + } |
| 179 | + } |
| 180 | + $content = $lines -join "`n" |
| 181 | + } |
| 182 | + |
| 183 | + if ($file.Name -match "locale") { |
| 184 | + $content = $content -replace "(ReleaseNotesUrl:\s+).+", "`${1}https://github.com/microsoft/DirectXTex/releases/tag/$Tag" |
| 185 | + } |
| 186 | + |
| 187 | + Set-Content -Path $file.FullName -Value $content -NoNewline |
| 188 | + } |
| 189 | + |
| 190 | + foreach ($file in Get-ChildItem -Path $newDir -Filter "*.yaml") { |
| 191 | + Write-Host " $($file.Name)" |
| 192 | + } |
| 193 | + |
| 194 | + $newDirs += $newDir |
| 195 | +} |
| 196 | + |
| 197 | +# --- Cleanup --- |
| 198 | +Remove-Item -Recurse -Force $tempDir |
| 199 | + |
| 200 | +Write-Host "`nwinget manifests created successfully!" |
| 201 | +Write-Host "`nNew manifest directories:" |
| 202 | +foreach ($dir in $newDirs) { |
| 203 | + Write-Host " $dir" |
| 204 | +} |
| 205 | +Write-Host "`nNext steps:" |
| 206 | +Write-Host " 1. Review the generated manifest files" |
| 207 | +foreach ($dir in $newDirs) { |
| 208 | + Write-Host " 2. Validate with: winget validate $dir" |
| 209 | +} |
| 210 | +foreach ($dir in $newDirs) { |
| 211 | + Write-Host " 3. Test with: winget install --manifest $dir" |
| 212 | +} |
| 213 | +Write-Host " 4. Submit PRs to the winget-pkgs repository" |
| 214 | +Write-Host "" |
| 215 | +Write-Host " NOTE: Each tool must be submitted as its own separate PR per winget-pkgs policy." |
0 commit comments