Skip to content
Open
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
10 changes: 5 additions & 5 deletions pkg/runner/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
31 changes: 31 additions & 0 deletions pkg/runner/run_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/runner/step_action_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++ {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/runner/step_action_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down