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