@@ -4,14 +4,13 @@ import (
44 "context"
55 "fmt"
66 "io"
7- "log"
87 "os"
98 "path/filepath"
109 "strings"
1110
12- "github.com/kballard/go-shellquote"
1311 "github.com/actions-oss/act-cli/pkg/common"
1412 "github.com/actions-oss/act-cli/pkg/container"
13+ "github.com/kballard/go-shellquote"
1514)
1615
1716type Environment struct {
@@ -24,20 +23,32 @@ type Environment struct {
2423
2524// "/Volumes/My Shared Files/act/"
2625func (e * Environment ) ToHostPath (path string ) string {
27- actPath := filepath .Clean ("/private/tmp/act/" )
28- altPath := filepath .Clean (path )
29- if strings .HasPrefix (altPath , actPath ) {
30- return e .Miscpath + altPath [len (actPath ):]
31- }
32- return altPath
26+ return e .translatePath (path , false )
3327}
3428
3529func (e * Environment ) ToContainerPath (path string ) string {
3630 path = e .HostEnvironment .ToContainerPath (path )
37- actPath := filepath .Clean (e .Miscpath )
31+ return e .translatePath (path , true )
32+ }
33+
34+ func (e * Environment ) translatePath (path string , reverse bool ) string {
35+ mounts := map [string ]string {
36+ "/private/tmp/act" : e .Miscpath ,
37+ "/private/tmp/tool_cache" : e .ToolCache ,
38+ }
3839 altPath := filepath .Clean (path )
39- if strings .HasPrefix (altPath , actPath ) {
40- return "/private/tmp/act/" + altPath [len (actPath ):]
40+ for k , v := range mounts {
41+ if reverse {
42+ v , k = k , v
43+ }
44+ actPath := filepath .Clean (k )
45+ add := 0
46+ if strings .HasPrefix (altPath , actPath + "/" ) {
47+ add = 1
48+ }
49+ if altPath == actPath || add > 0 {
50+ return filepath .Join (v , altPath [len (actPath )+ add :])
51+ }
4152 }
4253 return altPath
4354}
@@ -71,35 +82,39 @@ func (e *Environment) start(ctx context.Context) error {
7182
7283 config := e .Config
7384
85+ config .Writer = e .StdOut
86+
7487 if config .AlwaysPull {
75- log . Printf ("Pulling the latest version of %s...\n " , actEnv .JobImage )
88+ common . Logger ( ctx ). Infof ("Pulling the latest version of %s...\n " , actEnv .JobImage )
7689 _ , _ , err := ExecWithEnv (ctx , nil ,
7790 "pull" , actEnv .JobImage )
7891 if err != nil {
7992 return err
8093 }
8194 }
8295
83- log . Println ("Cloning and configuring a new VM..." )
96+ common . Logger ( ctx ). Info ("Cloning and configuring a new VM..." )
8497 vm , err := CreateNewVM (ctx , * actEnv , 0 , 0 )
8598 if err != nil {
8699 _ = e .Stop (ctx )
87100 return err
88101 }
89102 var customDirectoryMounts []string
90- _ = os .MkdirAll (e .Miscpath , 0666 )
103+ _ = os .MkdirAll (e .Miscpath , 0777 )
104+ _ = os .MkdirAll (e .ToolCache , 0777 )
91105 customDirectoryMounts = append (customDirectoryMounts , "act:" + e .Miscpath )
106+ customDirectoryMounts = append (customDirectoryMounts , "tool_cache:" + e .ToolCache )
92107 e .vm = vm
93- err = vm .Start (config , actEnv , customDirectoryMounts )
108+ err = vm .Start (ctx , config , actEnv , customDirectoryMounts )
94109 if err != nil {
95110 _ = e .Stop (ctx )
96111 return err
97112 }
98113
99- return e .execRaw (ctx , "ln -sf '/Volumes/My Shared Files/act' /private/tmp/act" )
114+ return e .execRaw (ctx , "ln -sf '/Volumes/My Shared Files/act' /private/tmp/act && ln -sf '/Volumes/My Shared Files/tool_cache' /private/tmp/tool_cache " )
100115}
101116func (e * Environment ) Stop (ctx context.Context ) error {
102- log . Println ( "Stop VM? " )
117+ common . Logger ( ctx ). Debug ( "Preparing stopping VM " )
103118
104119 actEnv := e .Env
105120
@@ -110,12 +125,12 @@ func (e *Environment) Stop(ctx context.Context) error {
110125 vm = ExistingVM (* actEnv )
111126 }
112127
113- if err := vm .Stop (); err != nil {
114- log . Printf ("Failed to stop VM: %v" , err )
128+ if err := vm .Stop (ctx ); err != nil {
129+ common . Logger ( ctx ). Errorf ("Failed to stop VM: %v" , err )
115130 }
116131
117- if err := vm .Delete (); err != nil {
118- log . Printf ("Failed to delete VM: %v" , err )
132+ if err := vm .Delete (ctx ); err != nil {
133+ common . Logger ( ctx ). Error ("Failed to delete VM: %v" , err )
119134
120135 return err
121136 }
@@ -126,7 +141,7 @@ func (e *Environment) Stop(ctx context.Context) error {
126141func (e * Environment ) Remove () common.Executor {
127142 return func (ctx context.Context ) error {
128143 _ = e .Stop (ctx )
129- log . Println ( "Remove VM? " )
144+ common . Logger ( ctx ). Debug ( "Stopped VM, removing... " )
130145 if e .CleanUp != nil {
131146 e .CleanUp ()
132147 }
@@ -162,9 +177,6 @@ func (e *Environment) execRaw(ctx context.Context, script string) error {
162177 vm = ExistingVM (* actEnv )
163178 }
164179
165- // Monitor "tart run" command's output so it's not silenced
166- go vm .MonitorTartRunOutput ()
167-
168180 config := e .Config
169181
170182 ssh , err := vm .OpenSSH (ctx , config )
@@ -179,7 +191,7 @@ func (e *Environment) execRaw(ctx context.Context, script string) error {
179191 }
180192 defer session .Close ()
181193
182- os . Stdout . WriteString (script + " \n " )
194+ common . Logger ( ctx ). Debug (script )
183195
184196 session .Stdin = strings .NewReader (
185197 script ,
0 commit comments