diff --git a/.github/workflows/check.ps1 b/.github/workflows/check.ps1 index f8049b9..92e7fff 100644 --- a/.github/workflows/check.ps1 +++ b/.github/workflows/check.ps1 @@ -2,7 +2,6 @@ param ( [switch]$DatabaseOnly ) - $ErrorActionPreference = 'Stop' function Request-Update { @@ -10,42 +9,43 @@ function Request-Update { [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 \ No newline at end of file