Skip to content

Commit

Permalink
always use latest komac; minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
a-mnich committed May 11, 2024
1 parent 8545475 commit a62ccc1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
13 changes: 7 additions & 6 deletions Scripts/common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function Test-PackageAndVersionInGithub {
$ghVersionCheck = Invoke-WebRequest -Uri $ghVersionURL -Method Head -SkipHttpErrorCheck

if ($ghCheck.StatusCode -eq 404) {
Write-Host "Packet not yet in winget. Please add new Packet manually"
Write-Host "Package not yet in winget. Please add new package manually"
exit 1
}
elseif ($ghVersionCheck.StatusCode -eq 200) {
Expand Down Expand Up @@ -57,7 +57,7 @@ function Test-PackageAndVersionInWinget {
$foundMessage, $textVersion, $separator, $wingetVersions = winget search --id $wingetPackage --source winget --versions

if (!$wingetVersions) {
Write-Host "Packet not yet in winget. Please add new Packet manually"
Write-Host "Package not yet in winget. Please add new package manually"
exit 1
}
elseif ($wingetVersions.contains($latestVersion)) {
Expand Down Expand Up @@ -176,8 +176,8 @@ function Get-ProductVersionFromFile {
function Update-WingetPackage {
param(
[Parameter(Mandatory = $true)] [string] $WebsiteURL,
[Parameter(Mandatory = $false)] [string] $wingetPackage = ${Env:PackageName},
[Parameter(Mandatory = $false)][AllowEmptyString()] [ValidateSet("Komac", "WinGetCreate")] [string] $With = "Komac"
[Parameter(Mandatory = $false)] [string] $WingetPackage = ${Env:PackageName},
[Parameter(Mandatory = $false)][ValidateSet("Komac", "WinGetCreate")] [string] $With = "Komac"
)
$gitToken = Test-GitHubToken

Expand All @@ -204,7 +204,8 @@ function Update-WingetPackage {
Write-Host "Downloading $with and open PR for $wingetPackage Version $($Latest.Version)"
Switch ($with) {
"Komac" {
Invoke-WebRequest "https://github.com/russellbanks/Komac/releases/download/v2.2.1/KomacPortable-x64.exe" -OutFile komac.exe
$latestKomacRelease = (Invoke-RestMethod -Uri "https://api.github.com/repos/russellbanks/Komac/releases/latest").assets | ? {$_.browser_download_url.EndsWith("KomacSetup-x64.exe")} | Select-Object -First 1 -ExpandProperty browser_download_url
Invoke-WebRequest -Uri $latestKomacRelease -OutFile komac.exe
.\komac.exe update --identifier $wingetPackage --version $Latest.Version --urls "$($Latest.URLs.replace(' ','" "'))" -s -t $gitToken
}
"WinGetCreate" {
Expand Down Expand Up @@ -249,7 +250,7 @@ function Get-LatestMongoDBVersions {
# $url = ${Env:WebsiteURL}
# $Latest = Get-VersionAndUrl -wingetPackage $wingetPackage -WebsiteURL $url

# Update-WingetPackage -wingetPackage $wingetPackage -latestVersion $Latest.Version -with Komac -latestVersionUrls $Latest.URLs
# Update-WingetPackage -WingetPackage $wingetPackage -latestVersion $Latest.Version -with Komac -latestVersionUrls $Latest.URLs
# }


Expand Down
11 changes: 6 additions & 5 deletions Scripts/generic.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
. .\Scripts\common.ps1

#### Main

if (${Env:With}) {
Update-WingetPackage -wingetPackage ${Env:PackageName} -With ${Env:With} -WebsiteURL ${Env:WebsiteURL}
$params = @{
wingetPackage = ${Env:PackageName}
WebsiteURL = ${Env:WebsiteURL}
}
else {
Update-WingetPackage -wingetPackage ${Env:PackageName} -WebsiteURL ${Env:WebsiteURL}
if($Env:With) {
$params.Add("With", $Env:With)
}

Update-WingetPackage @params

0 comments on commit a62ccc1

Please sign in to comment.