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

Cache-Hit set to string, not boolean, as of v4.1.0 #1466

Closed
bigdogwillfeed opened this issue Oct 7, 2024 · 8 comments
Closed

Cache-Hit set to string, not boolean, as of v4.1.0 #1466

bigdogwillfeed opened this issue Oct 7, 2024 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@bigdogwillfeed
Copy link

After a recent upgrade, our runners started behaving differently on cache miss.

As of 0c45773, a step defined with if: steps.cache-release.outputs.cache-hit would be skipped if the "cache release" job missed the cache, as intended. As of 2cdf405, the job now runs on cache miss, despite clearly missing the cache.

Here's a relevant snippet of the run with debug logging enabled

Cache not found for input keys: release-0e0ceb0ce2360a93ec77b898ac06177b7429666b
##[debug]Node Action run completed with exit code 0
##[debug]Save intra-action state CACHE_KEY = release-0e0ceb0ce2360a93ec77b898ac06177b7429666b
##[debug]Set output cache-hit = false
##[debug]Finishing: Cache release folder
<snip>
##[debug]Evaluating condition for step: 'Panic if build already exists'
##[debug]Evaluating: (success() && steps.cache-release.outputs.cache-hit)
##[debug]Evaluating And:
##[debug]..Evaluating success:
##[debug]..=> true
##[debug]..Evaluating Index:
##[debug]....Evaluating Index:
##[debug]......Evaluating Index:
##[debug]........Evaluating steps:
##[debug]........=> Object
##[debug]........Evaluating String:
##[debug]........=> 'cache-release'
##[debug]......=> Object
##[debug]......Evaluating String:
##[debug]......=> 'outputs'
##[debug]....=> Object
##[debug]....Evaluating String:
##[debug]....=> 'cache-hit'
##[debug]..=> 'false'
##[debug]=> 'false'
##[debug]Expanded: (true && 'false')
##[debug]Result: 'false'
##[debug]Starting: Panic if build already exists
@bigdogwillfeed bigdogwillfeed changed the title Cache-Miss set to string, not boolean, as of v4.1.0 Cache-Hit set to string, not boolean, as of v4.1.0 Oct 7, 2024
@madebr
Copy link

madebr commented Oct 8, 2024

I'm seeing the same bad behavior.
As a workaround, I added a string comparison to my workflows:

      if: ${{ (!steps.cache-restore.outputs.cache-hit || steps.cache-restore.outputs.cache-hit == 'false') }}

@Jason3S
Copy link

Jason3S commented Oct 8, 2024

This is cause by #1404, which was a major breaking change.
It is not clear why the change was necessary.

@lenalebt
Copy link

lenalebt commented Oct 8, 2024

It also breaks https://github.com/AnimMouse/setup-rclone, see AnimMouse/setup-rclone#10

@AnimMouse
Copy link

It's sad that it's 2024, and GitHub Actions still can't make their type system right!
true and false are booleans, not strings!

@joshmgross joshmgross self-assigned this Oct 8, 2024
@joshmgross joshmgross added the bug Something isn't working label Oct 8, 2024
madebr added a commit to libsdl-org/SDL that referenced this issue Oct 8, 2024
@joshmgross
Copy link
Member

This should be fixed in https://github.com/actions/cache/releases/tag/v4.1.1, the v4 tag will be updated soon.

@Jason3S
Copy link

Jason3S commented Oct 8, 2024

@joshmgross,
Thank you.

@itchyny
Copy link

itchyny commented Oct 8, 2024

Maintainers, you're doing quite well job. I'm not being sarcastic. Pray for your mental safety.

The behavior change was intentional to make it consistent with the documentation. The outputs of GitHub Actions have never supported booleans. You shoud check against a string 'true'.

It was an regression that the output is not set in v4. Yes, the behavior change was intentional to fixing the regression. In v3, cache-hit == 'false' worked! But leaving the regression too long allowed people depending on the undocumented (or proposed in #1263) behavior that the output beeing not set.

The changes are reverted right now, but the ternary output is quite difficult IMHO. Well, engineering is difficult.

@joshmgross
Copy link
Member

joshmgross commented Oct 8, 2024

@itchyny I agree that using cache-hit as-is is confusing and difficult.

Our priority is to maintain the existing behavior and avoid unnecessary user friction.

The existing cache-hit output really has two purposes:

  1. Indicates if a cache was restored ('' vs non-empty string)
  2. Indicates if an exact cache match was found ('true' or 'false')

In the future, I'd like to break that up into two outputs so that we don't need this odd ternary string to represent all 3 cases. Ideally that would come with proper support in the Actions runner for typed outputs, but that's not currently on our roadmap.

Alternatively, we adopt the changes that were reverted and properly release that as a breaking change with a v5 of this action. Major versions are not something we do often - we end up with mixed adoption across major versions and either have to maintain multiple major versions or leave users on older major versions out of important security updates or bug fixes.

I'm going to call this closed for now, but I'm open to further feedback on how we can improve cache-hit. Feel free to open an issue or discussion if you'd like to discuss that further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants