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

do not attempt to delete existing cache #1183

Closed
wants to merge 4 commits into from

Conversation

ericLemanissier
Copy link

@ericLemanissier ericLemanissier commented Oct 16, 2024

Description:
I don't think it's necessary to delete existing cache before overwriting it. https://github.com/actions/cache does not seem to do it. The problem with deleting a cache entry is that it requires to give actions: write permissions, which means the workflow has all these permissions and this is way too much, and not acceptable for a lot of projects.

Also, do not check if cache exists during restore. It introduces a TOCTOU issue, and is not needed because restoreCache returns undefined if the cache does not exist, cf https://github.com/actions/toolkit/tree/main/packages/cache

Related issue:
fixes #1159
fixes #1133
fixes #1131

Check list:

  • Mark if documentation changes are required.
  • Mark if tests were added or updated to cover the changes.

Sorry, something went wrong.

@ericLemanissier ericLemanissier marked this pull request as ready for review October 16, 2024 13:14
@ericLemanissier ericLemanissier requested a review from a team as a code owner October 16, 2024 13:14
It introduces a TOCTOU issue, and is not needed because `restoreCache` returns `undefined` if the cache does not exist
https://github.com/actions/toolkit/tree/main/packages/cache
@ericLemanissier
Copy link
Author

CI results available in https://github.com/ericLemanissier/stale/pull/21/checks

@ericLemanissier
Copy link
Author

@suyashgaonkar what do you think of this change ?

@ericLemanissier
Copy link
Author

@aparnajyothi-y @suyashgaonkar what to you think of this change ?

@ericLemanissier ericLemanissier marked this pull request as draft February 24, 2025 07:11
@ericLemanissier
Copy link
Author

well, it looks like caches are actually immutable.
https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/storing-and-sharing-data-from-a-workflow indicates Use caching when you want to reuse files that don't change often between jobs or workflow runs, so it seems to me that github cache is not the proper solution for storage of stale state, because it changes at each run.
Why not use actions/upload-artifact to save the state, then

- uses: actions/download-artifact@v4
  with:
    run-id: ${{ github.run_id -1 }}

@ericLemanissier ericLemanissier deleted the patch-2 branch February 25, 2025 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant