Skip to content

Commit

Permalink
fix highest version check in cleanup script
Browse files Browse the repository at this point in the history
  • Loading branch information
a-mnich committed Oct 6, 2024
1 parent 95e2f7c commit 31ea058
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
manifests/
Tests
scripts/package-cleanup/broken_packages.csv
scripts/package-cleanup/broken_packages.csv
scripts/package-cleanup/cleaned_packages.csv
15 changes: 14 additions & 1 deletion scripts/package-cleanup/Remove-BrokenPackages.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ else {
# get current script directory
$scriptDirectory = Split-Path -Parent $MyInvocation.MyCommand.Definition

if ([string]::IsNullOrEmpty($scriptDirectory)) {
Write-Host "Failed to get script directory. Falling back to current directory"
$scriptDirectory = (Get-Location).Path
}

# get files that start with naming "Broken Packages-data-"
$brokenPackagesFiles = Get-ChildItem -Path $scriptDirectory -Filter "Broken Packages-data-*" | Sort-Object -Property LastWriteTime -Descending
if ($brokenPackagesFiles.Count -eq 0) {
Expand All @@ -38,6 +43,12 @@ foreach ($package in $packages) {
write-host "Ignoring package $($package.package_identifier) | $($package.package_version)"
continue
}
# check if it is already in cleaned_packages.csv
$cleanedPackages = Import-Csv -Path $scriptDirectory\cleaned_packages.csv
if ($cleanedPackages | Where-Object { $_.package_identifier -eq $package.package_identifier -and $_.package_version -eq $package.package_version }) {
Write-Host "Ignoring package $($package.package_identifier) | $($package.package_version) as it is already cleaned"
continue
}

Write-Host "Checking package $($package.package_identifier) | $($package.package_version)"
$output = & winget.exe download --id $package.package_identifier --version $package.package_version
Expand All @@ -62,7 +73,7 @@ foreach ($package in $packages) {
Write-Host "Package $($package.package_identifier) | $($package.package_version) | Failed to download"

$ExistingPRs = gh pr list --search "Remove version: $($package.package_identifier) version $($package.package_version) in:title draft:false" --state 'all' --json 'title,url' --repo 'microsoft/winget-pkgs' | ConvertFrom-Json
$isHighestVersion = (& winget.exe search --id $package.package_identifier --exact ) -contains $package.package_version
$isHighestVersion = ((Find-WinGetPackage -Id $package.package_identifier) | Where-Object { $_.Version -eq $package.package_version -and $_.Id -eq $package.package_identifier }).Count -gt 0

if ($isHighestVersion -eq $true -and $REMOVE_HIGHEST_VERSIONS -eq $false) {
Write-Host "Ignoring package $($package.package_identifier) | $($package.package_version) as it is the highest version"
Expand All @@ -89,6 +100,8 @@ foreach ($package in $packages) {
$prBody = "installers return following HTTP status code: $($package.http_codes)"
}
. komac.exe remove --reason $prBody --submit -v $package.package_version $package.package_identifier
# add it to cleaned_packages.csv
$package | Export-Csv -Path $scriptDirectory\cleaned_packages.csv -Append -NoTypeInformation
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions scripts/package-cleanup/ignored_packages.csv
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Adobe.CreativeCloud,*
Baidu.BaiduSIAssistant,*
Baidu.BaiduSIMeeting,*
Baidu.BaiduTranslate,*
Baidu.BaiduSIAssistan,*
Baidu.TeraBox,*
Betterbird.Betterbird,*
BranchBlocks.Branch,1.1
Codemao.Lessons,3.5.0
Expand All @@ -17,3 +19,5 @@ GloopProgramming.Gloop,*
Codemao.kitten.4,*
Ocenaudio.Ocenaudio,*
wiznote.*,*
OutsourcedGuru.octopi-init,*

0 comments on commit 31ea058

Please sign in to comment.