Support configuration variables
(#43)
related to: https://gitea.com/gitea/act_runner/issues/127 This PR make `act` support the expression like `${{ vars.YOUR_CUSTOM_VARIABLES }}`. Reviewed-on: https://gitea.com/gitea/act/pulls/43 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
d3a56cdb69
commit
de529139af
5 changed files with 15 additions and 0 deletions
|
@ -23,6 +23,8 @@ type EvaluationEnvironment struct {
|
||||||
Matrix map[string]interface{}
|
Matrix map[string]interface{}
|
||||||
Needs map[string]Needs
|
Needs map[string]Needs
|
||||||
Inputs map[string]interface{}
|
Inputs map[string]interface{}
|
||||||
|
|
||||||
|
Vars map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Needs struct {
|
type Needs struct {
|
||||||
|
@ -181,6 +183,8 @@ func (impl *interperterImpl) evaluateVariable(variableNode *actionlint.VariableN
|
||||||
return math.Inf(1), nil
|
return math.Inf(1), nil
|
||||||
case "nan":
|
case "nan":
|
||||||
return math.NaN(), nil
|
return math.NaN(), nil
|
||||||
|
case "vars":
|
||||||
|
return impl.env.Vars, nil
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("Unavailable context: %s", variableNode.Name)
|
return nil, fmt.Errorf("Unavailable context: %s", variableNode.Name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,8 @@ func NewInterpeter(
|
||||||
Matrix: matrix,
|
Matrix: matrix,
|
||||||
Needs: using,
|
Needs: using,
|
||||||
Inputs: nil, // not supported yet
|
Inputs: nil, // not supported yet
|
||||||
|
|
||||||
|
Vars: nil,
|
||||||
}
|
}
|
||||||
|
|
||||||
config := exprparser.Config{
|
config := exprparser.Config{
|
||||||
|
|
|
@ -81,6 +81,8 @@ func (rc *RunContext) NewExpressionEvaluatorWithEnv(ctx context.Context, env map
|
||||||
Matrix: rc.Matrix,
|
Matrix: rc.Matrix,
|
||||||
Needs: using,
|
Needs: using,
|
||||||
Inputs: inputs,
|
Inputs: inputs,
|
||||||
|
|
||||||
|
Vars: rc.getVarsContext(),
|
||||||
}
|
}
|
||||||
if rc.JobContainer != nil {
|
if rc.JobContainer != nil {
|
||||||
ee.Runner = rc.JobContainer.GetRunnerContext(ctx)
|
ee.Runner = rc.JobContainer.GetRunnerContext(ctx)
|
||||||
|
@ -130,6 +132,8 @@ func (rc *RunContext) NewStepExpressionEvaluator(ctx context.Context, step step)
|
||||||
// todo: should be unavailable
|
// todo: should be unavailable
|
||||||
// but required to interpolate/evaluate the inputs in actions/composite
|
// but required to interpolate/evaluate the inputs in actions/composite
|
||||||
Inputs: inputs,
|
Inputs: inputs,
|
||||||
|
|
||||||
|
Vars: rc.getVarsContext(),
|
||||||
}
|
}
|
||||||
if rc.JobContainer != nil {
|
if rc.JobContainer != nil {
|
||||||
ee.Runner = rc.JobContainer.GetRunnerContext(ctx)
|
ee.Runner = rc.JobContainer.GetRunnerContext(ctx)
|
||||||
|
|
|
@ -683,6 +683,10 @@ func (rc *RunContext) getStepsContext() map[string]*model.StepResult {
|
||||||
return rc.StepResults
|
return rc.StepResults
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rc *RunContext) getVarsContext() map[string]string {
|
||||||
|
return rc.Config.Vars
|
||||||
|
}
|
||||||
|
|
||||||
func (rc *RunContext) getGithubContext(ctx context.Context) *model.GithubContext {
|
func (rc *RunContext) getGithubContext(ctx context.Context) *model.GithubContext {
|
||||||
logger := common.Logger(ctx)
|
logger := common.Logger(ctx)
|
||||||
ghc := &model.GithubContext{
|
ghc := &model.GithubContext{
|
||||||
|
|
|
@ -64,6 +64,7 @@ type Config struct {
|
||||||
DefaultActionInstance string // the default actions web site
|
DefaultActionInstance string // the default actions web site
|
||||||
PlatformPicker func(labels []string) string // platform picker, it will take precedence over Platforms if isn't nil
|
PlatformPicker func(labels []string) string // platform picker, it will take precedence over Platforms if isn't nil
|
||||||
JobLoggerLevel *log.Level // the level of job logger
|
JobLoggerLevel *log.Level // the level of job logger
|
||||||
|
Vars map[string]string // the list of variables set at the repository, environment, or organization levels.
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Config) GetToken() string {
|
func (c Config) GetToken() string {
|
||||||
|
|
Loading…
Reference in a new issue