Skip to content

Commit f121321

Browse files
Make runs-on support variable expression (#91)
Partial implementation of https://gitea.com/gitea/act_runner/issues/445, the Gitea side also needs a PR for the entire functionality. Gitea side: go-gitea/gitea#29468 Co-authored-by: Jason Song <[email protected]> Reviewed-on: https://gitea.com/gitea/act/pulls/91 Reviewed-by: Jason Song <[email protected]> Co-authored-by: sillyguodong <[email protected]> Co-committed-by: sillyguodong <[email protected]>
1 parent 15045b4 commit f121321

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

pkg/jobparser/interpeter.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func NewInterpeter(
1515
matrix map[string]interface{},
1616
gitCtx *model.GithubContext,
1717
results map[string]*JobResult,
18+
vars map[string]string,
1819
) exprparser.Interpreter {
1920
strategy := make(map[string]interface{})
2021
if job.Strategy != nil {
@@ -62,6 +63,7 @@ func NewInterpeter(
6263
Matrix: matrix,
6364
Needs: using,
6465
Inputs: nil, // not supported yet
66+
Vars: vars,
6567
}
6668

6769
config := exprparser.Config{

pkg/jobparser/jobparser.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func Parse(content []byte, options ...ParseOption) ([]*SingleWorkflow, error) {
5353
}
5454
job.Name = nameWithMatrix(job.Name, matrix)
5555
job.Strategy.RawMatrix = encodeMatrix(matrix)
56-
evaluator := NewExpressionEvaluator(NewInterpeter(id, origin.GetJob(id), matrix, pc.gitContext, results))
56+
evaluator := NewExpressionEvaluator(NewInterpeter(id, origin.GetJob(id), matrix, pc.gitContext, results, pc.vars))
5757
runsOn := origin.GetJob(id).RunsOn()
5858
for i, v := range runsOn {
5959
runsOn[i] = evaluator.Interpolate(v)
@@ -86,9 +86,16 @@ func WithGitContext(context *model.GithubContext) ParseOption {
8686
}
8787
}
8888

89+
func WithVars(vars map[string]string) ParseOption {
90+
return func(c *parseContext) {
91+
c.vars = vars
92+
}
93+
}
94+
8995
type parseContext struct {
9096
jobResults map[string]string
9197
gitContext *model.GithubContext
98+
vars map[string]string
9299
}
93100

94101
type ParseOption func(c *parseContext)

0 commit comments

Comments
 (0)