Skip to content

Commit 4204ed8

Browse files
author
Andrii Chyrva
committed
Fix nektos#2363. Add /pre- and /post-entrypoint handling
1 parent 935e4c3 commit 4204ed8

File tree

2 files changed

+66
-13
lines changed

2 files changed

+66
-13
lines changed

pkg/model/action.go

+13-11
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,19 @@ const (
4949

5050
// ActionRuns are a field in Action
5151
type ActionRuns struct {
52-
Using ActionRunsUsing `yaml:"using"`
53-
Env map[string]string `yaml:"env"`
54-
Main string `yaml:"main"`
55-
Pre string `yaml:"pre"`
56-
PreIf string `yaml:"pre-if"`
57-
Post string `yaml:"post"`
58-
PostIf string `yaml:"post-if"`
59-
Image string `yaml:"image"`
60-
Entrypoint string `yaml:"entrypoint"`
61-
Args []string `yaml:"args"`
62-
Steps []Step `yaml:"steps"`
52+
Using ActionRunsUsing `yaml:"using"`
53+
Env map[string]string `yaml:"env"`
54+
Main string `yaml:"main"`
55+
Pre string `yaml:"pre"`
56+
PreIf string `yaml:"pre-if"`
57+
Post string `yaml:"post"`
58+
PostIf string `yaml:"post-if"`
59+
Image string `yaml:"image"`
60+
PreEntrypoint string `yaml:"pre-entrypoint"`
61+
Entrypoint string `yaml:"entrypoint"`
62+
PostEntrypoint string `yaml:"post-entrypoint"`
63+
Args []string `yaml:"args"`
64+
Steps []Step `yaml:"steps"`
6365
}
6466

6567
// 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.

pkg/runner/action.go

+53-2
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,29 @@ func execAsDocker(ctx context.Context, step actionStep, actionName string, based
319319
cmd = action.Runs.Args
320320
evalDockerArgs(ctx, step, action, &cmd)
321321
}
322+
323+
preEntrypoint := strings.Fields(eval.Interpolate(ctx, step.getStepModel().With["pre-entrypoint"]))
324+
if len(preEntrypoint) == 0 {
325+
if action.Runs.PreEntrypoint != "" {
326+
preEntrypoint, err = shellquote.Split(action.Runs.PreEntrypoint)
327+
if err != nil {
328+
return err
329+
}
330+
} else {
331+
preEntrypoint = nil
332+
}
333+
}
334+
stepPreContainer := newStepContainer(ctx, step, image, cmd, preEntrypoint)
335+
prePipelineExecutor := common.NewPipelineExecutor(
336+
prepImage,
337+
stepPreContainer.Pull(forcePull),
338+
stepPreContainer.Remove().IfBool(!rc.Config.ReuseContainers),
339+
stepPreContainer.Create(rc.Config.ContainerCapAdd, rc.Config.ContainerCapDrop),
340+
stepPreContainer.Start(true),
341+
).Finally(
342+
stepPreContainer.Remove().IfBool(!rc.Config.ReuseContainers),
343+
).Finally(stepPreContainer.Close())
344+
322345
entrypoint := strings.Fields(eval.Interpolate(ctx, step.getStepModel().With["entrypoint"]))
323346
if len(entrypoint) == 0 {
324347
if action.Runs.Entrypoint != "" {
@@ -331,15 +354,43 @@ func execAsDocker(ctx context.Context, step actionStep, actionName string, based
331354
}
332355
}
333356
stepContainer := newStepContainer(ctx, step, image, cmd, entrypoint)
334-
return common.NewPipelineExecutor(
357+
pipelineExecutor := common.NewPipelineExecutor(
335358
prepImage,
336359
stepContainer.Pull(forcePull),
337360
stepContainer.Remove().IfBool(!rc.Config.ReuseContainers),
338361
stepContainer.Create(rc.Config.ContainerCapAdd, rc.Config.ContainerCapDrop),
339362
stepContainer.Start(true),
340363
).Finally(
341364
stepContainer.Remove().IfBool(!rc.Config.ReuseContainers),
342-
).Finally(stepContainer.Close())(ctx)
365+
).Finally(stepContainer.Close())
366+
367+
postEntrypoint := strings.Fields(eval.Interpolate(ctx, step.getStepModel().With["post-entrypoint"]))
368+
if len(postEntrypoint) == 0 {
369+
if action.Runs.PostEntrypoint != "" {
370+
postEntrypoint, err = shellquote.Split(action.Runs.PostEntrypoint)
371+
if err != nil {
372+
return err
373+
}
374+
} else {
375+
postEntrypoint = nil
376+
}
377+
}
378+
stepPostContainer := newStepContainer(ctx, step, image, cmd, postEntrypoint)
379+
postPipelineExecutor := common.NewPipelineExecutor(
380+
prepImage,
381+
stepPostContainer.Pull(forcePull),
382+
stepPostContainer.Remove().IfBool(!rc.Config.ReuseContainers),
383+
stepPostContainer.Create(rc.Config.ContainerCapAdd, rc.Config.ContainerCapDrop),
384+
stepPostContainer.Start(true),
385+
).Finally(
386+
stepPostContainer.Remove().IfBool(!rc.Config.ReuseContainers),
387+
).Finally(stepPostContainer.Close())
388+
389+
return common.NewPipelineExecutor(
390+
prePipelineExecutor,
391+
pipelineExecutor,
392+
postPipelineExecutor,
393+
)(ctx)
343394
}
344395

345396
func evalDockerArgs(ctx context.Context, step step, action *model.Action, cmd *[]string) {

0 commit comments

Comments
 (0)