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 save-if option for conditional cache saving #21

Merged
merged 7 commits into from
Jul 20, 2024
Merged

Conversation

TimJentzsch
Copy link
Collaborator

@TimJentzsch TimJentzsch commented Jul 20, 2024

Objective

Closes #20.

Sometimes you don't always want to save the new cache, but only restore from existing caches.
This might be necessary if the repository is very active and always hits the cache size limit.

For example, you might only want to save the cache on the main branch and reuse it across all branches.

See also bevyengine/bevy#13040.

Solution

Add a save-if option, allowing you to specify when the cache should be saved.
Defaults to true.

Unfortunately, the cache action does not provide a save-if option, so we need to conditionally use cache/restore instead.

Internally, we add a new job step to determine the cache paths, key and fallbacks such that we can reuse them consistently.
This turned out to be more difficult to get working than to just copy and paste everything, we will just have to be careful to keep the values in sync.

@TimJentzsch TimJentzsch added the enhancement New feature or request label Jul 20, 2024
@TimJentzsch
Copy link
Collaborator Author

Tested and confirmed to be working (after a lot of bugfixing).
A setup like this:

uses: Leafwing-Studios/cargo-cache@b46a3eb6f97357ee4bada528857bfff77d08b964
        with:
          save-if: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }}

Makes it possible to save the cache only on the default branch.

@TimJentzsch TimJentzsch marked this pull request as ready for review July 20, 2024 19:57
@alice-i-cecile alice-i-cecile merged commit 6c2a159 into main Jul 20, 2024
@alice-i-cecile alice-i-cecile deleted the 20-save-if branch July 20, 2024 20:53
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

Successfully merging this pull request may close these issues.

Add save-if option
3 participants