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: https://github.com/go-gitea/gitea/pull/29468 Co-authored-by: Jason Song <i@wolfogre.com> Reviewed-on: https://gitea.com/gitea/act/pulls/91 Reviewed-by: Jason Song <i@wolfogre.com> Co-authored-by: sillyguodong <gedong_1994@163.com> Co-committed-by: sillyguodong <gedong_1994@163.com>
This commit is contained in:
parent
e6fec7324e
commit
82a3640cf8
2 changed files with 10 additions and 1 deletions
|
@ -15,6 +15,7 @@ func NewInterpeter(
|
||||||
matrix map[string]interface{},
|
matrix map[string]interface{},
|
||||||
gitCtx *model.GithubContext,
|
gitCtx *model.GithubContext,
|
||||||
results map[string]*JobResult,
|
results map[string]*JobResult,
|
||||||
|
vars map[string]string,
|
||||||
) exprparser.Interpreter {
|
) exprparser.Interpreter {
|
||||||
strategy := make(map[string]interface{})
|
strategy := make(map[string]interface{})
|
||||||
if job.Strategy != nil {
|
if job.Strategy != nil {
|
||||||
|
@ -62,6 +63,7 @@ func NewInterpeter(
|
||||||
Matrix: matrix,
|
Matrix: matrix,
|
||||||
Needs: using,
|
Needs: using,
|
||||||
Inputs: nil, // not supported yet
|
Inputs: nil, // not supported yet
|
||||||
|
Vars: vars,
|
||||||
}
|
}
|
||||||
|
|
||||||
config := exprparser.Config{
|
config := exprparser.Config{
|
||||||
|
|
|
@ -53,7 +53,7 @@ func Parse(content []byte, options ...ParseOption) ([]*SingleWorkflow, error) {
|
||||||
}
|
}
|
||||||
job.Name = nameWithMatrix(job.Name, matrix)
|
job.Name = nameWithMatrix(job.Name, matrix)
|
||||||
job.Strategy.RawMatrix = encodeMatrix(matrix)
|
job.Strategy.RawMatrix = encodeMatrix(matrix)
|
||||||
evaluator := NewExpressionEvaluator(NewInterpeter(id, origin.GetJob(id), matrix, pc.gitContext, results))
|
evaluator := NewExpressionEvaluator(NewInterpeter(id, origin.GetJob(id), matrix, pc.gitContext, results, pc.vars))
|
||||||
runsOn := origin.GetJob(id).RunsOn()
|
runsOn := origin.GetJob(id).RunsOn()
|
||||||
for i, v := range runsOn {
|
for i, v := range runsOn {
|
||||||
runsOn[i] = evaluator.Interpolate(v)
|
runsOn[i] = evaluator.Interpolate(v)
|
||||||
|
@ -86,9 +86,16 @@ func WithGitContext(context *model.GithubContext) ParseOption {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WithVars(vars map[string]string) ParseOption {
|
||||||
|
return func(c *parseContext) {
|
||||||
|
c.vars = vars
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type parseContext struct {
|
type parseContext struct {
|
||||||
jobResults map[string]string
|
jobResults map[string]string
|
||||||
gitContext *model.GithubContext
|
gitContext *model.GithubContext
|
||||||
|
vars map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type ParseOption func(c *parseContext)
|
type ParseOption func(c *parseContext)
|
||||||
|
|
Loading…
Reference in a new issue