@@ -116,7 +116,7 @@ func readActionImpl(ctx context.Context, step *model.Step, actionDir string, act
116
116
return action , err
117
117
}
118
118
119
- func maybeCopyToActionDir (ctx context.Context , step actionStep , actionDir string , actionPath string , containerActionDir string ) error {
119
+ func maybeCopyToActionDir (ctx context.Context , step actionStep , actionPath string , containerActionDir string ) error {
120
120
logger := common .Logger (ctx )
121
121
rc := step .getRunContext ()
122
122
stepModel := step .getStepModel ()
@@ -133,21 +133,13 @@ func maybeCopyToActionDir(ctx context.Context, step actionStep, actionDir string
133
133
containerActionDirCopy += `/`
134
134
}
135
135
136
- if rc .Config != nil && rc .Config .ActionCache != nil {
137
- raction := step .(* stepActionRemote )
138
- ta , err := rc .Config .ActionCache .GetTarArchive (ctx , raction .cacheDir , raction .resolvedSha , "" )
139
- if err != nil {
140
- return err
141
- }
142
- defer ta .Close ()
143
- return rc .JobContainer .CopyTarStream (ctx , containerActionDirCopy , ta )
144
- }
145
-
146
- if err := removeGitIgnore (ctx , actionDir ); err != nil {
136
+ raction := step .(* stepActionRemote )
137
+ ta , err := rc .getActionCache ().GetTarArchive (ctx , raction .cacheDir , raction .resolvedSha , "" )
138
+ if err != nil {
147
139
return err
148
140
}
149
-
150
- return rc .JobContainer .CopyDir ( containerActionDirCopy , actionDir + "/" , rc . Config . UseGitIgnore )( ctx )
141
+ defer ta . Close ()
142
+ return rc .JobContainer .CopyTarStream ( ctx , containerActionDirCopy , ta )
151
143
}
152
144
153
145
func runActionImpl (step actionStep , actionDir string , remoteAction * remoteAction ) common.Executor {
@@ -176,7 +168,7 @@ func runActionImpl(step actionStep, actionDir string, remoteAction *remoteAction
176
168
177
169
switch action .Runs .Using {
178
170
case model .ActionRunsUsingNode12 , model .ActionRunsUsingNode16 , model .ActionRunsUsingNode20 :
179
- if err := maybeCopyToActionDir (ctx , step , actionDir , actionPath , containerActionDir ); err != nil {
171
+ if err := maybeCopyToActionDir (ctx , step , actionPath , containerActionDir ); err != nil {
180
172
return err
181
173
}
182
174
containerArgs := []string {rc .GetNodeToolFullPath (ctx ), path .Join (containerActionDir , action .Runs .Main )}
@@ -186,13 +178,13 @@ func runActionImpl(step actionStep, actionDir string, remoteAction *remoteAction
186
178
187
179
return rc .execJobContainer (containerArgs , * step .getEnv (), "" , "" )(ctx )
188
180
case model .ActionRunsUsingDocker :
189
- location := actionLocation
190
181
if remoteAction == nil {
191
- location = containerActionDir
182
+ actionDir = ""
183
+ actionPath = containerActionDir
192
184
}
193
- return execAsDocker (ctx , step , actionName , location , remoteAction == nil , "entrypoint" )
185
+ return execAsDocker (ctx , step , actionName , actionDir , actionPath , remoteAction == nil , "entrypoint" )
194
186
case model .ActionRunsUsingComposite :
195
- if err := maybeCopyToActionDir (ctx , step , actionDir , actionPath , containerActionDir ); err != nil {
187
+ if err := maybeCopyToActionDir (ctx , step , actionPath , containerActionDir ); err != nil {
196
188
return err
197
189
}
198
190
@@ -223,27 +215,10 @@ func setupActionEnv(ctx context.Context, step actionStep, _ *remoteAction) error
223
215
return nil
224
216
}
225
217
226
- // https://github.com/nektos/act/issues/228#issuecomment-629709055
227
- // files in .gitignore are not copied in a Docker container
228
- // this causes issues with actions that ignore other important resources
229
- // such as `node_modules` for example
230
- func removeGitIgnore (ctx context.Context , directory string ) error {
231
- gitIgnorePath := path .Join (directory , ".gitignore" )
232
- if _ , err := os .Stat (gitIgnorePath ); err == nil {
233
- // .gitignore exists
234
- common .Logger (ctx ).Debugf ("Removing %s before docker cp" , gitIgnorePath )
235
- err := os .Remove (gitIgnorePath )
236
- if err != nil {
237
- return err
238
- }
239
- }
240
- return nil
241
- }
242
-
243
218
// TODO: break out parts of function to reduce complexicity
244
219
//
245
220
//nolint:gocyclo
246
- func execAsDocker (ctx context.Context , step actionStep , actionName string , basedir string , localAction bool , entrypointType string ) error {
221
+ func execAsDocker (ctx context.Context , step actionStep , actionName , basedir , subpath string , localAction bool , entrypointType string ) error {
247
222
logger := common .Logger (ctx )
248
223
rc := step .getRunContext ()
249
224
action := step .getActionModel ()
@@ -260,7 +235,7 @@ func execAsDocker(ctx context.Context, step actionStep, actionName string, based
260
235
image = fmt .Sprintf ("%s-dockeraction:%s" , regexp .MustCompile ("[^a-zA-Z0-9]" ).ReplaceAllString (actionName , "-" ), "latest" )
261
236
image = fmt .Sprintf ("act-%s" , strings .TrimLeft (image , "-" ))
262
237
image = strings .ToLower (image )
263
- contextDir , fileName := filepath .Split (filepath .Join (basedir , action .Runs .Image ))
238
+ contextDir , fileName := path .Split (path .Join (subpath , action .Runs .Image ))
264
239
265
240
anyArchExists , err := container .ImageExistsLocally (ctx , image , "any" )
266
241
if err != nil {
@@ -291,16 +266,16 @@ func execAsDocker(ctx context.Context, step actionStep, actionName string, based
291
266
return err
292
267
}
293
268
defer buildContext .Close ()
294
- } else if rc . Config . ActionCache != nil {
269
+ } else {
295
270
rstep := step .(* stepActionRemote )
296
- buildContext , err = rc .Config . ActionCache .GetTarArchive (ctx , rstep .cacheDir , rstep .resolvedSha , contextDir )
271
+ buildContext , err = rc .getActionCache () .GetTarArchive (ctx , rstep .cacheDir , rstep .resolvedSha , contextDir )
297
272
if err != nil {
298
273
return err
299
274
}
300
275
defer buildContext .Close ()
301
276
}
302
277
prepImage = container .NewDockerBuildExecutor (container.NewDockerBuildExecutorInput {
303
- ContextDir : contextDir ,
278
+ ContextDir : filepath . Join ( basedir , contextDir ) ,
304
279
Dockerfile : fileName ,
305
280
ImageTag : image ,
306
281
BuildContext : buildContext ,
@@ -324,6 +299,7 @@ func execAsDocker(ctx context.Context, step actionStep, actionName string, based
324
299
if len (entrypoint ) == 0 {
325
300
if entrypointType == "pre-entrypoint" && action .Runs .PreEntrypoint != "" {
326
301
entrypoint , err = shellquote .Split (action .Runs .PreEntrypoint )
302
+
327
303
if err != nil {
328
304
return err
329
305
}
@@ -545,7 +521,7 @@ func runPreStep(step actionStep) common.Executor {
545
521
546
522
switch action .Runs .Using {
547
523
case model .ActionRunsUsingNode12 , model .ActionRunsUsingNode16 , model .ActionRunsUsingNode20 :
548
- if err := maybeCopyToActionDir (ctx , step , actionDir , actionPath , containerActionDir ); err != nil {
524
+ if err := maybeCopyToActionDir (ctx , step , actionPath , containerActionDir ); err != nil {
549
525
return err
550
526
}
551
527
@@ -557,11 +533,11 @@ func runPreStep(step actionStep) common.Executor {
557
533
return rc .execJobContainer (containerArgs , * step .getEnv (), "" , "" )(ctx )
558
534
559
535
case model .ActionRunsUsingDocker :
560
- location := actionLocation
561
536
if remoteAction == nil {
562
- location = containerActionDir
537
+ actionDir = ""
538
+ actionPath = containerActionDir
563
539
}
564
- return execAsDocker (ctx , step , actionName , location , remoteAction == nil , "pre-entrypoint" )
540
+ return execAsDocker (ctx , step , actionName , actionDir , actionPath , remoteAction == nil , "pre-entrypoint" )
565
541
566
542
case model .ActionRunsUsingComposite :
567
543
if step .getCompositeSteps () == nil {
@@ -662,14 +638,14 @@ func runPostStep(step actionStep) common.Executor {
662
638
return rc .execJobContainer (containerArgs , * step .getEnv (), "" , "" )(ctx )
663
639
664
640
case model .ActionRunsUsingDocker :
665
- location := actionLocation
666
641
if remoteAction == nil {
667
- location = containerActionDir
642
+ actionDir = ""
643
+ actionPath = containerActionDir
668
644
}
669
- return execAsDocker (ctx , step , actionName , location , remoteAction == nil , "post-entrypoint" )
645
+ return execAsDocker (ctx , step , actionName , actionDir , actionPath , remoteAction == nil , "post-entrypoint" )
670
646
671
647
case model .ActionRunsUsingComposite :
672
- if err := maybeCopyToActionDir (ctx , step , actionDir , actionPath , containerActionDir ); err != nil {
648
+ if err := maybeCopyToActionDir (ctx , step , actionPath , containerActionDir ); err != nil {
673
649
return err
674
650
}
675
651
0 commit comments