rhysd / actionlint

:octocat: Static checker for GitHub Actions workflow files
https://rhysd.github.io/actionlint/
MIT License
2.78k stars 154 forks source link

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

Open roryabraham opened 3 months ago

roryabraham commented 3 months ago

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 commented 3 months ago

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.