cache icon indicating copy to clipboard operation
cache copied to clipboard

`cache-hit` undefined on cache miss?

Open aryairani opened this issue 1 year ago • 4 comments

The README says:

Note cache-hit will only be set to true when a cache hit occurs for the exact key match. For a partial key match via restore-keys or a cache miss, it will be set to false.

but outputs.cache-hit == 'false' doesn't seem to be true when I get a cache miss, and I noticed that the examples all use != 'true', not == 'false'.

I think here we can see restoreImpl return early on a miss, without setting any value for cache-hit at all. I'm not a TypeScript or Actions expert though.

In the meantime, I'll switch my == 'false' to != 'true' but I feel dirty. :)

aryairani avatar Feb 23 '24 02:02 aryairani

This problem does not seem to occur in v3, only in v4. In fact, the repositories that had been delayed updating to v4 were working fine. In workflows that saving the cache when outputs.cache-hit == 'false', the cache was no longer being saved. I recognized this too late because it simply skips a step and does not result in an error. Is this a bug? Or is it a breaking change?

pddg avatar Apr 16 '24 09:04 pddg

I'm seeing a potentially related problem, where our steps that have if: ${{ steps.cache.outputs.cache-hit != 'true' }} now always get executed since the switch to v4. With v3, they used to be properly skipped on a cache hit, but I have not seen them skipped a single time since then.

EDIT: Never mind, I was just not patient enough and caches don't seem to always propagate instantly.

RalfJung avatar May 03 '24 18:05 RalfJung

@RalfJung: I was going to say don't use if: ${{ steps.cache.outputs.cache-hit != 'true' }} because that's a string that will always evaluate to true, not a boolean expression, and that you should use if: steps.cache.outputs.cache-hit != 'true' instead.

But if it eventually worked for you, then I have no idea how anything works.

aryairani avatar May 03 '24 19:05 aryairani

It looks like there are document revisions in progress related to this issue. https://github.com/actions/cache/pull/1263

no-yan avatar May 04 '24 04:05 no-yan