-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.ps1
74 lines (58 loc) · 2.66 KB
/
helpers.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
Import-Module PowerShellForGitHub
$installerFileNameRegex = 'Twinkle\.Tray\.v([\d\.]+(-beta[\d\.]+)?)\.exe'
$owner = 'xanderfrangos'
$repository = 'twinkle-tray'
function ConvertTo-SemVerV1CompliantVersion([string] $Version) {
$tokens = $Version -split '-'
$result = $tokens[0] + '-'
$result += $tokens[1] -replace '\.', '-'
return $result
}
function Get-LatestVersionInfo {
$releases = Get-GitHubRelease -OwnerName $owner -RepositoryName $repository
$latestStableRelease = $releases | Where-Object { $_.PreRelease -eq $false } | Select-Object -First 1
$latestStableVersion = $latestStableRelease.tag_name.Substring(1)
$latestNonCanaryBeta = $releases | Where-Object { $_.PreRelease -eq $true -and $_.tag_name -match 'v.*-beta[\d\.]+$' } | Select-Object -First 1
$latestBetaVersion = $latestNonCanaryBeta.tag_name.Substring(1)
$stableVersionInfo = @{
Url64 = Get-SoftwareAssetUriFromRelease -Release $latestStableRelease
Version = $latestStableVersion #This may change if building a package fix version
SoftwareVersion = $latestStableVersion
}
$betaVersionInfo = @{
Url64 = Get-SoftwareAssetUriFromRelease -Release $latestNonCanaryBeta
Version = ConvertTo-SemVerV1CompliantVersion -Version $latestBetaVersion #This may change if building a package fix version
SoftwareVersion = $latestBetaVersion
}
return [Ordered] @{
Beta = $betaVersionInfo
Stable = $stableVersionInfo
}
}
function Get-SoftwareAssetUriFromRelease($Release) {
$releaseAssets = Get-GitHubReleaseAsset -OwnerName $owner -RepositoryName $repository -Release $release.ID
$windowsInstallerAsset = $null
foreach ($asset in $releaseAssets) {
if ($asset.name -match $installerFileNameRegex) {
$windowsInstallerAsset = $asset
break
}
else {
continue
}
}
if ($null -eq $windowsInstallerAsset) {
throw 'Cannot find published Windows installer asset!'
}
return $windowsInstallerAsset.browser_download_url
}
function Get-SoftwareUri($Version) {
#TODO: Add entries for any package version deviations from the software version (e.g. pre-release versions without a trailing string, package fix versions)
switch ($Version) {
'1.15.3-beta' { $softwareVersion = '1.15.3' }
'1.16.0-beta5-1' { $softwareVersion = '1.16.0-beta5.1' }
default { $softwareVersion = $Version }
}
$release = Get-GitHubRelease -OwnerName $owner -RepositoryName $repository -Tag "v$($softwareVersion.ToString())"
return Get-SoftwareAssetUriFromRelease -Release $release
}