-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Rewrite contexts before evaluating them #287
Conversation
@badouralix - this is freaking awesome...how can i help? |
The current contextPattern is quite constraining and would fail the rewrite of a context with trailing spaces. Triming happens during the execution of Interpolate, and these tests aim to detect future breaking changes on this behavior.
6d75931
to
d7eec0a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the contribution!
🙌 thank you! |
Can you cut a new release with this? |
yes please release |
@justincy @myselfhimself - new release |
Perfect I will test against expressions like |
Fix confirmed thanks! |
Description
This PR aims to fix #104. In a nutshell,
act
uses a javascript virtual machine to interpret and evaluate expressions in github actions. It works pretty well, except for expressions likeobject.property-with-hyphens
which are correctly handled by github action runners, but not by the javascript vm.This solution is heavily inspired by #104 (comment) written by @Shadowfiend, although the implementation diverged a little bit from the initial proposal. The idea is to tweak just a little bit the expression and transform it into
object['property-with-hyphens']
which is both github actions and javascript compliant.To do so, we introduce the
Rewrite
method which job is exactly the one described above, and we call it just before evaluating the expression in the javascript vm.Explanations
That being said, using regex for this rewriting is really hard to get right !
Here is a snapshot of what I tried...
One thing to keep in mind is that not all
.
nor not all-
are bad. For instance we do not want to rewrite filenames with extension.But also, we would need to identify strings, escaped characters, already-bracketed expressions, recursive expressions, etc.
So let's keep it simple for now. We choose to only rewrite contexts, which is a subset of expressions
https://help.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#contexts
The pattern defines three groups, as described below :
Here is the execution of the method step by step with
in := "ecole.centrale.paris"
. See also https://play.golang.org/p/bu2rO817ycUBefore entering the loop
re
"ecole.centrale.paris"
First iteration
matches[0]
"ecole.centrale.paris"
matches[1]
"ecole"
matches[2]
"centrale"
matches[3]
".paris"
re
"ecole['centrale'].paris"
Second iteration
matches[0]
"ecole['centrale'].paris"
matches[1]
"ecole['centrale']"
matches[2]
"paris"
matches[3]
""
re
"ecole['centrale']['paris']"
Third iteration
matches[0]
"ecole['centrale']['paris']"
matches[1]
"ecole['centrale']['paris']"
matches[2]
""
matches[3]
""
re
"ecole['centrale']['paris']"
Here we trigger the break condition and the function returns
Testing
Before the fix :
After the fix :
References