@@ -3,6 +3,7 @@ package runner
33import (
44 "archive/tar"
55 "bufio"
6+ "bytes"
67 "context"
78 "crypto/rand"
89 "crypto/sha256"
@@ -50,6 +51,7 @@ type RunContext struct {
5051 Masks []string
5152 cleanUpJobContainer common.Executor
5253 caller * caller // job calling this RunContext (reusable workflows)
54+ nodeToolFullPath string
5355}
5456
5557func (rc * RunContext ) AddMask (mask string ) {
@@ -432,6 +434,48 @@ func (rc *RunContext) execJobContainer(cmd []string, env map[string]string, user
432434 }
433435}
434436
437+ func (rc * RunContext ) InitializeNodeTool () common.Executor {
438+ return func (ctx context.Context ) error {
439+ rc .GetNodeToolFullPath (ctx )
440+ return nil
441+ }
442+ }
443+
444+ func (rc * RunContext ) GetNodeToolFullPath (ctx context.Context ) string {
445+ if rc .nodeToolFullPath == "" {
446+ timeed , cancel := context .WithTimeout (ctx , time .Minute )
447+ defer cancel ()
448+ path := rc .JobContainer .GetPathVariableName ()
449+ cenv := map [string ]string {}
450+ var cpath string
451+ if err := rc .JobContainer .UpdateFromImageEnv (& cenv )(ctx ); err == nil {
452+ if p , ok := cenv [path ]; ok {
453+ cpath = p
454+ }
455+ }
456+ if len (cpath ) == 0 {
457+ cpath = rc .JobContainer .DefaultPathVariable ()
458+ }
459+ cenv [path ] = cpath
460+ hout := & bytes.Buffer {}
461+ herr := & bytes.Buffer {}
462+ stdout , stderr := rc .JobContainer .ReplaceLogWriter (hout , herr )
463+ err := rc .execJobContainer ([]string {"node" , "--no-warnings" , "-e" , "console.log(process.execPath)" },
464+ cenv , "" , "" ).
465+ Finally (func (context.Context ) error {
466+ rc .JobContainer .ReplaceLogWriter (stdout , stderr )
467+ return nil
468+ })(timeed )
469+ rawStr := strings .Trim (hout .String (), "\r \n " )
470+ if err == nil && ! strings .ContainsAny (rawStr , "\r \n " ) {
471+ rc .nodeToolFullPath = rawStr
472+ } else {
473+ rc .nodeToolFullPath = "node"
474+ }
475+ }
476+ return rc .nodeToolFullPath
477+ }
478+
435479func (rc * RunContext ) ApplyExtraPath (ctx context.Context , env * map [string ]string ) {
436480 if rc .ExtraPath != nil && len (rc .ExtraPath ) > 0 {
437481 path := rc .JobContainer .GetPathVariableName ()
0 commit comments