mirror of
https://github.com/nektos/act.git
synced 2026-04-26 09:25:54 +03:00
[GH-ISSUE #104] Unable to interpolate string - hyphenated variables #69
Labels
No labels
area/action
area/cli
area/docs
area/image
area/runner
area/workflow
backlog
confirmed/not-planned
kind/bug
kind/discussion
kind/external
kind/feature-request
kind/question
meta/duplicate
meta/invalid
meta/need-more-info
meta/resolved
meta/wontfix
meta/workaround
needs-work
pull-request
review/not-planned
size/M
size/XL
size/XXL
stale
stale-exempt
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/act#69
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @mced on GitHub (Feb 25, 2020).
Original GitHub issue: https://github.com/nektos/act/issues/104
I'm facing an issue when I'm trying to reference a
steps.<id>.outputs.<variable>with an id composed with-.Workaround; remove all
-in id names.@cplee commented on GitHub (Feb 25, 2020):
i was afraid of this :(
Implementing the expression logic in
actwas interesting. I noticed that if i squinted enough that the syntax looked like javascript, so i used robertkrimen/otto to process it as javascript. Unfortunately, javascript doesn't allow-in variable names, but GH expressions does.Any ideas on how to fix?
@mced commented on GitHub (Feb 25, 2020):
From the blogpost I've just read [1] and the releases history, you actually used a parser released by github. Unfortunately actions/workflow-parser is dead. Can you tell me what happened ?
[1] https://github.blog/2019-02-07-an-open-source-parser-for-github-actions/
@cplee commented on GitHub (Feb 25, 2020):
The first cut of actions was completely different from the GA version. Seems like it was a rewrite to be based on Azure DevOps.
@mced commented on GitHub (Feb 25, 2020):
You're right, it was based on HashiCorp HCL. Now GA uses yaml syntax.
Thus I'd say to replace otto by an yaml parser, but I won't :)
@cplee commented on GitHub (Feb 25, 2020):
The problem here isn't the parsing of the workflow files. I am using yaml parser for those (and previously the lib for HCL from github). However, some of the values in the yaml have a custom GitHub expression: https://help.github.com/en/actions/reference/contexts-and-expression-syntax-for-github-actions
That expression is what needs an evaluator, and what I use Otto for
@icarcal commented on GitHub (Feb 27, 2020):
Hey guys, I'm having the same problem here :(
As @mced pointed out,for a workaround to this, you can switch all variables with
-to_for example.The problem is when you have another action that implement output variables, for example: actions/cache
When I check for the
steps.yarn_cache.outputs.cache-hit != 'true', I receive the following error:sh ERRO[0017] Error evaluating expression 'steps.yarn_cache.outputs.cache-hit != 'true'' - ReferenceError: 'hit' is not definedGreat work in this package btw.
@icarcal commented on GitHub (Feb 29, 2020):
Hey guys.
I found a new "workaround" for this.
Looking further into the GA expression docs, there are two ways of writing an expression.
From the GA expression docs:
Since
actuses otto to evaluate all expressions, if we write:steps.yarn_cache.outputs['cache-hit'] != 'true'instead of
steps.yarn_cache.outputs.cache-hit != 'true'GA runner accepts it, otto evaluates it correctly, and we can run it both with
actandGA@cplee commented on GitHub (Mar 2, 2020):
Thanks @icarcal for calling out this workaround! Unfortunately, I think this is as good as it gets for now.
@mced - are you ok closing this given the workaround?
@mced commented on GitHub (Mar 2, 2020):
I'm ok with the given workarounds, thanks @icarcal @cplee.
@torbjornvatn commented on GitHub (Mar 6, 2020):
@cplee I found another case where this is an issue and the workaround doesn't work;
When your trying to use someone else's action and it has input parameters with
-in them.which gives the error:
@cplee commented on GitHub (Mar 6, 2020):
Confirmed @torbjornvatn :(
I'm really stumped on this one. I'd really rather not have to implement my own parser for GitHub Actions expression language. Open to suggestions.
@icarcal commented on GitHub (Mar 6, 2020):
@cplee Replace the dot notation with the array notation before evaluate the expression is an option?
@cplee commented on GitHub (Mar 6, 2020):
ya, that may work @icarcal ...would be a rather interesting regex
@eventualbuddha commented on GitHub (Mar 31, 2020):
While I agree it would be somewhat annoying to port it to Golang, the expression parser for it is at least open source. You can find the lexer here, for example. It really doesn't look too bad.
@cplee commented on GitHub (Apr 16, 2020):
Great find @eventualbuddha - would love some help with this one!
@Shadowfiend commented on GitHub (May 29, 2020):
Dug a little more at that lexer, looks like the right regex for the actual token would be something like
\.([a-zA-Z_][a-zA-Z0-9]*(?:-[a-zA-Z0-9]*)+)(see the legal keyword test for valid keyword contents). Replacing that with.["$1"]should do the trick.I'll try and do a PR in the next couple of days.
@badouralix commented on GitHub (Jun 24, 2020):
#286 is quite interesting
Here is the code handling the evaluation of the if-expression at high-level :
github.com/nektos/act@7cc668707b/pkg/runner/run_context.go (L254-L266)With this setup, we have
expr == "steps.bincache.outputs.cache-hit != 'true'".This is not properly parsed by
Interpolateas it is missing the${{...}}delimiters ( github actions support this feature though ). By default,Interpolatewill return the same output as the input.So we end up with
expr == "Boolean(steps.bincache.outputs.cache-hit != 'true')"which is the input ofEvaluateAnd it fails evaluating because of the js reference error, so we enter this block :
github.com/nektos/act@7cc668707b/pkg/runner/run_context.go (L259-L261)So here
EvalBoolreturnsfalse.But if we change just a little bit the if-expression with :
Then
Interpolatecan parse its input. It callsEvaluate, which fails for the same reason as before. But the error is caught byInterpolatewhich will return the empty string because of :github.com/nektos/act@7cc668707b/pkg/runner/expression.go (L65-L67)So here, we end up with
expr == Boolean()( this is different from the previous case ). It means that we reach :github.com/nektos/act@7cc668707b/pkg/runner/run_context.go (L262-L263)In particular, we got this debug log line :
And
EvalBoolalso returnsfalse.But the reason is different from the previous case, and the fix will likely be sightly different.