-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.ps1
51 lines (41 loc) · 1.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
Import-Module PowerShellForGitHub
$installerFileNameRegex = 'ViVeTool-v[\d\.]+\.zip$'
$owner = 'thebookisclosed'
$repository = 'ViVe'
function Get-GitHubReleaseObject([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())"
}
return $release
}
function Get-SourceCode([version] $Version) {
$release = Get-GitHubReleaseObject -Version $Version
$userAgent = 'Update checker of Chocolatey Community Package ''vivetool'''
Invoke-WebRequest -Uri $release.zipball_url -UserAgent $userAgent -OutFile ".\ViVe-v$Version.zip" -UseBasicParsing
}
function Get-LatestStableVersion {
$latestRelease = (Get-GitHubRelease -OwnerName $owner -RepositoryName $repository -Latest)[0]
return [version] $latestRelease.tag_name.Substring(1)
}
function Get-SoftwareUri([version] $Version) {
$release = Get-GitHubReleaseObject -Version $Version
$releaseAssets = Get-GitHubReleaseAsset -OwnerName $owner -RepositoryName $repository -Release $release.ID
$windowsPortableArchiveAsset = $null
foreach ($asset in $releaseAssets) {
if ($asset.name -match $installerFileNameRegex) {
$windowsPortableArchiveAsset = $asset
break
}
else {
continue
}
}
if ($null -eq $windowsPortableArchiveAsset) {
throw 'Cannot find published Windows portable archive asset!'
}
return $windowsPortableArchiveAsset.browser_download_url
}