Skip to content

Commit

Permalink
refactor(check.ps1): improve readability and enhance output formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
xrgzs committed Oct 15, 2024
1 parent 15c8474 commit ea67f89
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions .github/workflows/check.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,50 @@ param (
[switch]$DatabaseOnly
)


$ErrorActionPreference = 'Stop'

function Request-Update {
param (
[string]
$Category
)

$match = ((Invoke-WebRequest -Uri "https://uupdump.net/known.php?q=category:$Category").Links | Where-Object {$_.href -like "selectlang.php?id=*"} | Where-Object {$_.outerHTML -like "*amd64*"})[0].outerHTML -match '\((\S+)\)'


$match = ((Invoke-WebRequest -Uri "https://uupdump.net/known.php?q=category:$Category").Links |
Where-Object { $_.href -like "selectlang.php?id=*" } |
Where-Object { $_.outerHTML -like "*amd64*" })[0].outerHTML -match '\((\S+)\)'

if ($match) {
$LatestVersion = $Matches[1]
Write-Host "The latest version of $Category is $LatestVersion"
Write-Host -ForegroundColor Green "The latest version of $Category is $LatestVersion"
return $LatestVersion
} else {
Write-Error "Failed to get the latest version"
Write-Host -ForegroundColor Red "Failed to get the latest version"
}
}


$StatePath = Join-Path $PSScriptRoot '..' '..' 'State.json' -Resolve

$CurrentState = Get-Content -Path $StatePath | ConvertFrom-Json

foreach ($Category in $CurrentState.PSObject.Properties.Name) {
$CurrentVersion = $CurrentState.$Category.Version
Write-Host "Current version of $Category is $CurrentVersion"
Write-Host -ForegroundColor Yellow "Current version of $Category is $CurrentVersion"
$LatestVersion = Request-Update -Category $Category

if ($LatestVersion -ne $CurrentVersion) {
Write-Host "New version of $Category is available: $LatestVersion"
Write-Host -ForegroundColor Green "New version of $Category is available: $LatestVersion"
$CurrentState.$Category.Version = $LatestVersion

$scriptBlock = [scriptblock]::Create($CurrentState.$Category.Commands -join "`n")

if (!$DatabaseOnly) {
Write-Host "Executing commands for $Category ..."
Write-Host $scriptBlock
Write-Host -ForegroundColor Green "Executing commands for $Category ..."
Write-Host -ForegroundColor Yellow $scriptBlock
. $scriptBlock
}
} else {
Write-Host "No new version of $Category is available"
Write-Host -ForegroundColor Yellow "No new version of $Category is available"
}
}

$CurrentState | ConvertTo-Json | Set-Content -Path $StatePath
$CurrentState | ConvertTo-Json | Set-Content -Path $StatePath

0 comments on commit ea67f89

Please sign in to comment.