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 cache entries only on the workflow branch #97

Merged
merged 9 commits into from
Jan 15, 2024

Conversation

omus
Copy link
Collaborator

@omus omus commented Jan 12, 2024

I've noticed that the post-action step which automatically cleans up old cache entries accidentally cleans up entries created on other branches. This reduces performance with multiple PRs are being developed concurrently especially in the scenario where a PR deletes the cache entry for the main branch resulting in all new PRs having cache misses until a PR has been merged.

This PR updates the handle_caches.jl script to only delete caches which match the restore key using the same git ref as the executing workflow. This should result in workflows run on the main branch only deleting cache entries on main and PRs only deleting cache entries for that PR.

For more details about cache isolation in regards to branches see: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache

@omus omus changed the title Delete cache entries on the workflow branch Delete cache entries only on the workflow branch Jan 12, 2024
@omus omus marked this pull request as ready for review January 12, 2024 23:38
Copy link
Member

@IanButterworth IanButterworth left a comment

Choose a reason for hiding this comment

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

Sounds great. Makes sense

cache-name: ${{ needs.generate-key.outputs.cache-name }}
cache-name: ${{ needs.generate-key.outputs.cache-name }}-matrix
# Cannot require a successful cache delete on forked PRs as the permissions for actions is limited to read
delete-old-caches: ${{ github.event.pull_request.head.repo.full_name != 'julia-actions/cache' && 'false' || 'required' }}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

GitHub does allow repo administrators to allow
fork PRs to have write permissions: https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs#changing-the-permissions-in-a-forked-repository. I think it's best to leave things as is but it's good to know this is an option

@omus
Copy link
Collaborator Author

omus commented Jan 13, 2024

I'll hold off on merging until I triple check the non-fork version is working. Also, this may be a nicer way to detect a fork: https://github.com/orgs/community/discussions/25217#discussioncomment-3246904

@IanButterworth
Copy link
Member

I think this fixes #98.

Probably good to add 1.0 CI as these actions should probably work back to there, if possible.

@omus omus mentioned this pull request Jan 15, 2024
@omus
Copy link
Collaborator Author

omus commented Jan 15, 2024

I think this fixes #98.

Probably good to add 1.0 CI as these actions should probably work back to there, if possible.

I'll save this for another PR as there are a few additional changes required to get this to work

@omus omus merged commit 0c5d92d into julia-actions:main Jan 15, 2024
9 checks passed
@omus omus deleted the cv/delete-caches-only-on-branch branch January 15, 2024 16:15
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.

2 participants