diff --git a/pkg/model/action.go b/pkg/model/action.go index 6da142e005d..9336b6c146a 100644 --- a/pkg/model/action.go +++ b/pkg/model/action.go @@ -49,17 +49,19 @@ const ( // ActionRuns are a field in Action type ActionRuns struct { - Using ActionRunsUsing `yaml:"using"` - Env map[string]string `yaml:"env"` - Main string `yaml:"main"` - Pre string `yaml:"pre"` - PreIf string `yaml:"pre-if"` - Post string `yaml:"post"` - PostIf string `yaml:"post-if"` - Image string `yaml:"image"` - Entrypoint string `yaml:"entrypoint"` - Args []string `yaml:"args"` - Steps []Step `yaml:"steps"` + Using ActionRunsUsing `yaml:"using"` + Env map[string]string `yaml:"env"` + Main string `yaml:"main"` + Pre string `yaml:"pre"` + PreIf string `yaml:"pre-if"` + Post string `yaml:"post"` + PostIf string `yaml:"post-if"` + Image string `yaml:"image"` + PreEntrypoint string `yaml:"pre-entrypoint"` + Entrypoint string `yaml:"entrypoint"` + PostEntrypoint string `yaml:"post-entrypoint"` + Args []string `yaml:"args"` + Steps []Step `yaml:"steps"` } // Action describes a metadata file for GitHub actions. The metadata filename must be either action.yml or action.yaml. The data in the metadata file defines the inputs, outputs and main entrypoint for your action. diff --git a/pkg/runner/action.go b/pkg/runner/action.go index 3809359405b..583bf67fc15 100644 --- a/pkg/runner/action.go +++ b/pkg/runner/action.go @@ -319,6 +319,29 @@ func execAsDocker(ctx context.Context, step actionStep, actionName string, based cmd = action.Runs.Args evalDockerArgs(ctx, step, action, &cmd) } + + preEntrypoint := strings.Fields(eval.Interpolate(ctx, step.getStepModel().With["pre-entrypoint"])) + if len(preEntrypoint) == 0 { + if action.Runs.PreEntrypoint != "" { + preEntrypoint, err = shellquote.Split(action.Runs.PreEntrypoint) + if err != nil { + return err + } + } else { + preEntrypoint = nil + } + } + stepPreContainer := newStepContainer(ctx, step, image, cmd, preEntrypoint) + prePipelineExecutor := common.NewPipelineExecutor( + prepImage, + stepPreContainer.Pull(forcePull), + stepPreContainer.Remove().IfBool(!rc.Config.ReuseContainers), + stepPreContainer.Create(rc.Config.ContainerCapAdd, rc.Config.ContainerCapDrop), + stepPreContainer.Start(true), + ).Finally( + stepPreContainer.Remove().IfBool(!rc.Config.ReuseContainers), + ).Finally(stepPreContainer.Close()) + entrypoint := strings.Fields(eval.Interpolate(ctx, step.getStepModel().With["entrypoint"])) if len(entrypoint) == 0 { if action.Runs.Entrypoint != "" { @@ -331,7 +354,7 @@ func execAsDocker(ctx context.Context, step actionStep, actionName string, based } } stepContainer := newStepContainer(ctx, step, image, cmd, entrypoint) - return common.NewPipelineExecutor( + pipelineExecutor := common.NewPipelineExecutor( prepImage, stepContainer.Pull(forcePull), stepContainer.Remove().IfBool(!rc.Config.ReuseContainers), @@ -339,7 +362,35 @@ func execAsDocker(ctx context.Context, step actionStep, actionName string, based stepContainer.Start(true), ).Finally( stepContainer.Remove().IfBool(!rc.Config.ReuseContainers), - ).Finally(stepContainer.Close())(ctx) + ).Finally(stepContainer.Close()) + + postEntrypoint := strings.Fields(eval.Interpolate(ctx, step.getStepModel().With["post-entrypoint"])) + if len(postEntrypoint) == 0 { + if action.Runs.PostEntrypoint != "" { + postEntrypoint, err = shellquote.Split(action.Runs.PostEntrypoint) + if err != nil { + return err + } + } else { + postEntrypoint = nil + } + } + stepPostContainer := newStepContainer(ctx, step, image, cmd, postEntrypoint) + postPipelineExecutor := common.NewPipelineExecutor( + prepImage, + stepPostContainer.Pull(forcePull), + stepPostContainer.Remove().IfBool(!rc.Config.ReuseContainers), + stepPostContainer.Create(rc.Config.ContainerCapAdd, rc.Config.ContainerCapDrop), + stepPostContainer.Start(true), + ).Finally( + stepPostContainer.Remove().IfBool(!rc.Config.ReuseContainers), + ).Finally(stepPostContainer.Close()) + + return common.NewPipelineExecutor( + prePipelineExecutor, + pipelineExecutor, + postPipelineExecutor, + )(ctx) } func evalDockerArgs(ctx context.Context, step step, action *model.Action, cmd *[]string) {