[GH-ISSUE #718] Issue: act allows ternary operator in expression #455

Closed
opened 2026-03-01 21:43:33 +03:00 by kerem · 6 comments
Owner

Originally created by @notmatthancock on GitHub (Jun 3, 2021).
Original GitHub issue: https://github.com/nektos/act/issues/718

Act version

act version 0.2.20

Expected behaviour

act shouldn't allow ternary operator syntax inside of an expression

Reference: https://github.community/t/do-expressions-support-ternary-operators-to-change-their-returned-value/18114

Actual behaviour

act does allow ternary operator syntax inside of an expression, and it fails when run as a github action

Workflow and/or repository

workflow
name: CI
on:
  workflow_dispatch:
    inputs:
      arg1:
        description: "hello"
        required: true
      arg2:
        description: "goodbye"
        required: false
        default: "null"
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
    - name: nice-test 
      run: |
        echo "arg1 = ${{ 1 == 2 ? 'yes' : 'no' }}"

Steps to reproduce

act -j test

act output

Log
DEBU[0000] Loading environment from /home/inno/scratch/docker/github-actions-demo/.env 
DEBU[0000] Loading secrets from /home/inno/scratch/docker/github-actions-demo/.secrets 
DEBU[0000] Loading workflows from '/home/inno/scratch/docker/github-actions-demo/.github/workflows' 
DEBU[0000] Reading workflow '/home/inno/scratch/docker/github-actions-demo/.github/workflows/main.yml' 
DEBU[0000] Planning job: test                           
DEBU[0000] Loading slug from git directory '/home/inno/scratch/docker/github-actions-demo/.git' 
DEBU[0000] Found revision: 5c6f585b1f9d8526c8e1672c5f8f00883b895d93 
DEBU[0000] Loading revision from git directory '/home/inno/scratch/docker/github-actions-demo/.git' 
DEBU[0000] Found revision: 5c6f585b1f9d8526c8e1672c5f8f00883b895d93 
DEBU[0000] HEAD points to '5c6f585b1f9d8526c8e1672c5f8f00883b895d93' 
DEBU[0000] HEAD matches refs/heads/master               
DEBU[0000] using github ref: refs/heads/master          
DEBU[0000] context env => map[ACT:true]                 
[CI/test] 🚀  Start image=catthehacker/ubuntu:act-latest
DEBU[0000] Loading slug from git directory '/home/inno/scratch/docker/github-actions-demo/.git' 
DEBU[0000] Found revision: 5c6f585b1f9d8526c8e1672c5f8f00883b895d93 
DEBU[0000] Loading revision from git directory '/home/inno/scratch/docker/github-actions-demo/.git' 
DEBU[0000] Found revision: 5c6f585b1f9d8526c8e1672c5f8f00883b895d93 
DEBU[0000] HEAD points to '5c6f585b1f9d8526c8e1672c5f8f00883b895d93' 
DEBU[0000] HEAD matches refs/heads/master               
DEBU[0000] using github ref: refs/heads/master          
[CI/test]   🐳  docker pull catthehacker/ubuntu:act-latest
DEBU[0000] Image exists? true                           
[CI/test]   🐳  docker create image=catthehacker/ubuntu:act-latest entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[CI/test] Created container name=act-CI-test id=05ad9157c88abbf132945c31adf49b570bc150ea67849c59e736ade34f7dfc72 from image catthehacker/ubuntu:act-latest
[CI/test] ENV ==> [RUNNER_TOOL_CACHE=/opt/hostedtoolcache RUNNER_OS=Linux RUNNER_TEMP=/tmp]
[CI/test]   🐳  docker run image=catthehacker/ubuntu:act-latest entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[]
[CI/test] Starting container: 05ad9157c88abbf132945c31adf49b570bc150ea67849c59e736ade34f7dfc72
[CI/test] Started container: 05ad9157c88abbf132945c31adf49b570bc150ea67849c59e736ade34f7dfc72
DEBU[0000] Writing entry to tarball workflow/event.json len:2 
DEBU[0000] Writing entry to tarball workflow/envs.txt len:0 
DEBU[0000] Writing entry to tarball home/.act len:0     
[CI/test] Extracting content to '/github/'
DEBU[0000] Loading slug from git directory '/home/inno/scratch/docker/github-actions-demo/.git' 
DEBU[0000] Found revision: 5c6f585b1f9d8526c8e1672c5f8f00883b895d93 
DEBU[0000] Loading revision from git directory '/home/inno/scratch/docker/github-actions-demo/.git' 
DEBU[0000] Found revision: 5c6f585b1f9d8526c8e1672c5f8f00883b895d93 
DEBU[0000] HEAD points to '5c6f585b1f9d8526c8e1672c5f8f00883b895d93' 
DEBU[0000] HEAD matches refs/heads/master               
DEBU[0000] using github ref: refs/heads/master          
DEBU[0000] Loading slug from git directory '/home/inno/scratch/docker/github-actions-demo/.git' 
DEBU[0000] Found revision: 5c6f585b1f9d8526c8e1672c5f8f00883b895d93 
DEBU[0000] Loading revision from git directory '/home/inno/scratch/docker/github-actions-demo/.git' 
DEBU[0000] Found revision: 5c6f585b1f9d8526c8e1672c5f8f00883b895d93 
DEBU[0000] HEAD points to '5c6f585b1f9d8526c8e1672c5f8f00883b895d93' 
DEBU[0000] HEAD matches refs/heads/master               
DEBU[0000] using github ref: refs/heads/master          
DEBU[0000] context env => map[ACT:true]                 
DEBU[0000] context env => map[ACT:true CI:true GITHUB_ACTION:0 GITHUB_ACTIONS:true GITHUB_ACTOR:nektos/act GITHUB_API_URL:https://api.github.com GITHUB_ENV:/github/workflow/envs.txt GITHUB_EVENT_NAME:push GITHUB_EVENT_PATH:/github/workflow/event.json GITHUB_GRAPHQL_URL:https://api.github.com/graphql GITHUB_REF:refs/heads/master GITHUB_REPOSITORY:cplee/github-actions-demo GITHUB_RUN_ID:1 GITHUB_RUN_NUMBER:1 GITHUB_SERVER_URL:https://github.com GITHUB_SHA:5c6f585b1f9d8526c8e1672c5f8f00883b895d93 GITHUB_TOKEN: GITHUB_WORKFLOW:CI GITHUB_WORKSPACE:/github/workspace HOME:/github/home] 
DEBU[0000] setupEnv: map[ACT:true CI:true GITHUB_ACTION:0 GITHUB_ACTIONS:true GITHUB_ACTOR:nektos/act GITHUB_API_URL:https://api.github.com GITHUB_ENV:/github/workflow/envs.txt GITHUB_EVENT_NAME:push GITHUB_EVENT_PATH:/github/workflow/event.json GITHUB_GRAPHQL_URL:https://api.github.com/graphql GITHUB_REF:refs/heads/master GITHUB_REPOSITORY:cplee/github-actions-demo GITHUB_RUN_ID:1 GITHUB_RUN_NUMBER:1 GITHUB_SERVER_URL:https://github.com GITHUB_SHA:5c6f585b1f9d8526c8e1672c5f8f00883b895d93 GITHUB_TOKEN: GITHUB_WORKFLOW:CI GITHUB_WORKSPACE:/github/workspace HOME:/github/home] 
[CI/test] ⭐  Run nice-test
DEBU[0000] Wrote command 'echo "arg1 = no"
' to 'workflow/0' 
DEBU[0000] Writing entry to tarball workflow/0 len:17   
[CI/test] Extracting content to '/github/'
[CI/test] Exec command '[bash --noprofile --norc -eo pipefail /github/workflow/0]'
| arg1 = no
[CI/test]   ✅  Success - nice-test
[CI/test] Removed container: 05ad9157c88abbf132945c31adf49b570bc150ea67849c59e736ade34f7dfc72
[CI/test]   🐳  docker volume rm act-CI-test```

</details>
Originally created by @notmatthancock on GitHub (Jun 3, 2021). Original GitHub issue: https://github.com/nektos/act/issues/718 ## Act version ```none act version 0.2.20 ``` ## Expected behaviour `act` shouldn't allow ternary operator syntax inside of an expression Reference: https://github.community/t/do-expressions-support-ternary-operators-to-change-their-returned-value/18114 ## Actual behaviour `act` does allow ternary operator syntax inside of an expression, and it fails when run as a github action ## Workflow and/or repository <details> <summary>workflow</summary> ```none name: CI on: workflow_dispatch: inputs: arg1: description: "hello" required: true arg2: description: "goodbye" required: false default: "null" jobs: test: runs-on: ubuntu-latest steps: - name: nice-test run: | echo "arg1 = ${{ 1 == 2 ? 'yes' : 'no' }}" ``` </details> ## Steps to reproduce ``` act -j test ``` ## `act` output <details> <summary>Log</summary> ```none DEBU[0000] Loading environment from /home/inno/scratch/docker/github-actions-demo/.env DEBU[0000] Loading secrets from /home/inno/scratch/docker/github-actions-demo/.secrets DEBU[0000] Loading workflows from '/home/inno/scratch/docker/github-actions-demo/.github/workflows' DEBU[0000] Reading workflow '/home/inno/scratch/docker/github-actions-demo/.github/workflows/main.yml' DEBU[0000] Planning job: test DEBU[0000] Loading slug from git directory '/home/inno/scratch/docker/github-actions-demo/.git' DEBU[0000] Found revision: 5c6f585b1f9d8526c8e1672c5f8f00883b895d93 DEBU[0000] Loading revision from git directory '/home/inno/scratch/docker/github-actions-demo/.git' DEBU[0000] Found revision: 5c6f585b1f9d8526c8e1672c5f8f00883b895d93 DEBU[0000] HEAD points to '5c6f585b1f9d8526c8e1672c5f8f00883b895d93' DEBU[0000] HEAD matches refs/heads/master DEBU[0000] using github ref: refs/heads/master DEBU[0000] context env => map[ACT:true] [CI/test] 🚀 Start image=catthehacker/ubuntu:act-latest DEBU[0000] Loading slug from git directory '/home/inno/scratch/docker/github-actions-demo/.git' DEBU[0000] Found revision: 5c6f585b1f9d8526c8e1672c5f8f00883b895d93 DEBU[0000] Loading revision from git directory '/home/inno/scratch/docker/github-actions-demo/.git' DEBU[0000] Found revision: 5c6f585b1f9d8526c8e1672c5f8f00883b895d93 DEBU[0000] HEAD points to '5c6f585b1f9d8526c8e1672c5f8f00883b895d93' DEBU[0000] HEAD matches refs/heads/master DEBU[0000] using github ref: refs/heads/master [CI/test] 🐳 docker pull catthehacker/ubuntu:act-latest DEBU[0000] Image exists? true [CI/test] 🐳 docker create image=catthehacker/ubuntu:act-latest entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[] [CI/test] Created container name=act-CI-test id=05ad9157c88abbf132945c31adf49b570bc150ea67849c59e736ade34f7dfc72 from image catthehacker/ubuntu:act-latest [CI/test] ENV ==> [RUNNER_TOOL_CACHE=/opt/hostedtoolcache RUNNER_OS=Linux RUNNER_TEMP=/tmp] [CI/test] 🐳 docker run image=catthehacker/ubuntu:act-latest entrypoint=["/usr/bin/tail" "-f" "/dev/null"] cmd=[] [CI/test] Starting container: 05ad9157c88abbf132945c31adf49b570bc150ea67849c59e736ade34f7dfc72 [CI/test] Started container: 05ad9157c88abbf132945c31adf49b570bc150ea67849c59e736ade34f7dfc72 DEBU[0000] Writing entry to tarball workflow/event.json len:2 DEBU[0000] Writing entry to tarball workflow/envs.txt len:0 DEBU[0000] Writing entry to tarball home/.act len:0 [CI/test] Extracting content to '/github/' DEBU[0000] Loading slug from git directory '/home/inno/scratch/docker/github-actions-demo/.git' DEBU[0000] Found revision: 5c6f585b1f9d8526c8e1672c5f8f00883b895d93 DEBU[0000] Loading revision from git directory '/home/inno/scratch/docker/github-actions-demo/.git' DEBU[0000] Found revision: 5c6f585b1f9d8526c8e1672c5f8f00883b895d93 DEBU[0000] HEAD points to '5c6f585b1f9d8526c8e1672c5f8f00883b895d93' DEBU[0000] HEAD matches refs/heads/master DEBU[0000] using github ref: refs/heads/master DEBU[0000] Loading slug from git directory '/home/inno/scratch/docker/github-actions-demo/.git' DEBU[0000] Found revision: 5c6f585b1f9d8526c8e1672c5f8f00883b895d93 DEBU[0000] Loading revision from git directory '/home/inno/scratch/docker/github-actions-demo/.git' DEBU[0000] Found revision: 5c6f585b1f9d8526c8e1672c5f8f00883b895d93 DEBU[0000] HEAD points to '5c6f585b1f9d8526c8e1672c5f8f00883b895d93' DEBU[0000] HEAD matches refs/heads/master DEBU[0000] using github ref: refs/heads/master DEBU[0000] context env => map[ACT:true] DEBU[0000] context env => map[ACT:true CI:true GITHUB_ACTION:0 GITHUB_ACTIONS:true GITHUB_ACTOR:nektos/act GITHUB_API_URL:https://api.github.com GITHUB_ENV:/github/workflow/envs.txt GITHUB_EVENT_NAME:push GITHUB_EVENT_PATH:/github/workflow/event.json GITHUB_GRAPHQL_URL:https://api.github.com/graphql GITHUB_REF:refs/heads/master GITHUB_REPOSITORY:cplee/github-actions-demo GITHUB_RUN_ID:1 GITHUB_RUN_NUMBER:1 GITHUB_SERVER_URL:https://github.com GITHUB_SHA:5c6f585b1f9d8526c8e1672c5f8f00883b895d93 GITHUB_TOKEN: GITHUB_WORKFLOW:CI GITHUB_WORKSPACE:/github/workspace HOME:/github/home] DEBU[0000] setupEnv: map[ACT:true CI:true GITHUB_ACTION:0 GITHUB_ACTIONS:true GITHUB_ACTOR:nektos/act GITHUB_API_URL:https://api.github.com GITHUB_ENV:/github/workflow/envs.txt GITHUB_EVENT_NAME:push GITHUB_EVENT_PATH:/github/workflow/event.json GITHUB_GRAPHQL_URL:https://api.github.com/graphql GITHUB_REF:refs/heads/master GITHUB_REPOSITORY:cplee/github-actions-demo GITHUB_RUN_ID:1 GITHUB_RUN_NUMBER:1 GITHUB_SERVER_URL:https://github.com GITHUB_SHA:5c6f585b1f9d8526c8e1672c5f8f00883b895d93 GITHUB_TOKEN: GITHUB_WORKFLOW:CI GITHUB_WORKSPACE:/github/workspace HOME:/github/home] [CI/test] ⭐ Run nice-test DEBU[0000] Wrote command 'echo "arg1 = no" ' to 'workflow/0' DEBU[0000] Writing entry to tarball workflow/0 len:17 [CI/test] Extracting content to '/github/' [CI/test] Exec command '[bash --noprofile --norc -eo pipefail /github/workflow/0]' | arg1 = no [CI/test] ✅ Success - nice-test [CI/test] Removed container: 05ad9157c88abbf132945c31adf49b570bc150ea67849c59e736ade34f7dfc72 [CI/test] 🐳 docker volume rm act-CI-test``` </details>
kerem 2026-03-01 21:43:33 +03:00
Author
Owner

@notmatthancock commented on GitHub (Jun 3, 2021):

I'm not sure if this is a broader problem besides just the ternary operator. Github has some mini domain language for contexts/expressions, and I was not able to find documentation that describes if their expression DSL is a known language or not. I'm curious what act uses for evaluating expressions.

<!-- gh-comment-id:853491408 --> @notmatthancock commented on GitHub (Jun 3, 2021): I'm not sure if this is a broader problem besides just the ternary operator. Github has some mini domain language for contexts/expressions, and I was not able to find documentation that describes if their expression DSL is a known language or not. I'm curious what `act` uses for evaluating expressions.
Author
Owner

@ChristopherHX commented on GitHub (Jun 3, 2021):

I would say it's a broader problem

  • act uses otto a js engine in go (almost all js expressions are ok)
  • github uses DTExpressions2 sourcecode inside actions/runner, this isn't javascript but may look like it.

The ternary operator can be rewritten to ${{runner.os == 'linux' && 'Yes' || 'No'}} in dtexpressions2 similar to js.

Other examples
Not working in act

  • ${{contains(github.event.commits.*.message, 'Test')}}
  • ${{'${{This is a string with an escaped expression }}'}}

Not working with dtexpressions

  • ${{3+5}}
  • ${{"Double quotes"}}

...

<!-- gh-comment-id:853754266 --> @ChristopherHX commented on GitHub (Jun 3, 2021): I would say it's a broader problem - act uses otto a js engine in go (almost all js expressions are ok) - github uses DTExpressions2 sourcecode inside actions/runner, this isn't javascript but may look like it. The ternary operator can be rewritten to `${{runner.os == 'linux' && 'Yes' || 'No'}}` in dtexpressions2 similar to js. Other examples Not working in act - `${{contains(github.event.commits.*.message, 'Test')}}` - `${{'${{This is a string with an escaped expression }}'}}` Not working with dtexpressions - `${{3+5}}` - `${{"Double quotes"}}` ...
Author
Owner

@notmatthancock commented on GitHub (Jun 3, 2021):

github uses DTExpressions2 sourcecode

Interesting, I have not heard of this. A google search returns 0 results for "DTExpressions2". Any links? I'd be curious to read more.

I would say it's a broader problem
...
Other examples
Not working in act

I see. So perhaps a resolution of this issue could be documenting the discrepancy in the Known issues section of the README.

<!-- gh-comment-id:853869111 --> @notmatthancock commented on GitHub (Jun 3, 2021): > github uses DTExpressions2 sourcecode Interesting, I have not heard of this. A google search returns 0 results for "DTExpressions2". Any links? I'd be curious to read more. > I would say it's a broader problem > ... > Other examples > Not working in act I see. So perhaps a resolution of this issue could be documenting the discrepancy in the Known issues section of the README.
Author
Owner

@ChristopherHX commented on GitHub (Jun 3, 2021):

DTExpressions2 is an internal azure pipelines product, which was (accidentally?) open sourced under the MIT License.
Documentation of some parts of the language: https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions
The source code can be found here
I agree the documentation isn't really great for this language. I took the name out of the soucecode, DT = DistributedTasks.

Azure pipelines still uses version 1 of this language,

I use this in my act clone for full compatibility with github. You could try this if you really need the same expression interpreter

<!-- gh-comment-id:853878203 --> @ChristopherHX commented on GitHub (Jun 3, 2021): DTExpressions2 is an internal azure pipelines product, which was (accidentally?) open sourced under the MIT License. Documentation of some parts of the language: https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions [The source code can be found here](https://github.com/actions/runner/tree/main/src/Sdk/DTExpressions2/Expressions2) I agree the documentation isn't really great for this language. I took the name out of the soucecode, DT = DistributedTasks. Azure pipelines still uses version 1 of this language, _I use this in [my act clone](https://github.com/ChristopherHX/runner.server) for full compatibility with github. You could try this if you really need the same expression interpreter_
Author
Owner

@github-actions[bot] commented on GitHub (Jul 4, 2021):

Issue is stale and will be closed in 14 days unless there is new activity

<!-- gh-comment-id:873487440 --> @github-actions[bot] commented on GitHub (Jul 4, 2021): Issue is stale and will be closed in 14 days unless there is new activity
Author
Owner

@ZauberNerd commented on GitHub (Feb 1, 2022):

This has been fixed with: https://github.com/nektos/act/pull/908 and will be released with the next version.
If you want to try it out earlier, use one of the snapshots: https://github.com/nektos/act/actions/runs/1653750680 or install / build from master: https://github.com/nektos/act#go-linuxwindowsmacosany-other-platform-supported-by-go https://github.com/nektos/act#manually-building-from-source

<!-- gh-comment-id:1027161742 --> @ZauberNerd commented on GitHub (Feb 1, 2022): This has been fixed with: https://github.com/nektos/act/pull/908 and will be released with the next version. If you want to try it out earlier, use one of the snapshots: https://github.com/nektos/act/actions/runs/1653750680 or install / build from master: https://github.com/nektos/act#go-linuxwindowsmacosany-other-platform-supported-by-go https://github.com/nektos/act#manually-building-from-source
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/act#455
No description provided.