Skip to content
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

Add a dry-run flag #62

Merged
merged 2 commits into from
May 4, 2023
Merged

Add a dry-run flag #62

merged 2 commits into from
May 4, 2023

Conversation

jmichalicek
Copy link
Contributor

This adds a simple dry-run flag to allow for testing to easily see what would be deleted. The check for a dry run and skip of actual removal could be done even later/deeper in, but this was a very easy and clear place to put it. The image is added to the deleted list to follow what would happen as closely as possible, but I would be happy to remove that if desired since the image was not actually deleted.

@codecov
Copy link

codecov bot commented May 2, 2023

Codecov Report

Merging #62 (7c3662e) into main (23af218) will increase coverage by 0.12%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main      #62      +/-   ##
==========================================
+ Coverage   93.15%   93.27%   +0.12%     
==========================================
  Files           1        1              
  Lines         219      223       +4     
  Branches       53       54       +1     
==========================================
+ Hits          204      208       +4     
  Misses          7        7              
  Partials        8        8              
Impacted Files Coverage Δ
main.py 93.27% <100.00%> (+0.12%) ⬆️

Copy link
Member

@sondrelg sondrelg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, and happy to add this 🎉 Just have one initial question

main.py Outdated
delete_image = False
image_name_with_tag = f'{image_name}:{version.id}'
print(f'Would delete image {image_name_with_tag}.')
deleted.append(image_name_with_tag)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this append? Could we not just skip this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sondrelg yep, happy to remove that. That was what I was commenting on in the initial PR comments with The image is added to the deleted list to follow what would happen as closely as possible, but I would be happy to remove that if desired since the image was not actually deleted.

I'll pull that out this evening.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, trying to review between other tasks, so just didn't have the time to look at whether there was a benefit. If there is, I'm open to keeping it 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, I didn't manage to find the 2 seconds to pull it out last night either. The goal was to have the same data in place at the end of the run as what would have happened if the images really had been deleted.

That seems useful to me, but I can definitely see the reasoning to remove that line because the image wasn't really deleted and so to not have to maintain doing that in two places, though. I could also throw a quick comment before that line explaining why it's being done. Whatever your preference is, I'm happy to go with

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the list is used here to output which images were actually deleted, I suggest we remove it 👍 Could be misleading otherwise I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@sondrelg
Copy link
Member

sondrelg commented May 4, 2023

I don't have any images hosted on ghcr anymore, so I can't really test this on any of my own projects. Would you mind doing a quick test run with:

uses: jmichalicek/container-retention-policy@add-dry-run

..in your workflow?

It's hopefully redundant, but seems worth the extra 5 minutes to save everyone else broken workflows.

@sondrelg
Copy link
Member

sondrelg commented May 4, 2023

Happy to merge this after that 👍

@jmichalicek
Copy link
Contributor Author

uses: jmichalicek/container-retention-policy@add-dry-run

No problem
https://github.com/jmichalicek/container-retention-policy/actions/runs/4884897747
https://github.com/jmichalicek/container-retention-policy/actions/runs/4884897747/workflow#L69

I'm also using my fork and branch for now for a project at work, but that is of course all private repos.

@sondrelg sondrelg merged commit f617f1c into snok:main May 4, 2023
@sondrelg
Copy link
Member

sondrelg commented May 4, 2023

Thanks @jmichalicek!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants