@@ -3,6 +3,7 @@ package runner
3
3
import (
4
4
"archive/tar"
5
5
"bufio"
6
+ "bytes"
6
7
"context"
7
8
"crypto/rand"
8
9
"crypto/sha256"
@@ -50,6 +51,7 @@ type RunContext struct {
50
51
Masks []string
51
52
cleanUpJobContainer common.Executor
52
53
caller * caller // job calling this RunContext (reusable workflows)
54
+ nodeToolFullPath string
53
55
}
54
56
55
57
func (rc * RunContext ) AddMask (mask string ) {
@@ -432,6 +434,48 @@ func (rc *RunContext) execJobContainer(cmd []string, env map[string]string, user
432
434
}
433
435
}
434
436
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
+
435
479
func (rc * RunContext ) ApplyExtraPath (ctx context.Context , env * map [string ]string ) {
436
480
if rc .ExtraPath != nil && len (rc .ExtraPath ) > 0 {
437
481
path := rc .JobContainer .GetPathVariableName ()
0 commit comments