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

Provide a richer API in actions/cache for sophisticated caching use cases #1157

Open
bigdaz opened this issue Aug 17, 2022 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@bigdaz
Copy link

bigdaz commented Aug 17, 2022

The gradle-build-action is effectively a setup-gradle action that takes care of caching and other setup for the Gradle build tool. This action is quite sophisticated in it's use of the @actions/cache library, extracting multiple cache entries out of the Gradle User Home and providing a detailed report of each entry saved/restored (including the entry size). See here for an example (expand the 'cache entry details' section).

To provide this functionality we are using a patched version of the @actons/cache library, due to some limitations in the main implementation:

  • We added a rich response object to cache save/restore, instead of simply returning the cache key. This response object includes the total size of the entry saved/restored, and allows us to report on the total size of cache entries in total and individually.
  • When the @actions/cache library recently started to log and swallow any errors that occur during save/restore, we had to undo this change via a npm patch. While swallowing exceptions might be useful for basic uses of the library, it limits our ability to report to users when a save/restore was successful or failed. In addition, the library logs warnings that lack the context that can be added by our action implementation.

Describe the enhancement

I propose that @actions/cache provide a parallel API to saveCache and restoreCache, but that this API be aimed at programmatic users of the cache infrastructure.

Features of this API would be:

  • Return value from these functions would be an object containing important information about the action
    • For restoreCache, at least the key and size of downloaded entry
      • Optionally, the ID, github_ref, URL and creation date
    • For saveCache, at least the cacheId and size of uploaded entry
      • Optionally, the key, github_ref and URL of the saved entry
  • No implicit logging/warning of cache errors: these will be passed to the caller
    • Allow errors to propagate to caller
    • OR Add error information to return object

Code Snippet
Here is an example calling a modified restoreCache function, reporting on the size of the entry and any errors: https://github.com/gradle/gradle-build-action/blob/main/src/cache-utils.ts#L155-L167
Here is an example calling a modified saveCache function, reporting on the size of the upload and contextualizing any errors: https://github.com/gradle/gradle-build-action/blob/main/src/cache-utils.ts#L171-L181

Additional information
@kotewar @tiwarishub I'd be happy to work on a PR to provide this functionality if it's likely to be accepted.

@bigdaz bigdaz added the enhancement New feature or request label Aug 17, 2022
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

1 participant