From ea67f8974ef67e1b804aa2adf3f21355580a1dc8 Mon Sep 17 00:00:00 2001 From: xrgzs Date: Tue, 15 Oct 2024 12:51:06 +0800 Subject: [PATCH] refactor(check.ps1): improve readability and enhance output formatting --- .github/workflows/check.ps1 | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) 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