diff --git a/pkg/runner/action.go b/pkg/runner/action.go index b46a4d03a75..9d4b46827ad 100644 --- a/pkg/runner/action.go +++ b/pkg/runner/action.go @@ -170,7 +170,7 @@ func runActionImpl(step actionStep, actionDir string, remoteAction *remoteAction } actionLocation := path.Join(actionDir, actionPath) - actionName, containerActionDir := getContainerActionPaths(stepModel, actionLocation, rc) + actionName, containerActionDir := getContainerActionPaths(ctx, stepModel, actionLocation, rc) 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) @@ -459,7 +459,7 @@ func populateEnvsFromInput(ctx context.Context, env *map[string]string, action * } } -func getContainerActionPaths(step *model.Step, actionDir string, rc *RunContext) (string, string) { +func getContainerActionPaths(ctx context.Context, step *model.Step, actionDir string, rc *RunContext) (string, string) { actionName := "" containerActionDir := "." if step.Type() != model.StepTypeUsesActionRemote { @@ -477,7 +477,7 @@ func getContainerActionPaths(step *model.Step, actionDir string, rc *RunContext) actionName = strings.ReplaceAll(actionName, "\\", "/") } } - return actionName, containerActionDir + return actionName, rc.GetCanonicalActionPath(ctx, containerActionDir) } func getOsSafeRelativePath(s, prefix string) string { @@ -546,7 +546,7 @@ func runPreStep(step actionStep) common.Executor { actionLocation = actionDir } - actionName, containerActionDir := getContainerActionPaths(stepModel, actionLocation, rc) + actionName, containerActionDir := getContainerActionPaths(ctx, stepModel, actionLocation, rc) x := action.Runs.Using switch { @@ -650,7 +650,7 @@ func runPostStep(step actionStep) common.Executor { actionLocation = actionDir } - actionName, containerActionDir := getContainerActionPaths(stepModel, actionLocation, rc) + actionName, containerActionDir := getContainerActionPaths(ctx, stepModel, actionLocation, rc) x := action.Runs.Using switch { diff --git a/pkg/runner/run_context.go b/pkg/runner/run_context.go index 5d4277123ed..001983f854f 100644 --- a/pkg/runner/run_context.go +++ b/pkg/runner/run_context.go @@ -451,6 +451,37 @@ func (rc *RunContext) InitializeNodeTool() common.Executor { } } +func (rc *RunContext) GetCanonicalActionPath(ctx context.Context, actionPath string) string { + timeed, cancel := context.WithTimeout(ctx, time.Minute) + defer cancel() + path := rc.JobContainer.GetPathVariableName() + cenv := map[string]string{} + var cpath string + if err := rc.JobContainer.UpdateFromImageEnv(&cenv)(ctx); err == nil { + if p, ok := cenv[path]; ok { + cpath = p + } + } + if len(cpath) == 0 { + cpath = rc.JobContainer.DefaultPathVariable() + } + cenv[path] = cpath + hout := &bytes.Buffer{} + herr := &bytes.Buffer{} + stdout, stderr := rc.JobContainer.ReplaceLogWriter(hout, herr) + err := rc.execJobContainer([]string{"readlink", "-f", actionPath}, + cenv, "", ""). + Finally(func(context.Context) error { + rc.JobContainer.ReplaceLogWriter(stdout, stderr) + return nil + })(timeed) + rawStr := strings.Trim(hout.String(), "\r\n") + if err == nil && !strings.ContainsAny(rawStr, "\r\n") { + return rawStr + } + return actionPath +} + func (rc *RunContext) GetNodeToolFullPath(ctx context.Context) string { if rc.nodeToolFullPath == "" { timeed, cancel := context.WithTimeout(ctx, time.Minute) diff --git a/pkg/runner/step_action_local.go b/pkg/runner/step_action_local.go index 4bb85bf7d64..c5e481487c1 100644 --- a/pkg/runner/step_action_local.go +++ b/pkg/runner/step_action_local.go @@ -43,7 +43,7 @@ func (sal *stepActionLocal) main() common.Executor { actionDir := filepath.Join(sal.getRunContext().Config.Workdir, sal.Step.Uses) localReader := func(ctx context.Context) actionYamlReader { - _, cpath := getContainerActionPaths(sal.Step, path.Join(actionDir, ""), sal.RunContext) + _, cpath := getContainerActionPaths(ctx, sal.Step, path.Join(actionDir, ""), sal.RunContext) return func(filename string) (io.Reader, io.Closer, error) { spath := path.Join(cpath, filename) for i := 0; i < maxSymlinkDepth; i++ { @@ -121,7 +121,7 @@ func (sal *stepActionLocal) getActionModel() *model.Action { func (sal *stepActionLocal) getCompositeRunContext(ctx context.Context) *RunContext { if sal.compositeRunContext == nil { actionDir := filepath.Join(sal.RunContext.Config.Workdir, sal.Step.Uses) - _, containerActionDir := getContainerActionPaths(sal.getStepModel(), actionDir, sal.RunContext) + _, containerActionDir := getContainerActionPaths(ctx, sal.getStepModel(), actionDir, sal.RunContext) sal.compositeRunContext = newCompositeRunContext(ctx, sal.RunContext, sal, containerActionDir) sal.compositeSteps = sal.compositeRunContext.compositeExecutor(sal.action) diff --git a/pkg/runner/step_action_remote.go b/pkg/runner/step_action_remote.go index 4c1ef353278..fb8f50b5c90 100644 --- a/pkg/runner/step_action_remote.go +++ b/pkg/runner/step_action_remote.go @@ -228,7 +228,7 @@ func (sar *stepActionRemote) getCompositeRunContext(ctx context.Context) *RunCon if sar.compositeRunContext == nil { actionDir := fmt.Sprintf("%s/%s", sar.RunContext.ActionCacheDir(), safeFilename(sar.Step.Uses)) actionLocation := path.Join(actionDir, sar.remoteAction.Path) - _, containerActionDir := getContainerActionPaths(sar.getStepModel(), actionLocation, sar.RunContext) + _, containerActionDir := getContainerActionPaths(ctx, sar.getStepModel(), actionLocation, sar.RunContext) sar.compositeRunContext = newCompositeRunContext(ctx, sar.RunContext, sar, containerActionDir) sar.compositeSteps = sar.compositeRunContext.compositeExecutor(sar.action)