Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2363. Add /pre- and /post-entrypoint handling #2377

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions pkg/model/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
55 changes: 53 additions & 2 deletions pkg/runner/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,29 @@
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

Check warning on line 328 in pkg/runner/action.go

View check run for this annotation

Codecov / codecov/patch

pkg/runner/action.go#L326-L328

Added lines #L326 - L328 were not covered by tests
}
} 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 != "" {
Expand All @@ -331,15 +354,43 @@
}
}
stepContainer := newStepContainer(ctx, step, image, cmd, entrypoint)
return common.NewPipelineExecutor(
pipelineExecutor := common.NewPipelineExecutor(
prepImage,
stepContainer.Pull(forcePull),
stepContainer.Remove().IfBool(!rc.Config.ReuseContainers),
stepContainer.Create(rc.Config.ContainerCapAdd, rc.Config.ContainerCapDrop),
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

Check warning on line 372 in pkg/runner/action.go

View check run for this annotation

Codecov / codecov/patch

pkg/runner/action.go#L370-L372

Added lines #L370 - L372 were not covered by tests
}
} 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) {
Expand Down
Loading