mirror of
https://github.com/nektos/act.git
synced 2026-04-26 09:25:54 +03:00
[PR #287] [MERGED] Rewrite contexts before evaluating them #1402
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#1402
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?
📋 Pull Request Information
Original PR: https://github.com/nektos/act/pull/287
Author: @badouralix
Created: 6/21/2020
Status: ✅ Merged
Merged: 6/24/2020
Merged by: @cplee
Base:
master← Head:rewrite-hyphens📝 Commits (5)
5a72c07Rewrite contexts before evaluating thema429c03Precompile context and expression patternsd7eec0aTest trim before rewrited27985cMerge branch 'master' into rewrite-hyphens364a344Merge branch 'master' into rewrite-hyphens📊 Changes
2 files changed (+101 additions, -14 deletions)
View changed files
📝
pkg/runner/expression.go(+36 -9)📝
pkg/runner/expression_test.go(+65 -5)📄 Description
Description
This PR aims to fix https://github.com/nektos/act/issues/104. In a nutshell,
actuses a javascript virtual machine to interpret and evaluate expressions in github actions. It works pretty well, except for expressions likeobject.property-with-hyphenswhich are correctly handled by github action runners, but not by the javascript vm.This solution is heavily inspired by https://github.com/nektos/act/issues/104#issuecomment-636213788 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
Rewritemethod which job is exactly the one described above, and we call it just before evaluating the expression in the javascript vm.Explanations
⚠️ The current implementation relies on a regex hackery ( see here to test it online ), which is fairly ugly and hard to maintain. In the future, we should invest some time to implement a proper lexer/parser and a proper term rewriter. But in the short-term, this regex works.
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
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.