-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgithub_repo_version_scan.ps1
67 lines (60 loc) · 1.61 KB
/
github_repo_version_scan.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
function Parse-Json {
param (
[string]$Json,
[string]$Key
)
$ParsedJson = $Json | ConvertFrom-Json
return $ParsedJson.$Key
}
function Get-RepoVersion {
param (
[string]$Repo
)
$LatestReleaseInfo = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest"
return $LatestReleaseInfo.tag_name
}
function Check-NeedBuild {
param (
[string]$RemoteVersion,
[string]$ThisVersion
)
$NeedBuild = "no"
if ($ThisVersion[0] -ne 'v') {
$NeedBuild = "yes"
return $NeedBuild
}
$RemoteVersionNoV = $RemoteVersion.Substring(1)
$ThisVersionNoV = $ThisVersion.Substring(1)
$SortedVersions = @($RemoteVersionNoV, $ThisVersionNoV) | Sort-Object { [Version]$_ }
if ($RemoteVersionNoV -ne $SortedVersions[0]) {
$NeedBuild = "yes"
}
return $NeedBuild
}
function Get-RepoLatestUploadUrl {
param (
[string]$Repo
)
$LatestReleaseInfo = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest"
return $LatestReleaseInfo.upload_url
}
function Check-FileExistFromRepoLatest {
param (
[string]$Repo,
[string]$FileName,
[string]$Token
)
$Headers = @{
"Authorization" = "Bearer $Token"
}
$Response = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest" -Headers $Headers
$AssetNames = $Response.assets.name
$AssetExists = "no"
foreach ($Name in $AssetNames) {
if ($Name -eq $FileName) {
$AssetExists = "yes"
break
}
}
return $AssetExists
}