gradle / gradle-build-action

Execute your Gradle build and trigger dependency submission
https://github.com/marketplace/actions/gradle-build-action
MIT License
671 stars 97 forks source link

[FEATURE REQUEST] custom cache name #947

Closed dimaslanjaka closed 10 months ago

dimaslanjaka commented 11 months ago

please add option cache name. prevent too many cache generated each commits, which currently github limiting cache sizes and total each repository.

bigdaz commented 11 months ago

I don't really understand what you're asking. Are you suggesting that a custom cache name could prevent caches growing too large?

There is a lot of information about caching documented here: https://github.com/gradle/gradle-build-action#caching-build-state-between-jobs

dimaslanjaka commented 11 months ago

I don't really understand what you're asking. Are you suggesting that a custom cache name could prevent caches growing too large?

There is a lot of information about caching documented here: https://github.com/gradle/gradle-build-action#caching-build-state-between-jobs

cache name start with v8 there too many caches with it. wait, ill re-run my previous ci to reproduce the caches. i was cleaned them and disabling gradle-build-action from my workflow yml config

dimaslanjaka commented 11 months ago

I don't really understand what you're asking. Are you suggesting that a custom cache name could prevent caches growing too large?

There is a lot of information about caching documented here: https://github.com/gradle/gradle-build-action#caching-build-state-between-jobs

image

dimaslanjaka commented 11 months ago

add custom cache name to prevent duplicate caches each commit like this image

bigdaz commented 10 months ago

Unfortunately that won't work. Each GitHub Actions cache entry is immutable, so we cannot use a fixed name and update the contents. Instead, each time the entry contents change, it is uploaded with a different name.

BUT, you'll notice that those "duplicated" entries are quite small. We extract common things like dependencies and wrapper zips so that they will be cached once and reused until the underlying contents change.

dimaslanjaka commented 10 months ago

now iam using actions/cache to solve gradle caching system https://github.com/dimaslanjaka/android-traffic-exchange/blob/a3ba8c74008206a404511b563b4dd482326345e0/.github/workflows/android.yml#L57-L75

then add jvm arg --gradle-user-home to rootProject/.gradle https://github.com/dimaslanjaka/android-traffic-exchange/blob/a3ba8c74008206a404511b563b4dd482326345e0/.github/workflows/android.yml#L107-L118

The result all downloaded jars, build cache, etc in rootProject/.gradle

and the build with cache task working like charm

image

bigdaz commented 10 months ago

now iam using actions/cache to solve gradle caching system https://github.com/dimaslanjaka/android-traffic-exchange/blob/a3ba8c74008206a404511b563b4dd482326345e0/.github/workflows/android.yml#L57-L75

You are using a fixed cache key. From my understanding the cache entry for this key will be written ONCE ONLY and will never be updated. So over time this cache entry will be become more and more out of date, and less useful.

From the cache documentation:

You cannot change the contents of an existing cache. Instead, you can create a new cache with a new key.

dimaslanjaka commented 10 months ago

now iam using actions/cache to solve gradle caching system https://github.com/dimaslanjaka/android-traffic-exchange/blob/a3ba8c74008206a404511b563b4dd482326345e0/.github/workflows/android.yml#L57-L75

You are using a fixed cache key. From my understanding the cache entry for this key will be written ONCE ONLY and will never be updated. So over time this cache entry will be become more and more out of date, and less useful.

From the cache documentation:

You cannot change the contents of an existing cache. Instead, you can create a new cache with a new key.

yeah but not created new cache every push. it will make my github account experience limited github actions (spending limits) because the total cache exceeds the 10GB limit. and all unused caches will auto deleted after 7 days.