diff --git a/pkg/runner/action.go b/pkg/runner/action.go index 48069fe91f5..3346fbf8bd1 100644 --- a/pkg/runner/action.go +++ b/pkg/runner/action.go @@ -101,11 +101,13 @@ func readActionImpl(step *model.Step, actionDir string, actionPath string, readF func runActionImpl(step actionStep, actionDir string, remoteAction *remoteAction) common.Executor { rc := step.getRunContext() stepModel := step.getStepModel() + return func(ctx context.Context) error { actionPath := "" if remoteAction != nil && remoteAction.Path != "" { actionPath = remoteAction.Path } + action := step.getActionModel() log.Debugf("About to run action %v", action) @@ -441,7 +443,7 @@ func execAsComposite(step actionStep, containerActionDir string) common.Executor rc.JobContainer.ReplaceLogWriter(oldout, olderr) })() - err := compositerc.compositeExecutor(action)(ctx) + err := runCompositeSteps(ctx, action, compositerc) // Map outputs from composite RunContext to job RunContext eval = compositerc.NewExpressionEvaluator() @@ -459,8 +461,10 @@ func execAsComposite(step actionStep, containerActionDir string) common.Executor } // Executor returns a pipeline executor for all the steps in the job -func (rc *RunContext) compositeExecutor(action *model.Action) common.Executor { +func (rc *RunContext) compositeExecutor(action *model.Action) *compositeSteps { steps := make([]common.Executor, 0) + preSteps := make([]common.Executor, 0) + postSteps := make([]common.Executor, 0) sf := &stepFactoryImpl{} @@ -475,12 +479,15 @@ func (rc *RunContext) compositeExecutor(action *model.Action) common.Executor { step, err := sf.newStep(&stepcopy, rc) if err != nil { - return common.NewErrorExecutor(err) + return &compositeSteps{ + main: common.NewErrorExecutor(err), + } } - stepExec := common.NewPipelineExecutor(step.pre(), step.main(), step.post()) + + preSteps = append(preSteps, step.pre()) steps = append(steps, func(ctx context.Context) error { - err := stepExec(ctx) + err := step.main()(ctx) if err != nil { common.Logger(ctx).Errorf("%v", err) common.SetJobError(ctx, err) @@ -490,12 +497,33 @@ func (rc *RunContext) compositeExecutor(action *model.Action) common.Executor { } return nil }) + + postSteps = append([]common.Executor{step.post()}, postSteps...) } steps = append(steps, common.JobError) - return func(ctx context.Context) error { - return common.NewPipelineExecutor(steps...)(common.WithJobErrorContainer(ctx)) + return &compositeSteps{ + pre: common.NewPipelineExecutor(preSteps...), + main: func(ctx context.Context) error { + return common.NewPipelineExecutor(steps...)(common.WithJobErrorContainer(ctx)) + }, + post: common.NewPipelineExecutor(postSteps...), + } +} + +func runCompositeSteps(ctx context.Context, action *model.Action, compositerc *RunContext) error { + steps := compositerc.compositeExecutor(action) + var err error + if steps.pre != nil { + err = steps.pre(ctx) + } + if err == nil { + err = steps.main(ctx) + } + if err == nil && steps.post != nil { + err = steps.post(ctx) } + return err } func populateEnvsFromSavedState(env *map[string]string, step actionStep, rc *RunContext) { diff --git a/pkg/runner/action_composite.go b/pkg/runner/action_composite.go new file mode 100644 index 00000000000..6509e645594 --- /dev/null +++ b/pkg/runner/action_composite.go @@ -0,0 +1,9 @@ +package runner + +import "github.com/nektos/act/pkg/common" + +type compositeSteps struct { + pre common.Executor + main common.Executor + post common.Executor +} diff --git a/pkg/runner/action_test.go b/pkg/runner/action_test.go index e1400a79f68..b2db989643a 100644 --- a/pkg/runner/action_test.go +++ b/pkg/runner/action_test.go @@ -146,7 +146,7 @@ func TestActionRunner(t *testing.T) { name: "with-input", step: &stepActionRemote{ Step: &model.Step{ - Uses: "repo@ref", + Uses: "org/repo/path@ref", }, RunContext: &RunContext{ Config: &Config{}, @@ -180,10 +180,10 @@ func TestActionRunner(t *testing.T) { step: &stepActionRemote{ Step: &model.Step{ ID: "step", - Uses: "repo@ref", + Uses: "org/repo/path@ref", }, RunContext: &RunContext{ - ActionRepository: "repo", + ActionRepository: "org/repo", ActionPath: "path", ActionRef: "ref", Config: &Config{},