mirror of
https://gitea.com/gitea/act
synced 2026-05-01 01:27:48 +02:00
refactor: simplify adding new node versions add node 24 (#140)
* backport Reviewed-on: https://gitea.com/gitea/act/pulls/140 Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: Christopher Homberger <christopher.homberger@web.de> Co-committed-by: Christopher Homberger <christopher.homberger@web.de>
This commit is contained in:
committed by
ChristopherHX
parent
39509e9ad0
commit
91852faf93
@@ -20,7 +20,7 @@ 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 format {
|
||||||
case ActionRunsUsingNode20, ActionRunsUsingNode16, ActionRunsUsingNode12, ActionRunsUsingDocker, ActionRunsUsingComposite, ActionRunsUsingGo:
|
case ActionRunsUsingNode24, ActionRunsUsingNode20, ActionRunsUsingNode16, ActionRunsUsingNode12, ActionRunsUsingDocker, ActionRunsUsingComposite, ActionRunsUsingGo:
|
||||||
*a = format
|
*a = format
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf(fmt.Sprintf("The runs.using key in action.yml must be one of: %v, got %s", []string{
|
return fmt.Errorf(fmt.Sprintf("The runs.using key in action.yml must be one of: %v, got %s", []string{
|
||||||
@@ -29,6 +29,7 @@ func (a *ActionRunsUsing) UnmarshalYAML(unmarshal func(interface{}) error) error
|
|||||||
ActionRunsUsingNode12,
|
ActionRunsUsingNode12,
|
||||||
ActionRunsUsingNode16,
|
ActionRunsUsingNode16,
|
||||||
ActionRunsUsingNode20,
|
ActionRunsUsingNode20,
|
||||||
|
ActionRunsUsingNode24,
|
||||||
ActionRunsUsingGo,
|
ActionRunsUsingGo,
|
||||||
}, format))
|
}, format))
|
||||||
}
|
}
|
||||||
@@ -42,6 +43,8 @@ const (
|
|||||||
ActionRunsUsingNode16 = "node16"
|
ActionRunsUsingNode16 = "node16"
|
||||||
// ActionRunsUsingNode20 for running with node20
|
// ActionRunsUsingNode20 for running with node20
|
||||||
ActionRunsUsingNode20 = "node20"
|
ActionRunsUsingNode20 = "node20"
|
||||||
|
// ActionRunsUsingNode24 for running with node24
|
||||||
|
ActionRunsUsingNode24 = "node24"
|
||||||
// ActionRunsUsingDocker for running with docker
|
// ActionRunsUsingDocker for running with docker
|
||||||
ActionRunsUsingDocker = "docker"
|
ActionRunsUsingDocker = "docker"
|
||||||
// ActionRunsUsingComposite for running composite
|
// ActionRunsUsingComposite for running composite
|
||||||
@@ -50,6 +53,23 @@ const (
|
|||||||
ActionRunsUsingGo = "go"
|
ActionRunsUsingGo = "go"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (a ActionRunsUsing) IsNode() bool {
|
||||||
|
switch a {
|
||||||
|
case ActionRunsUsingNode12, ActionRunsUsingNode16, ActionRunsUsingNode20, ActionRunsUsingNode24:
|
||||||
|
return true
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a ActionRunsUsing) IsDocker() bool {
|
||||||
|
return a == ActionRunsUsingDocker
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a ActionRunsUsing) IsComposite() bool {
|
||||||
|
return a == ActionRunsUsingComposite
|
||||||
|
}
|
||||||
|
|
||||||
// ActionRuns are a field in Action
|
// ActionRuns are a field in Action
|
||||||
type ActionRuns struct {
|
type ActionRuns struct {
|
||||||
Using ActionRunsUsing `yaml:"using"`
|
Using ActionRunsUsing `yaml:"using"`
|
||||||
|
|||||||
@@ -176,8 +176,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, actionDir, actionPath, containerActionDir); err != nil {
|
if err := maybeCopyToActionDir(ctx, step, actionDir, actionPath, containerActionDir); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -187,19 +188,19 @@ 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():
|
||||||
location := actionLocation
|
location := actionLocation
|
||||||
if remoteAction == nil {
|
if remoteAction == nil {
|
||||||
location = containerActionDir
|
location = containerActionDir
|
||||||
}
|
}
|
||||||
return execAsDocker(ctx, step, actionName, location, remoteAction == nil)
|
return execAsDocker(ctx, step, actionName, location, remoteAction == nil)
|
||||||
case model.ActionRunsUsingComposite:
|
case x.IsComposite():
|
||||||
if err := maybeCopyToActionDir(ctx, step, actionDir, actionPath, containerActionDir); err != nil {
|
if err := maybeCopyToActionDir(ctx, step, actionDir, actionPath, containerActionDir); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return execAsComposite(step)(ctx)
|
return execAsComposite(step)(ctx)
|
||||||
case model.ActionRunsUsingGo:
|
case x == model.ActionRunsUsingGo:
|
||||||
if err := maybeCopyToActionDir(ctx, step, actionDir, actionPath, containerActionDir); err != nil {
|
if err := maybeCopyToActionDir(ctx, step, actionDir, actionPath, containerActionDir); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -220,6 +221,7 @@ func runActionImpl(step actionStep, actionDir string, remoteAction *remoteAction
|
|||||||
model.ActionRunsUsingNode12,
|
model.ActionRunsUsingNode12,
|
||||||
model.ActionRunsUsingNode16,
|
model.ActionRunsUsingNode16,
|
||||||
model.ActionRunsUsingNode20,
|
model.ActionRunsUsingNode20,
|
||||||
|
model.ActionRunsUsingNode24,
|
||||||
model.ActionRunsUsingComposite,
|
model.ActionRunsUsingComposite,
|
||||||
model.ActionRunsUsingGo,
|
model.ActionRunsUsingGo,
|
||||||
}, action.Runs.Using))
|
}, action.Runs.Using))
|
||||||
@@ -508,11 +510,10 @@ func shouldRunPreStep(step actionStep) common.Conditional {
|
|||||||
func hasPreStep(step actionStep) common.Conditional {
|
func hasPreStep(step actionStep) common.Conditional {
|
||||||
return func(ctx context.Context) bool {
|
return func(ctx 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.Pre != "") ||
|
||||||
action.Runs.Using == model.ActionRunsUsingNode20 ||
|
(action.Runs.Using == model.ActionRunsUsingGo &&
|
||||||
action.Runs.Using == model.ActionRunsUsingGo) &&
|
|
||||||
action.Runs.Pre != "")
|
action.Runs.Pre != "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -526,8 +527,9 @@ func runPreStep(step actionStep) common.Executor {
|
|||||||
stepModel := step.getStepModel()
|
stepModel := step.getStepModel()
|
||||||
action := step.getActionModel()
|
action := step.getActionModel()
|
||||||
|
|
||||||
switch action.Runs.Using {
|
x := action.Runs.Using
|
||||||
case model.ActionRunsUsingNode12, model.ActionRunsUsingNode16, model.ActionRunsUsingNode20:
|
switch {
|
||||||
|
case x.IsNode():
|
||||||
// defaults in pre steps were missing, however provided inputs are available
|
// defaults in pre steps were missing, however provided inputs are available
|
||||||
populateEnvsFromInput(ctx, step.getEnv(), action, rc)
|
populateEnvsFromInput(ctx, step.getEnv(), action, rc)
|
||||||
// todo: refactor into step
|
// todo: refactor into step
|
||||||
@@ -561,7 +563,7 @@ func runPreStep(step actionStep) common.Executor {
|
|||||||
|
|
||||||
return rc.execJobContainer(containerArgs, *step.getEnv(), "", "")(ctx)
|
return rc.execJobContainer(containerArgs, *step.getEnv(), "", "")(ctx)
|
||||||
|
|
||||||
case model.ActionRunsUsingComposite:
|
case x.IsComposite():
|
||||||
if step.getCompositeSteps() == nil {
|
if step.getCompositeSteps() == nil {
|
||||||
step.getCompositeRunContext(ctx)
|
step.getCompositeRunContext(ctx)
|
||||||
}
|
}
|
||||||
@@ -571,7 +573,7 @@ func runPreStep(step actionStep) common.Executor {
|
|||||||
}
|
}
|
||||||
return fmt.Errorf("missing steps in composite action")
|
return fmt.Errorf("missing steps in composite action")
|
||||||
|
|
||||||
case model.ActionRunsUsingGo:
|
case x == model.ActionRunsUsingGo:
|
||||||
// defaults in pre steps were missing, however provided inputs are available
|
// defaults in pre steps were missing, however provided inputs are available
|
||||||
populateEnvsFromInput(ctx, step.getEnv(), action, rc)
|
populateEnvsFromInput(ctx, step.getEnv(), action, rc)
|
||||||
// todo: refactor into step
|
// todo: refactor into step
|
||||||
@@ -642,11 +644,10 @@ func shouldRunPostStep(step actionStep) common.Conditional {
|
|||||||
func hasPostStep(step actionStep) common.Conditional {
|
func hasPostStep(step actionStep) common.Conditional {
|
||||||
return func(ctx context.Context) bool {
|
return func(ctx 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.Post != "") ||
|
||||||
action.Runs.Using == model.ActionRunsUsingNode20 ||
|
(action.Runs.Using == model.ActionRunsUsingGo &&
|
||||||
action.Runs.Using == model.ActionRunsUsingGo) &&
|
|
||||||
action.Runs.Post != "")
|
action.Runs.Post != "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -680,8 +681,9 @@ func runPostStep(step actionStep) common.Executor {
|
|||||||
|
|
||||||
_, containerActionDir := getContainerActionPaths(stepModel, actionLocation, rc)
|
_, 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)
|
||||||
|
|
||||||
@@ -692,7 +694,7 @@ func runPostStep(step actionStep) common.Executor {
|
|||||||
|
|
||||||
return rc.execJobContainer(containerArgs, *step.getEnv(), "", "")(ctx)
|
return rc.execJobContainer(containerArgs, *step.getEnv(), "", "")(ctx)
|
||||||
|
|
||||||
case model.ActionRunsUsingComposite:
|
case x.IsComposite():
|
||||||
if err := maybeCopyToActionDir(ctx, step, actionDir, actionPath, containerActionDir); err != nil {
|
if err := maybeCopyToActionDir(ctx, step, actionDir, actionPath, containerActionDir); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -702,7 +704,7 @@ func runPostStep(step actionStep) common.Executor {
|
|||||||
}
|
}
|
||||||
return fmt.Errorf("missing steps in composite action")
|
return fmt.Errorf("missing steps in composite action")
|
||||||
|
|
||||||
case model.ActionRunsUsingGo:
|
case x == model.ActionRunsUsingGo:
|
||||||
populateEnvsFromSavedState(step.getEnv(), step, rc)
|
populateEnvsFromSavedState(step.getEnv(), step, rc)
|
||||||
rc.ApplyExtraPath(ctx, step.getEnv())
|
rc.ApplyExtraPath(ctx, step.getEnv())
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user