oh-my-posh/packages/winget/build.ps1

85 lines
2.6 KiB
PowerShell
Raw Normal View History

2021-01-29 10:50:11 -08:00
Param
(
[parameter(Mandatory = $true)]
[string]
$Version,
[parameter(Mandatory = $false)]
[string]
$Token
)
2021-09-14 09:13:33 -07:00
function Get-HashForArchitecture {
param (
[parameter(Mandatory = $true)]
[string]
$Architecture,
[parameter(Mandatory = $true)]
[string]
$Version
)
2024-12-01 08:57:52 -08:00
$hash = (new-object Net.WebClient).DownloadString("https://cdn.ohmyposh.dev/releases/v$Version/install-$Architecture.msi.sha256")
return $hash.Trim()
2021-09-14 09:13:33 -07:00
}
function Write-MetaData {
2021-01-29 10:50:11 -08:00
param (
[parameter(Mandatory = $true)]
[string]
$FileName,
[parameter(Mandatory = $true)]
[string]
$Version,
[parameter(Mandatory = $true)]
[string]
2021-09-14 09:13:33 -07:00
$HashAmd64,
[parameter(Mandatory = $true)]
[string]
$HashArm64,
[parameter(Mandatory = $true)]
[string]
$Hash386
2021-01-29 10:50:11 -08:00
)
$content = Get-Content $FileName -Raw
$content = $content.Replace('<VERSION>', $Version)
2021-09-14 09:13:33 -07:00
$content = $content.Replace('<HASH-AMD64>', $HashAmd64)
$content = $content.Replace('<HASH-ARM64>', $HashArm64)
$content = $content.Replace('<HASH-386>', $Hash386)
$date = Get-Date -Format "yyyy-MM-dd"
$content = $content.Replace('<DATE>', $date)
2021-01-29 10:50:11 -08:00
$content | Out-File -Encoding 'UTF8' "./$Version/$FileName"
}
# clean version string
$Version = $Version.TrimStart('v')
2021-01-29 10:50:11 -08:00
New-Item -Path $PWD -Name $Version -ItemType "directory"
# Get all files inside the folder and adjust the version/hash
2024-11-24 10:18:10 -08:00
$HashAmd64 = Get-HashForArchitecture -Architecture 'x64' -Version $Version
2021-09-14 09:13:33 -07:00
$HashArm64 = Get-HashForArchitecture -Architecture 'arm64' -Version $Version
2024-11-24 10:18:10 -08:00
$Hash386 = Get-HashForArchitecture -Architecture 'x86' -Version $Version
2021-01-29 10:50:11 -08:00
Get-ChildItem '*.yaml' | ForEach-Object -Process {
Write-MetaData -FileName $_.Name -Version $Version -HashAmd64 $HashAmd64 -HashArm64 $HashArm64 -Hash386 $Hash386
2021-01-29 10:50:11 -08:00
}
2024-11-24 10:18:10 -08:00
2021-01-29 10:50:11 -08:00
if (-not $Token) {
return
}
2024-11-24 10:18:10 -08:00
# Install the latest wingetcreate exe
2022-12-16 06:19:18 -08:00
# Need to do things this way, see https://github.com/PowerShell/PowerShell/issues/13138
Import-Module Appx -UseWindowsPowerShell
# Download and install C++ Runtime framework package.
$vcLibsBundleFile = "$env:TEMP\Microsoft.VCLibs.Desktop.appx"
Invoke-WebRequest https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx -OutFile $vcLibsBundleFile
Add-AppxPackage $vcLibsBundleFile
# Download Winget-Create msixbundle, install, and execute update.
$appxBundleFile = "$env:TEMP\wingetcreate.msixbundle"
Invoke-WebRequest https://aka.ms/wingetcreate/latest/msixbundle -OutFile $appxBundleFile
Add-AppxPackage $appxBundleFile
2021-01-29 10:50:11 -08:00
# Create the PR
wingetcreate submit --token $Token $Version