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

61 lines
1.8 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
)
$hash = (new-object Net.WebClient).DownloadString("https://github.com/JanDeDobbeleer/oh-my-posh/releases/download/v$Version/install-$Architecture.exe.sha256")
return $hash
}
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
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)
2021-01-29 10:50:11 -08:00
$content | Out-File -Encoding 'UTF8' "./$Version/$FileName"
}
New-Item -Path $PWD -Name $Version -ItemType "directory"
# Get all files inside the folder and adjust the version/hash
2021-09-14 09:13:33 -07:00
$HashAmd64 = Get-HashForArchitecture -Architecture 'amd64' -Version $Version
$HashArm64 = Get-HashForArchitecture -Architecture 'arm64' -Version $Version
2021-01-29 10:50:11 -08:00
Get-ChildItem '*.yaml' | ForEach-Object -Process {
2021-09-14 09:13:33 -07:00
Write-MetaData -FileName $_.Name -Version $Version -HashAmd64 $HashAmd64 -HashArm64 $HashArm64
2021-01-29 10:50:11 -08:00
}
if (-not $Token) {
return
}
# Get the latest wingetcreate exe
Invoke-WebRequest 'https://aka.ms/wingetcreate/latest/self-contained' -OutFile wingetcreate.exe
2021-01-29 10:50:11 -08:00
# Create the PR
./wingetcreate.exe submit --token $Token $Version