-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.ps1
50 lines (44 loc) · 1.52 KB
/
generate.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# This script requires PowerShell 6 or above
param(
[switch] $Preview = $false,
[switch] $Stable = $false,
[Parameter()]
[string] $GithubToken
)
$Headers = @{
Accept = "application/vnd.github+json";
}
if ("${GithubToken}" -ne "") {
$Headers['Authorization'] = $GithubToken
}
# All releases, in version order
$AllReleases = (Invoke-WebRequest -URI https://api.github.com/repos/OpenKneeboard/OpenKneeboard/releases -Headers $Headers).Content
| ConvertFrom-Json
| Sort-Object -Descending -Property { [System.Management.Automation.SemanticVersion] ($_.tag_name -replace '^v' -replace 'beta','beta.') }
function Get-Update-Version($object) {
return $object.tag_name
}
function Write-Update-File-If-Changed($File, $NewData) {
$OldVersion = (Get-Update-Version (Get-Content $File | ConvertFrom-Json))
$NewVersion = (Get-Update-Version $NewData)
Write-Host -NoNewline "[$((Get-Item $File).BaseName)] ${OldVersion} -> ${NewVersion}: "
if ($OldVersion -eq $NewVersion) {
Write-Host "no change."
return
}
Write-Host "UPDATING"
$NewData | ConvertTo-Json -Depth 8 -AsArray | Out-File -Encoding utf8NoBOM -FilePath $File
}
if ($Preview) {
# Highest semver, regardless of if it's a prerelease or not
$UpdateData = $AllReleases
| Select-Object -First 1
Write-Update-File-If-Changed 'preview-msi.json' $UpdateData
}
if ($Stable) {
# Latest stable release
$UpdateData = $AllReleases
| Where-Object -Not -Property 'prerelease'
| Select-Object -First 1
Write-Update-File-If-Changed 'stable-msi.json' $UpdateData
}