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

Call out ternaries with falsy value-if-true #440

Open
roryabraham opened this issue Jul 24, 2024 · 1 comment
Open

Call out ternaries with falsy value-if-true #440

roryabraham opened this issue Jul 24, 2024 · 1 comment

Comments

@roryabraham
Copy link

Problem

It's common to use this "false ternary" syntax in GitHub Actions:

${{ env.MY_BOOL = 'true' && 'value-if-true' || 'value-if-false' }}

However a note from their docs:

Important

It is important to note that the first value after the && must be truthy. Otherwise, the value after the || will always be returned.

This mistake bit us when I foolishly added some code that looked like this:

run: |
   # the steps don't matter
env:
  S3_URL: s3://${{ env.SHOULD_DEPLOY_PRODUCTION == 'true' && '' || 'staging-' }}expensify-cash

not surprisingly, this led to unexpected behavior where the result was always s3://staging-expensify-cash.

Solution

Update this repo to call out this careless mistake in expressions, since it is likely to lead to unexpected behavior.

@roryabraham
Copy link
Author

Was looking into what it would take to implement this, and I managed to track down some stuff:

It looks like the LogicalOpNode structure is comprised of a LHS and a RHS. So I'd assume that ${{ condition && value-if-true || value-if-false }}.

Need to continue to dig into how the AST is traversed and such. It looks like a custom AST was developed for this repo to represent GHA syntax? Pretty impressive stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant