-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.ps1
44 lines (36 loc) · 1.26 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
Import-Module PowerShellForGitHub
$installerFileNameRegex = 'Crushee-v([\d\.]+)-win-setup\.exe$'
$owner = 'xanderfrangos'
$repository = 'crushee'
function Get-LatestStableVersion {
$latestRelease = (Get-GitHubRelease -OwnerName $owner -RepositoryName $repository -Latest)[0]
return [Version] $latestRelease.tag_name.Substring(1)
}
function Get-SoftwareUri {
[CmdletBinding()]
param(
[Version] $Version
)
if ($null -eq $Version) {
# Default to latest stable version
$release = (Get-GitHubRelease -OwnerName $owner -RepositoryName $repository -Latest)[0]
}
else {
$release = Get-GitHubRelease -OwnerName $owner -RepositoryName $repository -Tag "v$($Version.ToString())"
}
$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
}