Disable cache-to for pull requests
Hi,
I would like to disable cache publishing for pull requests, something like:
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
cache-from: type=gha
cache-to: type=gha,mode=max,enable=${{ github.event_name == 'push' }}
But enable flags aren't apparently supported for cache-to according to the docs.
Is there any chance it can be supported?
Is there any chance it can be supported?
I don't think we are going to add this kind of attribute but I'm curious about your use case to disable cache on PR?
I have a project that produces big images, and I would not like PRs to consume all the cache quota from merged commits. If they do, they would start deleting the cache from merged commits which means later PRs won't have cache to consume from.
I'm running into the same issue, PR's are producing several layers combined +1GB which is taking all the Cache quota
@felipecrs Have you found a solution for this yet?
One dumb thing you can do is to repeat the build-push-action call, but add if conditions to both to ensure one will run for pull requests and another for push or the rest.
@felipecrs Clever, I will use that in the meantime!
The expressions return the truthy value. Caching-to is disabled when it's empty.
Expression example executed in a JavaScript console:
>> true && 'type=gha,mode=max' || ''
<< "type=gha,mode=max"
>> false && 'type=gha,mode=max' || ''
<< ""
So the following yml works. I use something similar.
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
cache-from: type=gha
cache-to: ${{ github.event_name == 'push' && 'type=gha,mode=max' || '' }}