mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-03-01 01:10:17 +00:00
fix: Allow almost all node<number> variants in actions.runs (#120)
This commit is contained in:
@@ -20,28 +20,34 @@ func (a *ActionRunsUsing) UnmarshalYAML(unmarshal func(interface{}) error) error
|
||||
|
||||
// Force input to lowercase for case insensitive comparison
|
||||
format := ActionRunsUsing(strings.ToLower(using))
|
||||
switch format {
|
||||
case ActionRunsUsingNode20, ActionRunsUsingNode16, ActionRunsUsingNode12, ActionRunsUsingDocker, ActionRunsUsingComposite:
|
||||
switch {
|
||||
case format.IsNode() || format.IsDocker() || format.IsComposite():
|
||||
*a = format
|
||||
default:
|
||||
return fmt.Errorf("the runs.using key in action.yml must be one of: %v, got %s", []string{
|
||||
ActionRunsUsingComposite,
|
||||
ActionRunsUsingDocker,
|
||||
ActionRunsUsingNode12,
|
||||
ActionRunsUsingNode16,
|
||||
ActionRunsUsingNode20,
|
||||
ActionRunsUsingNode + "<node version like 12, 16, 20, 24 or later>",
|
||||
}, format)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a ActionRunsUsing) IsNode() bool {
|
||||
return strings.HasPrefix(string(a), string(ActionRunsUsingNode))
|
||||
}
|
||||
|
||||
func (a ActionRunsUsing) IsDocker() bool {
|
||||
return a == ActionRunsUsingDocker
|
||||
}
|
||||
|
||||
func (a ActionRunsUsing) IsComposite() bool {
|
||||
return a == ActionRunsUsingComposite
|
||||
}
|
||||
|
||||
const (
|
||||
// ActionRunsUsingNode12 for running with node12
|
||||
ActionRunsUsingNode12 = "node12"
|
||||
// ActionRunsUsingNode16 for running with node16
|
||||
ActionRunsUsingNode16 = "node16"
|
||||
// ActionRunsUsingNode20 for running with node20
|
||||
ActionRunsUsingNode20 = "node20"
|
||||
// ActionRunsUsingNode for running with node12, node16, node20, node24 or later
|
||||
ActionRunsUsingNode = "node"
|
||||
// ActionRunsUsingDocker for running with docker
|
||||
ActionRunsUsingDocker = "docker"
|
||||
// ActionRunsUsingComposite for running composite
|
||||
|
||||
@@ -166,8 +166,9 @@ func runActionImpl(step actionStep, actionDir string, remoteAction *remoteAction
|
||||
|
||||
logger.Debugf("type=%v actionDir=%s actionPath=%s workdir=%s actionCacheDir=%s actionName=%s containerActionDir=%s", stepModel.Type(), actionDir, actionPath, rc.Config.Workdir, rc.ActionCacheDir(), actionName, containerActionDir)
|
||||
|
||||
switch action.Runs.Using {
|
||||
case model.ActionRunsUsingNode12, model.ActionRunsUsingNode16, model.ActionRunsUsingNode20:
|
||||
x := action.Runs.Using
|
||||
switch {
|
||||
case x.IsNode():
|
||||
if err := maybeCopyToActionDir(ctx, step, actionPath, containerActionDir); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -177,13 +178,13 @@ func runActionImpl(step actionStep, actionDir string, remoteAction *remoteAction
|
||||
rc.ApplyExtraPath(ctx, step.getEnv())
|
||||
|
||||
return rc.execJobContainer(containerArgs, *step.getEnv(), "", "")(ctx)
|
||||
case model.ActionRunsUsingDocker:
|
||||
case x.IsDocker():
|
||||
if remoteAction == nil {
|
||||
actionDir = ""
|
||||
actionPath = containerActionDir
|
||||
}
|
||||
return execAsDocker(ctx, step, actionName, actionDir, actionPath, remoteAction == nil, "entrypoint")
|
||||
case model.ActionRunsUsingComposite:
|
||||
case x.IsComposite():
|
||||
if err := maybeCopyToActionDir(ctx, step, actionPath, containerActionDir); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -192,9 +193,7 @@ func runActionImpl(step actionStep, actionDir string, remoteAction *remoteAction
|
||||
default:
|
||||
return fmt.Errorf("the runs.using key must be one of: %v, got %s", []string{
|
||||
model.ActionRunsUsingDocker,
|
||||
model.ActionRunsUsingNode12,
|
||||
model.ActionRunsUsingNode16,
|
||||
model.ActionRunsUsingNode20,
|
||||
model.ActionRunsUsingNode,
|
||||
model.ActionRunsUsingComposite,
|
||||
}, action.Runs.Using)
|
||||
}
|
||||
@@ -480,12 +479,10 @@ func shouldRunPreStep(step actionStep) common.Conditional {
|
||||
func hasPreStep(step actionStep) common.Conditional {
|
||||
return func(_ context.Context) bool {
|
||||
action := step.getActionModel()
|
||||
return (action.Runs.Using == model.ActionRunsUsingComposite) ||
|
||||
((action.Runs.Using == model.ActionRunsUsingNode12 ||
|
||||
action.Runs.Using == model.ActionRunsUsingNode16 ||
|
||||
action.Runs.Using == model.ActionRunsUsingNode20) &&
|
||||
return action.Runs.Using.IsComposite() ||
|
||||
(action.Runs.Using.IsNode() &&
|
||||
action.Runs.Pre != "") ||
|
||||
(action.Runs.Using == model.ActionRunsUsingDocker &&
|
||||
(action.Runs.Using.IsDocker() &&
|
||||
action.Runs.PreEntrypoint != "")
|
||||
}
|
||||
}
|
||||
@@ -524,8 +521,9 @@ func runPreStep(step actionStep) common.Executor {
|
||||
|
||||
actionName, containerActionDir := getContainerActionPaths(stepModel, actionLocation, rc)
|
||||
|
||||
switch action.Runs.Using {
|
||||
case model.ActionRunsUsingNode12, model.ActionRunsUsingNode16, model.ActionRunsUsingNode20:
|
||||
x := action.Runs.Using
|
||||
switch {
|
||||
case x.IsNode():
|
||||
if err := maybeCopyToActionDir(ctx, step, actionPath, containerActionDir); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -537,14 +535,14 @@ func runPreStep(step actionStep) common.Executor {
|
||||
|
||||
return rc.execJobContainer(containerArgs, *step.getEnv(), "", "")(ctx)
|
||||
|
||||
case model.ActionRunsUsingDocker:
|
||||
case x.IsDocker():
|
||||
if remoteAction == nil {
|
||||
actionDir = ""
|
||||
actionPath = containerActionDir
|
||||
}
|
||||
return execAsDocker(ctx, step, actionName, actionDir, actionPath, remoteAction == nil, "pre-entrypoint")
|
||||
|
||||
case model.ActionRunsUsingComposite:
|
||||
case x.IsComposite():
|
||||
if step.getCompositeSteps() == nil {
|
||||
step.getCompositeRunContext(ctx)
|
||||
}
|
||||
@@ -588,12 +586,10 @@ func shouldRunPostStep(step actionStep) common.Conditional {
|
||||
func hasPostStep(step actionStep) common.Conditional {
|
||||
return func(_ context.Context) bool {
|
||||
action := step.getActionModel()
|
||||
return (action.Runs.Using == model.ActionRunsUsingComposite) ||
|
||||
((action.Runs.Using == model.ActionRunsUsingNode12 ||
|
||||
action.Runs.Using == model.ActionRunsUsingNode16 ||
|
||||
action.Runs.Using == model.ActionRunsUsingNode20) &&
|
||||
return action.Runs.Using.IsComposite() ||
|
||||
(action.Runs.Using.IsNode() &&
|
||||
action.Runs.Post != "") ||
|
||||
(action.Runs.Using == model.ActionRunsUsingDocker &&
|
||||
(action.Runs.Using.IsDocker() &&
|
||||
action.Runs.PostEntrypoint != "")
|
||||
}
|
||||
}
|
||||
@@ -629,9 +625,9 @@ func runPostStep(step actionStep) common.Executor {
|
||||
|
||||
actionName, containerActionDir := getContainerActionPaths(stepModel, actionLocation, rc)
|
||||
|
||||
switch action.Runs.Using {
|
||||
case model.ActionRunsUsingNode12, model.ActionRunsUsingNode16, model.ActionRunsUsingNode20:
|
||||
|
||||
x := action.Runs.Using
|
||||
switch {
|
||||
case x.IsNode():
|
||||
populateEnvsFromSavedState(step.getEnv(), step, rc)
|
||||
populateEnvsFromInput(ctx, step.getEnv(), step.getActionModel(), rc)
|
||||
|
||||
@@ -642,14 +638,14 @@ func runPostStep(step actionStep) common.Executor {
|
||||
|
||||
return rc.execJobContainer(containerArgs, *step.getEnv(), "", "")(ctx)
|
||||
|
||||
case model.ActionRunsUsingDocker:
|
||||
case x.IsDocker():
|
||||
if remoteAction == nil {
|
||||
actionDir = ""
|
||||
actionPath = containerActionDir
|
||||
}
|
||||
return execAsDocker(ctx, step, actionName, actionDir, actionPath, remoteAction == nil, "post-entrypoint")
|
||||
|
||||
case model.ActionRunsUsingComposite:
|
||||
case x.IsComposite():
|
||||
if err := maybeCopyToActionDir(ctx, step, actionPath, containerActionDir); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user