Skip to content

Commit 1e1bea4

Browse files
authored
Merge pull request #835 from aaronparker/apps
Apps
2 parents 9a5df3c + 16d6cb5 commit 1e1bea4

8 files changed

Lines changed: 227 additions & 84 deletions

Evergreen/Apps/Get-Eduvpn.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ Function Get-eduVPN {
2222
MatchVersion = $res.Get.MatchVersion
2323
Filter = $res.Get.MatchFileTypes
2424
}
25-
$object = Get-GitHubRepoRelease @params
26-
25+
$object = Get-CodebergRepoRelease @params
2726
Write-Output -InputObject $object
2827
}

Evergreen/Apps/Get-GhislerTotalCommander.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ function Get-GhislerTotalCommander {
55
66
.NOTES
77
Author: Aaron Parker
8-
Twitter: @stealthpuppy
98
#>
109
[OutputType([System.Management.Automation.PSObject])]
1110
[CmdletBinding(SupportsShouldProcess = $False)]
@@ -23,7 +22,6 @@ function Get-GhislerTotalCommander {
2322
}
2423
$Response = Resolve-DnsNameWrapper @params
2524
if ($null -ne $Response) {
26-
2725
try {
2826
$Value = ([Regex]$res.Get.Update.MatchVersion).Match($Response).Groups.Value
2927
$Major = $Value.Split(".")[1]

Evergreen/Apps/Get-MicrosoftAzureDataStudio.ps1

Lines changed: 0 additions & 49 deletions
This file was deleted.

Evergreen/Evergreen.json

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"ErrorAction": "Stop"
44
},
55
"UserAgent": {
6-
"Base": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.3124.85",
6+
"Base": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.3124.85",
77
"Download": [
88
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.3124.85",
99
"Googlebot/2.1 (+http://www.google.com/bot.html)"
@@ -47,6 +47,26 @@
4747
"zipball_url",
4848
"tarball_url",
4949
"node_id"
50+
],
51+
"Codeberg": [
52+
"archive_download_count",
53+
"assets",
54+
"author",
55+
"body",
56+
"created_at",
57+
"draft",
58+
"hide_archive_links",
59+
"html_url",
60+
"id",
61+
"name",
62+
"prerelease",
63+
"published_at",
64+
"tag_name",
65+
"tarball_url",
66+
"target_commitish",
67+
"upload_url",
68+
"url",
69+
"zipball_url"
5070
]
5171
},
5272
"Uri": {

Evergreen/Manifests/Eduvpn.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"Name": "eduVPN",
33
"Source": "https://app.eduvpn.org/",
44
"Get": {
5-
"Uri": "https://api.github.com/repos/Amebis/eduVPN/releases/latest",
5+
"Uri": "https://codeberg.org/api/v1/repos/eduVPN/windows/releases/latest",
66
"MatchVersion": "(\\d+(\\.\\d+){1,4}).*",
77
"MatchFileTypes": "eduVPNClient_.*(exe|msi)$"
88
},

Evergreen/Manifests/GhislerTotalCommander.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
},
1010
"Download": {
1111
"Uri": {
12-
"x86": "https://totalcommander.ch/win/tcmd#versionx32.exe",
13-
"x64": "https://totalcommander.ch/win/tcmd#versionx64.exe"
12+
"x86": "https://totalcommander.ch/#version/tcmd#versionx32.exe",
13+
"x64": "https://totalcommander.ch/#version/tcmd#versionx64.exe"
1414
},
1515
"ReplaceText": "#version"
1616
}

Evergreen/Manifests/MicrosoftAzureDataStudio.json

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
function Get-CodebergRepoRelease {
2+
<#
3+
.SYNOPSIS
4+
Calls the Codeberg Releases API passed via $Uri, validates the response and returns a formatted object
5+
Docs: https://codeberg.org/api/swagger
6+
#>
7+
[OutputType([System.Management.Automation.PSObject])]
8+
[CmdletBinding(SupportsShouldProcess = $false)]
9+
param (
10+
[Parameter(Mandatory = $true, Position = 0)]
11+
[ValidateScript( {
12+
if ($_ -match "^(https://codeberg.org/api/v1/repos/)([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)(/tags|/releases)") {
13+
$true
14+
}
15+
else {
16+
throw "'$_' must be in the format 'https://codeberg.org/api/v1/repos/user/repository/releases'. Replace 'user' with the user or organisation and 'repository' with the target repository name."
17+
}
18+
})]
19+
[System.String] $Uri,
20+
21+
[Parameter(Mandatory = $false, Position = 1)]
22+
[ValidateNotNullOrEmpty()]
23+
[System.String] $MatchVersion = "(\d+(\.\d+){1,4}).*",
24+
25+
[Parameter(Mandatory = $false, Position = 2)]
26+
[ValidateNotNullOrEmpty()]
27+
[System.String] $VersionTag = "tag_name",
28+
29+
[Parameter(Mandatory = $false, Position = 3)]
30+
[ValidateNotNullOrEmpty()]
31+
[System.String] $Filter = "\.exe$|\.msi$|\.msp$|\.zip$",
32+
33+
[Parameter(Mandatory = $false, Position = 4)]
34+
[System.Array] $VersionReplace,
35+
36+
[Parameter()]
37+
[System.Management.Automation.SwitchParameter] $ReturnVersionOnly
38+
)
39+
40+
begin {
41+
}
42+
43+
process {
44+
try {
45+
# Retrieve the releases from the Codeberg API
46+
# Use TLS for connections
47+
Write-Verbose -Message "$($MyInvocation.MyCommand): Set TLS to 1.2."
48+
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
49+
50+
# Invoke the Codeberg releases REST API
51+
# Note that the API performs rate limiting.
52+
# https://docs.Codeberg.com/en/free-pro-team@latest/rest/reference/repos#get-the-latest-release
53+
$params = @{
54+
ContentType = "application/json"
55+
ErrorAction = "Stop"
56+
MaximumRedirection = 0
57+
DisableKeepAlive = $true
58+
UseBasicParsing = $true
59+
UserAgent = "codeberg-aaronparker-evergreen"
60+
Uri = $Uri
61+
}
62+
if (Test-ProxyEnv) {
63+
$params.Proxy = $script:EvergreenProxy
64+
}
65+
if (Test-ProxyEnv -Creds) {
66+
$params.ProxyCredential = $script:EvergreenProxyCreds
67+
}
68+
# # If Codeberg_TOKEN or GH_TOKEN exists, let's add that to the API request
69+
# if (Test-Path -Path "env:Codeberg_TOKEN") {
70+
# $params.Headers = @{ Authorization = "token $env:Codeberg_TOKEN" }
71+
# }
72+
# elseif (Test-Path -Path "env:GH_TOKEN") {
73+
# $params.Headers = @{ Authorization = "token $env:GH_TOKEN" }
74+
# }
75+
76+
# Output the parameters when using -Verbose
77+
foreach ($item in $params.GetEnumerator()) {
78+
Write-Verbose -Message "$($MyInvocation.MyCommand): Invoke-WebRequest parameter: $($item.name): $($item.value)."
79+
}
80+
81+
Write-Verbose -Message "$($MyInvocation.MyCommand): Get Codeberg release from: $Uri."
82+
$release = Invoke-RestMethod @params
83+
}
84+
catch {
85+
throw $_
86+
}
87+
88+
if ($null -eq $script:resourceStrings.Properties.Codeberg) {
89+
Write-Warning -Message "$($MyInvocation.MyCommand): Unable to validate release against Codeberg releases property object because we can't find the module resource."
90+
}
91+
else {
92+
# Validate that $release has the expected properties
93+
Write-Verbose -Message "$($MyInvocation.MyCommand): Validating Codeberg release object."
94+
foreach ($item in $release) {
95+
96+
# Compare the Codeberg release object with properties that we expect
97+
$params = @{
98+
ReferenceObject = $script:resourceStrings.Properties.Codeberg
99+
DifferenceObject = (Get-Member -InputObject $item -MemberType NoteProperty)
100+
PassThru = $true
101+
ErrorAction = "Continue"
102+
}
103+
$missingProperties = Compare-Object @params
104+
105+
# Throw an error for missing properties
106+
if ($null -ne $missingProperties) {
107+
Write-Verbose -Message "$($MyInvocation.MyCommand): Validated successfully."
108+
}
109+
else {
110+
Write-Verbose -Message "$($MyInvocation.MyCommand): Validation failed."
111+
$missingProperties | ForEach-Object {
112+
throw [System.Management.Automation.ValidationMetadataException]::New("$($MyInvocation.MyCommand): Property: '$_' missing")
113+
}
114+
}
115+
}
116+
}
117+
118+
# Build and array of the latest release and download URLs
119+
Write-Verbose -Message "$($MyInvocation.MyCommand): Found $($release.count) release/s."
120+
Write-Verbose -Message "$($MyInvocation.MyCommand): Found $($release.assets.count) asset/s."
121+
122+
if ($PSBoundParameters.ContainsKey("ReturnVersionOnly")) {
123+
if ($Uri -match "^*tags$") {
124+
try {
125+
# Uri matches tags fo the repo; find the latest tag
126+
$Version = [RegEx]::Match($release[0].name, $MatchVersion).Captures.Groups[1].Value
127+
}
128+
catch {
129+
Write-Verbose -Message "$($MyInvocation.MyCommand): Failed to match version number as-is, returning: $($release[0].$VersionTag)."
130+
$Version = $release[0].name
131+
}
132+
}
133+
else {
134+
try {
135+
# Uri matches releases for the repo; return just the version string
136+
$Version = [RegEx]::Match($release[0].$VersionTag, $MatchVersion).Captures.Groups[1].Value
137+
}
138+
catch {
139+
Write-Verbose -Message "$($MyInvocation.MyCommand): Failed to match version number as-is, returning: $($release[0].$VersionTag)."
140+
$Version = $item.$VersionTag
141+
}
142+
}
143+
144+
if ($PSBoundParameters.ContainsKey("VersionReplace")) {
145+
# Replace string in version
146+
$Version = $Version -replace $res.Get.VersionReplace[0], $res.Get.VersionReplace[1]
147+
}
148+
149+
# Build the output object
150+
$PSObject = [PSCustomObject] @{
151+
Version = $Version
152+
}
153+
Write-Output -InputObject $PSObject
154+
}
155+
else {
156+
foreach ($item in $release) {
157+
foreach ($asset in $item.assets) {
158+
159+
# Filter downloads by matching the RegEx in the manifest. The the RegEx may perform includes and excludes
160+
Write-Verbose -Message "$($MyInvocation.MyCommand): Match $Filter to $($asset.browser_download_url)."
161+
if ($asset.browser_download_url -match $Filter) {
162+
Write-Verbose -Message "$($MyInvocation.MyCommand): Building Windows release output object with: $($asset.browser_download_url)."
163+
164+
# Capture the version string from the specified release tag
165+
try {
166+
Write-Verbose -Message "$($MyInvocation.MyCommand): Matching version number against: $($item.$VersionTag)."
167+
$Version = [RegEx]::Match($item.$VersionTag, $MatchVersion).Captures.Groups[1].Value
168+
Write-Verbose -Message "$($MyInvocation.MyCommand): Found version number: $Version."
169+
}
170+
catch {
171+
Write-Verbose -Message "$($MyInvocation.MyCommand): Failed to match version number, returning: $($item.$VersionTag)."
172+
$Version = $item.$VersionTag
173+
}
174+
175+
if ($PSBoundParameters.ContainsKey("VersionReplace")) {
176+
# Replace string in version
177+
Write-Verbose -Message "$($MyInvocation.MyCommand): Replace $($res.Get.VersionReplace[0])."
178+
$Version = $Version -replace $res.Get.VersionReplace[0], $res.Get.VersionReplace[1]
179+
}
180+
181+
# Build the output object
182+
if ((Get-Platform -String $asset.browser_download_url) -eq "Windows") {
183+
$PSObject = [PSCustomObject] @{
184+
Version = $Version
185+
Date = ConvertTo-DateTime -DateTime $item.created_at -Pattern "MM/dd/yyyy HH:mm:ss"
186+
Size = $asset.size
187+
Architecture = Get-Architecture -String $(Split-Path -Path $asset.browser_download_url -Leaf)
188+
InstallerType = Get-InstallerType -String $asset.browser_download_url
189+
Type = [System.IO.Path]::GetExtension($asset.browser_download_url).Split(".")[-1]
190+
URI = $asset.browser_download_url
191+
}
192+
Write-Output -InputObject $PSObject
193+
}
194+
}
195+
else {
196+
Write-Verbose -Message "$($MyInvocation.MyCommand): Skip: $($asset.browser_download_url)."
197+
}
198+
}
199+
}
200+
}
201+
}
202+
}

0 commit comments

Comments
 (0)