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

Issue: act allows ternary operator in expression #718

Closed
notmatthancock opened this issue Jun 3, 2021 · 6 comments
Closed

Issue: act allows ternary operator in expression #718

notmatthancock opened this issue Jun 3, 2021 · 6 comments
Labels
kind/bug Something isn't working needs-work Extra attention is needed stale-exempt Exempt from stale

Comments

@notmatthancock
Copy link

notmatthancock commented Jun 3, 2021

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>
@notmatthancock notmatthancock added the kind/bug Something isn't working label Jun 3, 2021
@notmatthancock
Copy link
Author

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.

@ChristopherHX
Copy link
Contributor

ChristopherHX commented 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"}}

...

@notmatthancock
Copy link
Author

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.

@ChristopherHX
Copy link
Contributor

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

@github-actions
Copy link
Contributor

github-actions bot commented Jul 4, 2021

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

@ZauberNerd
Copy link
Contributor

This has been fixed with: #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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working needs-work Extra attention is needed stale-exempt Exempt from stale
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants