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

Delete all caches or support bulk cache deletion using filters #20

Open
RSickenberg opened this issue Jul 29, 2022 · 11 comments
Open

Delete all caches or support bulk cache deletion using filters #20

RSickenberg opened this issue Jul 29, 2022 · 11 comments
Labels
enhancement New feature or request

Comments

@RSickenberg
Copy link

Describe the feature or problem you’d like to solve

It would be cool to add a flag if we want to delete all cache from a repo or with some filters like older than x, bigger than x, and so on.

Proposed solution

The solution would help to gain time between the list command and the delete command.

Regards :)

@RSickenberg RSickenberg added the enhancement New feature or request label Jul 29, 2022
@kotewar kotewar self-assigned this Jul 30, 2022
@kotewar
Copy link
Contributor

kotewar commented Aug 1, 2022

Hi @RSickenberg 👋🏽

Thank you for your wonderful suggestion! :)

Currently we are planning for some enhancements on the current CLI on making it better and I've added your suggestion in list. We will prioritise based on the urgent needs and feedback from other users.

In the meantime, in case you wish to contribute, please feel free to raise a Pull Request for your suggested feature and we will be happy to review the same.

Thanks! :)

@tbenthompson
Copy link

In case it's useful to anyone, I was able to do this with this snippet:

gh actions-cache list --limit 100 | tail -n +5 | awk '{print $1}' | tr '\n' '\0' | xargs -0 -n1 gh actions-cache delete --confirm

Unfortunately, it's kinda slow. Took a couple minutes to delete 250 cache entries.

@tpak
Copy link

tpak commented Jan 30, 2023

Any update @kotewar?

I'd love to see this progress soon. My use case is that I would like to delete the cache on working branches if they are older than x days - thus leaving them in place for working branches until after they merge. Still, I need to leave them in case the branch gets changed after an initial merge to a protected branch such as staging or main.

So I really need to be able to filer by x hours/days and also filter by "branch != main, staging, other-protected-branches." - this does not need to be branches that are listed under branch protection rules per se, I am fine with specifying them in the workflow. if I had this, I think I could get all branches older than X days. Then I could filter out the ones that have my protected branch names with a pipe to grep and a well-crafted regex. But it would also be great to have a negative filter on branch name(s) as well. I don't see an issue that asks for that but is it in your work plan? If not, I can open an issue (or point me to one and I will comment/upvote it)

The concept is this "get rid of all branches older than X that are not on branches main, staging, XYZ" and without having to get into scripting, etc.

@kotewar
Copy link
Contributor

kotewar commented Jan 31, 2023

Hey @tpak, 👋🏽

Unfortunately no update yet. This kind of functionality needs support from the backend side and we don't have any APIs in place yet that support bulk deletion of caches which can make this faster than the alternative suggested above.

I'll add this request in our backlog so that we can support bulk deletion of caches given the filters.

@kotewar kotewar changed the title Delete all or older than x hours Delete all caches or caches older than x hours Jan 31, 2023
@kotewar kotewar changed the title Delete all caches or caches older than x hours Delete all caches or support bulk cache deletion using filters Jan 31, 2023
@tpak
Copy link

tpak commented Jan 31, 2023

Thanks for the update @kotewar

I guess I need bulk delete but as I re-read it, I'm seeking to filter better on dates both for list and delete operations.

Unfortunately, as it currently stands there is no filtering capability for the list or delete operations. For delete, it would translate as "bulk" but for list it would materialize as a filter. The return from list operations
"-d627a4016d488c214... 149.16 MB refs/heads/staging 16 hours ago"
is not great to work with since it switches to " 1 days ago" after 24 hours. The solution above suggested by @tbenthompson does not filter although can be cleverly piped to another awk or grep step with regex.

I'll re-read existing issues and maybe open a new one for list filters

@tpak tpak mentioned this issue Jan 31, 2023
@kotewar
Copy link
Contributor

kotewar commented Feb 1, 2023

@tpak , list capability does support filtering by cache name, branch and sorting by last-used, size, created-at. You can provide filters with the list command as shown in the documentation.

Although I understand what you are trying to refer here. I went through your recently created issues #51 and #52. We will add these to our backlog.

@tpak
Copy link

tpak commented Feb 1, 2023

Thanks @kotewar. Yes, I am aware of the current filter and sort options, but unfortunately, as outlined in 51 and 52, the current filter and sort capabilities are not quite up to the task at hand. Those will make great upgrades.

@kotewar kotewar removed their assignment May 5, 2023
@arminrosu
Copy link

For anyone stumbling on the same issue, another option to gh actions-cache by tbenthompson (which requires gh extension install actions/gh-actions-cache), you can also use the built-in gh cache list.

@rosshettel
Copy link

I came across this issue while looking how to delete all caches, didn't see it mentioned here but the github cli now supports this via:

gh cache delete --all

@aliberts
Copy link

aliberts commented Nov 28, 2023

I had the same problem as OP and came up with the following command to delete cache entries that have not been accessed after a certain date:

gh cache list -R OWNER/REPO | awk '$5 < "2023-11-28"' | cut -f2 | xargs -I {} gh cache delete -R OWNER/REPO {}

You can even set the following alias which is more handy:

gh alias set --shell 'cache prune' 'gh cache list -R "$1" | awk -v date="$2" '\''$5 < date'\'' | cut -f2 | xargs -I {} gh cache delete -R "$1" {}'

Then run the command with :

gh cache prune OWNER/REPO 2023-11-28

This also works with time:

gh cache prune OWNER/REPO 2023-11-28T12:00

This last example will delete cache objects last accessed before Nov. 28 2023 at 12:00 (UTC) on the given repo.

Note that I use the last access date but if you want to filter on the cache object creation date you can just replace $5 with $4 in these commands.

Hope this helps!

@davseve
Copy link

davseve commented Apr 15, 2024

In continue to @tbenthompson suggestion, I used the following snippet to delete cache files that contain certain keywords:
gh cache list --limit 100 | grep "keyword" | awk '{print $1}' | xargs -I {} gh cache delete {}

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

No branches or pull requests

10 participants