-
-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Will not delete old versions with max-versions-to-keep set to 1, if only 1 version exists. #307
Comments
Hi, I checked the latest code, and it seems to be working correctly. I think this is/might be a bug in v2, which does not use the code you've mentioned. Can you do a run with main branch and tell if it works or not? |
I will report when I have an update to post. There was a problem with v2, but this is code from the main branch, which is why I mentioned it. I was checking it before doing an update. |
Just pushed an update, it failed to delete the previous version. https://github.com/maforget/ComicRackCE/actions/runs/11308262081/job/31450951821#step:3:200 Run # delete previous versions w.r.t. max-versions-to-keep (if any)
# delete previous versions w.r.t. max-versions-to-keep (if any)
$ToNatural = { [regex]::Replace($_, '\d+', { $args[0].Value.PadLeft(20) }) }
$Versions = komac list-versions 'maforget.ComicRackCE.Nightly' --json | ConvertFrom-Json | Sort-Object $ToNatural -Descending
$Reason = 'This version is older than what has been set in `max-versions-to-keep` by the publisher.'
If ($Versions.Count + 1 -gt 1) {
$VersionsToDelete = $Versions[(1 - 1)..($Versions.Count - 1)]
Write-Output "Versions to delete: $($VersionsToDelete -join ', ')"
ForEach ($Version in $VersionsToDelete) {
Write-Output "Deleting version: $Version"
komac remove 'maforget.ComicRackCE.Nightly' --version $Version --reason "$Reason" --submit
}
} Else {
Write-Output "No versions to delete. All good :)"
}
shell: /usr/bin/pwsh -command ". '{0}'"
env:
KOMAC_FORK_OWNER: maforget
KOMAC_CREATED_WITH: WinGet Releaser
KOMAC_CREATED_WITH_URL: https://github.com/vedantmgoyal9/winget-releaser
GITHUB_TOKEN: ***
Versions to delete: n
Deleting version: n
Packages should only be removed when necessary
Error:
0: maforget.ComicRackCE.Nightly version n does not exist in microsoft/winget-pkgs
Error: Process completed with exit code 1. |
And as I predicted on the following build, it deleted both remaining versions correctly. When more than 1 version exists it works correctly, but not when there is only one. |
@all-contributors please add @maforget for bug |
I've put up a pull request to add @maforget! 🎉 |
Is there an existing issue for this?
What happened?
First I am new to winget and still unsure about a couple of things. I was kind of forced to learn it, because someone submitted my program to it, without thinking that it would break the moment I made a new build and the installer checksum would change and not install anymore.
A contributor from the winget team did a PR to implement your action to my workflow to help automate things. They had put the max-versions-to-keep to 5. But since I am using a single url for a nightly version, keeping any other version than the last one is worthless since they would all point to the same link and any other would fail.
I also am using the commit sha as a version number, so I wanted to keep only 1 version to make sure that it would upgrade correctly (not certain about that one still).
When I ran my latest build it only deleted the oldest one and not both version that were already in the winget repo, I see now that it was ran on v2, and you stated to use main instead. I've changed that for the future.
But I was looking at your latest code to make sure and I believe I spotted a possible bug.
winget-releaser/action.yml
Lines 96 to 98 in b87a066
Say that I have
max-versions-to-keep = 1
and I have 2 versions already in the repo (I assume that$Versions.Count
would not include the just created manifest). Then$VersionsToDelete = $Versions[0..1)]
, which would return both versions correctly removing both and keeping only the latest just created one.But then the build after I would have only 1 version so it would result in
$VersionsToDelete = $Versions[0..0)]
, which would return nothing and so delete nothing. So I would end up with 2 versions. Then on the subsequent run it would delete both and keep the latest, then 2, etc.At least that is what I get when I test it in my powershell environment, not certain about running it via actions. Not going to test it out without any reasons.
So maybe it would be better to have something like (test code):
Please correct me if there is a reason or if I am mistaking anywhere.
The text was updated successfully, but these errors were encountered: