Skip to content

Commit 140cfd1

Browse files
authored
Merge branch 'master' into patch-1
2 parents eb6e07b + e374ef9 commit 140cfd1

File tree

12 files changed

+153
-54
lines changed

12 files changed

+153
-54
lines changed
File renamed without changes.

pkg/model/action.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (a *ActionRunsUsing) UnmarshalYAML(unmarshal func(interface{}) error) error
2121
// Force input to lowercase for case insensitive comparison
2222
format := ActionRunsUsing(strings.ToLower(using))
2323
switch format {
24-
case ActionRunsUsingNode20, ActionRunsUsingNode16, ActionRunsUsingNode12, ActionRunsUsingDocker, ActionRunsUsingComposite:
24+
case ActionRunsUsingNode24, ActionRunsUsingNode20, ActionRunsUsingNode16, ActionRunsUsingNode12, ActionRunsUsingDocker, ActionRunsUsingComposite:
2525
*a = format
2626
default:
2727
return fmt.Errorf("The runs.using key in action.yml must be one of: %v, got %s", []string{
@@ -30,6 +30,7 @@ func (a *ActionRunsUsing) UnmarshalYAML(unmarshal func(interface{}) error) error
3030
ActionRunsUsingNode12,
3131
ActionRunsUsingNode16,
3232
ActionRunsUsingNode20,
33+
ActionRunsUsingNode24,
3334
}, format)
3435
}
3536
return nil
@@ -42,12 +43,31 @@ const (
4243
ActionRunsUsingNode16 = "node16"
4344
// ActionRunsUsingNode20 for running with node20
4445
ActionRunsUsingNode20 = "node20"
46+
// ActionRunsUsingNode24 for running with node24
47+
ActionRunsUsingNode24 = "node24"
4548
// ActionRunsUsingDocker for running with docker
4649
ActionRunsUsingDocker = "docker"
4750
// ActionRunsUsingComposite for running composite
4851
ActionRunsUsingComposite = "composite"
4952
)
5053

54+
func (a ActionRunsUsing) IsNode() bool {
55+
switch a {
56+
case ActionRunsUsingNode12, ActionRunsUsingNode16, ActionRunsUsingNode20, ActionRunsUsingNode24:
57+
return true
58+
default:
59+
return false
60+
}
61+
}
62+
63+
func (a ActionRunsUsing) IsDocker() bool {
64+
return a == ActionRunsUsingDocker
65+
}
66+
67+
func (a ActionRunsUsing) IsComposite() bool {
68+
return a == ActionRunsUsingComposite
69+
}
70+
5171
// ActionRuns are a field in Action
5272
type ActionRuns struct {
5373
Using ActionRunsUsing `yaml:"using"`

pkg/model/workflow.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,6 @@ func (j *Job) Matrix() map[string][]interface{} {
390390

391391
// GetMatrixes returns the matrix cross product
392392
// It skips includes and hard fails excludes for non-existing keys
393-
//
394-
//nolint:gocyclo
395393
func (j *Job) GetMatrixes() ([]map[string]interface{}, error) {
396394
matrixes := make([]map[string]interface{}, 0)
397395
if j.Strategy != nil {
@@ -406,31 +404,11 @@ func (j *Job) GetMatrixes() ([]map[string]interface{}, error) {
406404
case []interface{}:
407405
for _, i := range t {
408406
i := i.(map[string]interface{})
409-
extraInclude := true
410-
for k := range i {
411-
if _, ok := m[k]; ok {
412-
includes = append(includes, i)
413-
extraInclude = false
414-
break
415-
}
416-
}
417-
if extraInclude {
418-
extraIncludes = append(extraIncludes, i)
419-
}
407+
includes = append(includes, i)
420408
}
421409
case interface{}:
422410
v := v.(map[string]interface{})
423-
extraInclude := true
424-
for k := range v {
425-
if _, ok := m[k]; ok {
426-
includes = append(includes, v)
427-
extraInclude = false
428-
break
429-
}
430-
}
431-
if extraInclude {
432-
extraIncludes = append(extraIncludes, v)
433-
}
411+
includes = append(includes, v)
434412
}
435413
}
436414
delete(m, "include")

pkg/model/workflow_test.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"testing"
66

77
"github.com/stretchr/testify/assert"
8+
"github.com/stretchr/testify/require"
9+
"gopkg.in/yaml.v3"
810
)
911

1012
func TestReadWorkflow_StringEvent(t *testing.T) {
@@ -367,10 +369,9 @@ func TestReadWorkflow_Strategy(t *testing.T) {
367369
assert.NoError(t, err)
368370
assert.Equal(t, matrixes,
369371
[]map[string]interface{}{
370-
{"datacenter": "site-c", "node-version": "14.x", "site": "staging"},
371-
{"datacenter": "site-c", "node-version": "16.x", "site": "staging"},
372-
{"datacenter": "site-d", "node-version": "16.x", "site": "staging"},
373-
{"php-version": 5.4},
372+
{"datacenter": "site-c", "node-version": "14.x", "site": "staging", "php-version": 5.4},
373+
{"datacenter": "site-c", "node-version": "16.x", "site": "staging", "php-version": 5.4},
374+
{"datacenter": "site-d", "node-version": "16.x", "site": "staging", "php-version": 5.4},
374375
{"datacenter": "site-a", "node-version": "10.x", "site": "prod"},
375376
{"datacenter": "site-b", "node-version": "12.x", "site": "dev"},
376377
},
@@ -394,6 +395,32 @@ func TestReadWorkflow_Strategy(t *testing.T) {
394395
assert.Equal(t, job.Strategy.FailFast, false)
395396
}
396397

398+
func TestMatrixOnlyIncludes(t *testing.T) {
399+
matrix := map[string][]interface{}{
400+
"include": []interface{}{
401+
map[string]interface{}{"a": "1", "b": "2"},
402+
map[string]interface{}{"a": "3", "b": "4"},
403+
},
404+
}
405+
rN := yaml.Node{}
406+
err := rN.Encode(matrix)
407+
require.NoError(t, err, "encoding matrix should succeed")
408+
job := &Job{
409+
Strategy: &Strategy{
410+
RawMatrix: rN,
411+
},
412+
}
413+
assert.Equal(t, job.Matrix(), matrix)
414+
matrixes, err := job.GetMatrixes()
415+
require.NoError(t, err)
416+
assert.Equal(t, matrixes,
417+
[]map[string]interface{}{
418+
{"a": "1", "b": "2"},
419+
{"a": "3", "b": "4"},
420+
},
421+
)
422+
}
423+
397424
func TestStep_ShellCommand(t *testing.T) {
398425
tests := []struct {
399426
shell string

pkg/runner/action.go

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,9 @@ func runActionImpl(step actionStep, actionDir string, remoteAction *remoteAction
174174

175175
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)
176176

177-
switch action.Runs.Using {
178-
case model.ActionRunsUsingNode12, model.ActionRunsUsingNode16, model.ActionRunsUsingNode20:
177+
x := action.Runs.Using
178+
switch {
179+
case x.IsNode():
179180
if err := maybeCopyToActionDir(ctx, step, actionDir, actionPath, containerActionDir); err != nil {
180181
return err
181182
}
@@ -185,13 +186,13 @@ func runActionImpl(step actionStep, actionDir string, remoteAction *remoteAction
185186
rc.ApplyExtraPath(ctx, step.getEnv())
186187

187188
return rc.execJobContainer(containerArgs, *step.getEnv(), "", "")(ctx)
188-
case model.ActionRunsUsingDocker:
189+
case x.IsDocker():
189190
if remoteAction == nil {
190191
actionDir = ""
191192
actionPath = containerActionDir
192193
}
193194
return execAsDocker(ctx, step, actionName, actionDir, actionPath, remoteAction == nil, "entrypoint")
194-
case model.ActionRunsUsingComposite:
195+
case x.IsComposite():
195196
if err := maybeCopyToActionDir(ctx, step, actionDir, actionPath, containerActionDir); err != nil {
196197
return err
197198
}
@@ -203,6 +204,7 @@ func runActionImpl(step actionStep, actionDir string, remoteAction *remoteAction
203204
model.ActionRunsUsingNode12,
204205
model.ActionRunsUsingNode16,
205206
model.ActionRunsUsingNode20,
207+
model.ActionRunsUsingNode24,
206208
model.ActionRunsUsingComposite,
207209
}, action.Runs.Using)
208210
}
@@ -406,13 +408,18 @@ func newStepContainer(ctx context.Context, step step, image string, cmd []string
406408

407409
binds, mounts := rc.GetBindsAndMounts()
408410
networkMode := fmt.Sprintf("container:%s", rc.jobContainerName())
411+
var workdir string
409412
if rc.IsHostEnv(ctx) {
410413
networkMode = "default"
414+
ext := container.LinuxContainerEnvironmentExtensions{}
415+
workdir = ext.ToContainerPath(rc.Config.Workdir)
416+
} else {
417+
workdir = rc.JobContainer.ToContainerPath(rc.Config.Workdir)
411418
}
412419
stepContainer := container.NewContainer(&container.NewContainerInput{
413420
Cmd: cmd,
414421
Entrypoint: entrypoint,
415-
WorkingDir: rc.JobContainer.ToContainerPath(rc.Config.Workdir),
422+
WorkingDir: workdir,
416423
Image: image,
417424
Username: rc.Config.Secrets["DOCKER_USERNAME"],
418425
Password: rc.Config.Secrets["DOCKER_PASSWORD"],
@@ -499,12 +506,10 @@ func shouldRunPreStep(step actionStep) common.Conditional {
499506
func hasPreStep(step actionStep) common.Conditional {
500507
return func(_ context.Context) bool {
501508
action := step.getActionModel()
502-
return (action.Runs.Using == model.ActionRunsUsingComposite) ||
503-
((action.Runs.Using == model.ActionRunsUsingNode12 ||
504-
action.Runs.Using == model.ActionRunsUsingNode16 ||
505-
action.Runs.Using == model.ActionRunsUsingNode20) &&
509+
return action.Runs.Using.IsComposite() ||
510+
(action.Runs.Using.IsNode() &&
506511
action.Runs.Pre != "") ||
507-
(action.Runs.Using == model.ActionRunsUsingDocker &&
512+
(action.Runs.Using.IsDocker() &&
508513
action.Runs.PreEntrypoint != "")
509514
}
510515
}
@@ -543,8 +548,9 @@ func runPreStep(step actionStep) common.Executor {
543548

544549
actionName, containerActionDir := getContainerActionPaths(stepModel, actionLocation, rc)
545550

546-
switch action.Runs.Using {
547-
case model.ActionRunsUsingNode12, model.ActionRunsUsingNode16, model.ActionRunsUsingNode20:
551+
x := action.Runs.Using
552+
switch {
553+
case x.IsNode():
548554
if err := maybeCopyToActionDir(ctx, step, actionDir, actionPath, containerActionDir); err != nil {
549555
return err
550556
}
@@ -556,14 +562,14 @@ func runPreStep(step actionStep) common.Executor {
556562

557563
return rc.execJobContainer(containerArgs, *step.getEnv(), "", "")(ctx)
558564

559-
case model.ActionRunsUsingDocker:
565+
case x.IsDocker():
560566
if remoteAction == nil {
561567
actionDir = ""
562568
actionPath = containerActionDir
563569
}
564570
return execAsDocker(ctx, step, actionName, actionDir, actionPath, remoteAction == nil, "pre-entrypoint")
565571

566-
case model.ActionRunsUsingComposite:
572+
case x.IsComposite():
567573
if step.getCompositeSteps() == nil {
568574
step.getCompositeRunContext(ctx)
569575
}
@@ -607,12 +613,10 @@ func shouldRunPostStep(step actionStep) common.Conditional {
607613
func hasPostStep(step actionStep) common.Conditional {
608614
return func(_ context.Context) bool {
609615
action := step.getActionModel()
610-
return (action.Runs.Using == model.ActionRunsUsingComposite) ||
611-
((action.Runs.Using == model.ActionRunsUsingNode12 ||
612-
action.Runs.Using == model.ActionRunsUsingNode16 ||
613-
action.Runs.Using == model.ActionRunsUsingNode20) &&
616+
return action.Runs.Using.IsComposite() ||
617+
(action.Runs.Using.IsNode() &&
614618
action.Runs.Post != "") ||
615-
(action.Runs.Using == model.ActionRunsUsingDocker &&
619+
(action.Runs.Using.IsDocker() &&
616620
action.Runs.PostEntrypoint != "")
617621
}
618622
}
@@ -648,9 +652,9 @@ func runPostStep(step actionStep) common.Executor {
648652

649653
actionName, containerActionDir := getContainerActionPaths(stepModel, actionLocation, rc)
650654

651-
switch action.Runs.Using {
652-
case model.ActionRunsUsingNode12, model.ActionRunsUsingNode16, model.ActionRunsUsingNode20:
653-
655+
x := action.Runs.Using
656+
switch {
657+
case x.IsNode():
654658
populateEnvsFromSavedState(step.getEnv(), step, rc)
655659
populateEnvsFromInput(ctx, step.getEnv(), step.getActionModel(), rc)
656660

@@ -661,14 +665,14 @@ func runPostStep(step actionStep) common.Executor {
661665

662666
return rc.execJobContainer(containerArgs, *step.getEnv(), "", "")(ctx)
663667

664-
case model.ActionRunsUsingDocker:
668+
case x.IsDocker():
665669
if remoteAction == nil {
666670
actionDir = ""
667671
actionPath = containerActionDir
668672
}
669673
return execAsDocker(ctx, step, actionName, actionDir, actionPath, remoteAction == nil, "post-entrypoint")
670674

671-
case model.ActionRunsUsingComposite:
675+
case x.IsComposite():
672676
if err := maybeCopyToActionDir(ctx, step, actionDir, actionPath, containerActionDir); err != nil {
673677
return err
674678
}

pkg/runner/run_context.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ func (rc *RunContext) GetBindsAndMounts() ([]string, map[string]string) {
139139

140140
ext := container.LinuxContainerEnvironmentExtensions{}
141141

142+
if hostEnv, ok := rc.JobContainer.(*container.HostEnvironment); ok {
143+
mounts := map[string]string{}
144+
// Permission issues?
145+
// binds = append(binds, hostEnv.ToolCache+":/opt/hostedtoolcache")
146+
binds = append(binds, hostEnv.GetActPath()+":"+ext.GetActPath())
147+
binds = append(binds, hostEnv.ToContainerPath(rc.Config.Workdir)+":"+ext.ToContainerPath(rc.Config.Workdir))
148+
return binds, mounts
149+
}
142150
mounts := map[string]string{
143151
"act-toolcache": "/opt/hostedtoolcache",
144152
name + "-env": ext.GetActPath(),

pkg/runner/runner_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func init() {
3939

4040
platforms = map[string]string{
4141
"ubuntu-latest": baseImage,
42+
"self-hosted": "-self-hosted",
4243
}
4344

4445
if l := os.Getenv("ACT_TEST_LOG_LEVEL"); l != "" {
@@ -330,6 +331,9 @@ func TestRunEvent(t *testing.T) {
330331

331332
// local remote action overrides
332333
{workdir, "local-remote-action-overrides", "push", "", platforms, secrets},
334+
335+
// docker action on host executor
336+
{workdir, "docker-action-host-env", "push", "", platforms, secrets},
333337
}
334338

335339
for _, table := range tables {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM debian:bullseye-slim
2+
3+
# Install dependencies
4+
RUN apt-get update && apt-get install -y \
5+
curl \
6+
&& apt-get clean
7+
8+
# Copy the entrypoint script
9+
COPY entrypoint.sh /entrypoint.sh
10+
RUN chmod +x /entrypoint.sh
11+
12+
# Set the entrypoint
13+
ENTRYPOINT ["/entrypoint.sh"]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: "Hello World Docker Action"
2+
description: "A simple Docker action that prints Hello, World! and environment variables."
3+
inputs:
4+
who-to-greet:
5+
description: "Who to greet"
6+
required: false
7+
default: "World"
8+
runs:
9+
using: "docker"
10+
image: "Dockerfile"
11+
args:
12+
- ${{ inputs.who-to-greet }}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Print a greeting
5+
echo "Hello, $1!"
6+
7+
# Print all environment variables
8+
echo "Environment Variables:"
9+
env
10+
11+
ls -la "$PWD"
12+
ls -la "$PWD/docker-action-host-env"
13+
14+
if [ -f "$PWD/docker-action-host-env/Dockerfile" ]; then
15+
echo "Dockerfile exists in workspace."
16+
else
17+
echo "Dockerfile does not exist in workspace."
18+
fi

0 commit comments

Comments
 (0)