Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherHX committed Oct 29, 2024
1 parent b989239 commit 35918dd
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 107 deletions.
24 changes: 12 additions & 12 deletions pkg/runner/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ func runActionImpl(step actionStep, actionDir string, remoteAction *remoteAction

return rc.execJobContainer(containerArgs, *step.getEnv(), "", "")(ctx)
case model.ActionRunsUsingDocker:
location := actionLocation
if remoteAction == nil {
location = containerActionDir
actionDir = ""
actionPath = containerActionDir
}
return execAsDocker(ctx, step, actionName, location, remoteAction == nil, "entrypoint")
return execAsDocker(ctx, step, actionName, actionDir, actionPath, remoteAction == nil, "entrypoint")
case model.ActionRunsUsingComposite:
if err := maybeCopyToActionDir(ctx, step, actionDir, actionPath, containerActionDir); err != nil {
return err
Expand Down Expand Up @@ -235,7 +235,7 @@ func removeGitIgnore(ctx context.Context, directory string) error {
// TODO: break out parts of function to reduce complexicity
//
//nolint:gocyclo
func execAsDocker(ctx context.Context, step actionStep, actionName string, basedir string, localAction bool, entrypointType string) error {
func execAsDocker(ctx context.Context, step actionStep, actionName, basedir, subpath string, localAction bool, entrypointType string) error {
logger := common.Logger(ctx)
rc := step.getRunContext()
action := step.getActionModel()
Expand All @@ -252,7 +252,7 @@ func execAsDocker(ctx context.Context, step actionStep, actionName string, based
image = fmt.Sprintf("%s-dockeraction:%s", regexp.MustCompile("[^a-zA-Z0-9]").ReplaceAllString(actionName, "-"), "latest")
image = fmt.Sprintf("act-%s", strings.TrimLeft(image, "-"))
image = strings.ToLower(image)
contextDir, fileName := filepath.Split(filepath.Join(basedir, action.Runs.Image))
contextDir, fileName := filepath.Split(filepath.Join(basedir, subpath, action.Runs.Image))

anyArchExists, err := container.ImageExistsLocally(ctx, image, "any")
if err != nil {
Expand Down Expand Up @@ -285,7 +285,7 @@ func execAsDocker(ctx context.Context, step actionStep, actionName string, based
defer buildContext.Close()
} else {
rstep := step.(*stepActionRemote)
buildContext, err = rc.getActionCache().GetTarArchive(ctx, rstep.cacheDir, rstep.resolvedSha, contextDir)
buildContext, err = rc.getActionCache().GetTarArchive(ctx, rstep.cacheDir, rstep.resolvedSha, path.Join(subpath, action.Runs.Image))
if err != nil {
return err
}
Expand Down Expand Up @@ -549,11 +549,11 @@ func runPreStep(step actionStep) common.Executor {
return rc.execJobContainer(containerArgs, *step.getEnv(), "", "")(ctx)

case model.ActionRunsUsingDocker:
location := actionLocation
if remoteAction == nil {
location = containerActionDir
actionDir = ""
actionPath = containerActionDir
}
return execAsDocker(ctx, step, actionName, location, remoteAction == nil, "pre-entrypoint")
return execAsDocker(ctx, step, actionName, actionDir, actionPath, remoteAction == nil, "pre-entrypoint")

case model.ActionRunsUsingComposite:
if step.getCompositeSteps() == nil {
Expand Down Expand Up @@ -654,11 +654,11 @@ func runPostStep(step actionStep) common.Executor {
return rc.execJobContainer(containerArgs, *step.getEnv(), "", "")(ctx)

case model.ActionRunsUsingDocker:
location := actionLocation
if remoteAction == nil {
location = containerActionDir
actionDir = ""
actionPath = containerActionDir
}
return execAsDocker(ctx, step, actionName, location, remoteAction == nil, "post-entrypoint")
return execAsDocker(ctx, step, actionName, actionDir, actionPath, remoteAction == nil, "post-entrypoint")

case model.ActionRunsUsingComposite:
if err := maybeCopyToActionDir(ctx, step, actionDir, actionPath, containerActionDir); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/runner/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ func TestActionRunner(t *testing.T) {
cm := &containerMock{}
cm.On("CopyDir", "/var/run/act/actions/dir/", "dir/", false).Return(func(ctx context.Context) error { return nil })

cacheMock := &TestRepositoryCache{}
cacheMock.On("GetTarArchive", ctx, "", "", "").Return(io.MultiReader())

Check failure on line 233 in pkg/runner/action_test.go

View workflow job for this annotation

GitHub Actions / lint

cacheMock.On undefined (type *TestRepositoryCache has no field or method On) (typecheck)

envMatcher := mock.MatchedBy(func(env map[string]string) bool {
for k, v := range tt.expectedEnv {
if env[k] != v {
Expand All @@ -241,6 +244,7 @@ func TestActionRunner(t *testing.T) {
cm.On("Exec", []string{"node", "/var/run/act/actions/dir/path"}, envMatcher, "", "").Return(func(ctx context.Context) error { return nil })

tt.step.getRunContext().JobContainer = cm
tt.step.getRunContext().Config.ActionCache = cacheMock

err := runActionImpl(tt.step, "dir", newRemoteAction("org/repo/path@ref"))(ctx)

Expand Down
190 changes: 95 additions & 95 deletions pkg/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,102 +227,102 @@ func TestRunEvent(t *testing.T) {

tables := []TestJobFileInfo{
// Shells
{workdir, "shells/defaults", "push", "", platforms, secrets},
// TODO: figure out why it fails
// {workdir, "shells/custom", "push", "", map[string]string{"ubuntu-latest": "catthehacker/ubuntu:pwsh-latest"}, }, // custom image with pwsh
{workdir, "shells/pwsh", "push", "", map[string]string{"ubuntu-latest": "catthehacker/ubuntu:pwsh-latest"}, secrets}, // custom image with pwsh
{workdir, "shells/bash", "push", "", platforms, secrets},
{workdir, "shells/python", "push", "", map[string]string{"ubuntu-latest": "node:16-buster"}, secrets}, // slim doesn't have python
{workdir, "shells/sh", "push", "", platforms, secrets},

// Local action
{workdir, "local-action-docker-url", "push", "", platforms, secrets},
{workdir, "local-action-dockerfile", "push", "", platforms, secrets},
{workdir, "local-action-via-composite-dockerfile", "push", "", platforms, secrets},
{workdir, "local-action-js", "push", "", platforms, secrets},

// Uses
{workdir, "uses-composite", "push", "", platforms, secrets},
{workdir, "uses-composite-with-error", "push", "Job 'failing-composite-action' failed", platforms, secrets},
{workdir, "uses-composite-check-for-input-collision", "push", "", platforms, secrets},
{workdir, "uses-composite-check-for-input-shadowing", "push", "", platforms, secrets},
{workdir, "uses-nested-composite", "push", "", platforms, secrets},
{workdir, "remote-action-composite-js-pre-with-defaults", "push", "", platforms, secrets},
{workdir, "remote-action-composite-action-ref", "push", "", platforms, secrets},
{workdir, "uses-workflow", "push", "", platforms, map[string]string{"secret": "keep_it_private"}},
{workdir, "uses-workflow", "pull_request", "", platforms, map[string]string{"secret": "keep_it_private"}},
{workdir, "uses-docker-url", "push", "", platforms, secrets},
{workdir, "act-composite-env-test", "push", "", platforms, secrets},

// Eval
{workdir, "evalmatrix", "push", "", platforms, secrets},
{workdir, "evalmatrixneeds", "push", "", platforms, secrets},
{workdir, "evalmatrixneeds2", "push", "", platforms, secrets},
{workdir, "evalmatrix-merge-map", "push", "", platforms, secrets},
{workdir, "evalmatrix-merge-array", "push", "", platforms, secrets},
{workdir, "issue-1195", "push", "", platforms, secrets},

{workdir, "basic", "push", "", platforms, secrets},
{workdir, "fail", "push", "exit with `FAILURE`: 1", platforms, secrets},
{workdir, "runs-on", "push", "", platforms, secrets},
{workdir, "checkout", "push", "", platforms, secrets},
{workdir, "job-container", "push", "", platforms, secrets},
{workdir, "job-container-non-root", "push", "", platforms, secrets},
{workdir, "job-container-invalid-credentials", "push", "failed to handle credentials: failed to interpolate container.credentials.password", platforms, secrets},
{workdir, "container-hostname", "push", "", platforms, secrets},
{workdir, "remote-action-docker", "push", "", platforms, secrets},
{workdir, "remote-action-js", "push", "", platforms, secrets},
{workdir, "remote-action-js-node-user", "push", "", platforms, secrets}, // Test if this works with non root container
{workdir, "matrix", "push", "", platforms, secrets},
{workdir, "matrix-include-exclude", "push", "", platforms, secrets},
{workdir, "matrix-exitcode", "push", "Job 'test' failed", platforms, secrets},
{workdir, "commands", "push", "", platforms, secrets},
{workdir, "workdir", "push", "", platforms, secrets},
{workdir, "defaults-run", "push", "", platforms, secrets},
{workdir, "composite-fail-with-output", "push", "", platforms, secrets},
{workdir, "issue-597", "push", "", platforms, secrets},
{workdir, "issue-598", "push", "", platforms, secrets},
{workdir, "if-env-act", "push", "", platforms, secrets},
{workdir, "env-and-path", "push", "", platforms, secrets},
{workdir, "environment-files", "push", "", platforms, secrets},
{workdir, "GITHUB_STATE", "push", "", platforms, secrets},
{workdir, "environment-files-parser-bug", "push", "", platforms, secrets},
{workdir, "non-existent-action", "push", "Job 'nopanic' failed", platforms, secrets},
{workdir, "outputs", "push", "", platforms, secrets},
{workdir, "networking", "push", "", platforms, secrets},
{workdir, "steps-context/conclusion", "push", "", platforms, secrets},
{workdir, "steps-context/outcome", "push", "", platforms, secrets},
{workdir, "job-status-check", "push", "job 'fail' failed", platforms, secrets},
{workdir, "if-expressions", "push", "Job 'mytest' failed", platforms, secrets},
// {workdir, "shells/defaults", "push", "", platforms, secrets},
// // TODO: figure out why it fails
// // {workdir, "shells/custom", "push", "", map[string]string{"ubuntu-latest": "catthehacker/ubuntu:pwsh-latest"}, }, // custom image with pwsh
// {workdir, "shells/pwsh", "push", "", map[string]string{"ubuntu-latest": "catthehacker/ubuntu:pwsh-latest"}, secrets}, // custom image with pwsh
// {workdir, "shells/bash", "push", "", platforms, secrets},
// {workdir, "shells/python", "push", "", map[string]string{"ubuntu-latest": "node:16-buster"}, secrets}, // slim doesn't have python
// {workdir, "shells/sh", "push", "", platforms, secrets},

// // Local action
// {workdir, "local-action-docker-url", "push", "", platforms, secrets},
// {workdir, "local-action-dockerfile", "push", "", platforms, secrets},
// {workdir, "local-action-via-composite-dockerfile", "push", "", platforms, secrets},
// {workdir, "local-action-js", "push", "", platforms, secrets},

// // Uses
// {workdir, "uses-composite", "push", "", platforms, secrets},
// {workdir, "uses-composite-with-error", "push", "Job 'failing-composite-action' failed", platforms, secrets},
// {workdir, "uses-composite-check-for-input-collision", "push", "", platforms, secrets},
// {workdir, "uses-composite-check-for-input-shadowing", "push", "", platforms, secrets},
// {workdir, "uses-nested-composite", "push", "", platforms, secrets},
// {workdir, "remote-action-composite-js-pre-with-defaults", "push", "", platforms, secrets},
// {workdir, "remote-action-composite-action-ref", "push", "", platforms, secrets},
// {workdir, "uses-workflow", "push", "", platforms, map[string]string{"secret": "keep_it_private"}},
// {workdir, "uses-workflow", "pull_request", "", platforms, map[string]string{"secret": "keep_it_private"}},
// {workdir, "uses-docker-url", "push", "", platforms, secrets},
// {workdir, "act-composite-env-test", "push", "", platforms, secrets},

// // Eval
// {workdir, "evalmatrix", "push", "", platforms, secrets},
// {workdir, "evalmatrixneeds", "push", "", platforms, secrets},
// {workdir, "evalmatrixneeds2", "push", "", platforms, secrets},
// {workdir, "evalmatrix-merge-map", "push", "", platforms, secrets},
// {workdir, "evalmatrix-merge-array", "push", "", platforms, secrets},
// {workdir, "issue-1195", "push", "", platforms, secrets},

// {workdir, "basic", "push", "", platforms, secrets},
// {workdir, "fail", "push", "exit with `FAILURE`: 1", platforms, secrets},
// {workdir, "runs-on", "push", "", platforms, secrets},
// {workdir, "checkout", "push", "", platforms, secrets},
// {workdir, "job-container", "push", "", platforms, secrets},
// {workdir, "job-container-non-root", "push", "", platforms, secrets},
// {workdir, "job-container-invalid-credentials", "push", "failed to handle credentials: failed to interpolate container.credentials.password", platforms, secrets},
// {workdir, "container-hostname", "push", "", platforms, secrets},
// {workdir, "remote-action-docker", "push", "", platforms, secrets},
// {workdir, "remote-action-js", "push", "", platforms, secrets},
// {workdir, "remote-action-js-node-user", "push", "", platforms, secrets}, // Test if this works with non root container
// {workdir, "matrix", "push", "", platforms, secrets},
// {workdir, "matrix-include-exclude", "push", "", platforms, secrets},
// {workdir, "matrix-exitcode", "push", "Job 'test' failed", platforms, secrets},
// {workdir, "commands", "push", "", platforms, secrets},
// {workdir, "workdir", "push", "", platforms, secrets},
// {workdir, "defaults-run", "push", "", platforms, secrets},
// {workdir, "composite-fail-with-output", "push", "", platforms, secrets},
// {workdir, "issue-597", "push", "", platforms, secrets},
// {workdir, "issue-598", "push", "", platforms, secrets},
// {workdir, "if-env-act", "push", "", platforms, secrets},
// {workdir, "env-and-path", "push", "", platforms, secrets},
// {workdir, "environment-files", "push", "", platforms, secrets},
// {workdir, "GITHUB_STATE", "push", "", platforms, secrets},
// {workdir, "environment-files-parser-bug", "push", "", platforms, secrets},
// {workdir, "non-existent-action", "push", "Job 'nopanic' failed", platforms, secrets},
// {workdir, "outputs", "push", "", platforms, secrets},
// {workdir, "networking", "push", "", platforms, secrets},
// {workdir, "steps-context/conclusion", "push", "", platforms, secrets},
// {workdir, "steps-context/outcome", "push", "", platforms, secrets},
// {workdir, "job-status-check", "push", "job 'fail' failed", platforms, secrets},
// {workdir, "if-expressions", "push", "Job 'mytest' failed", platforms, secrets},
{workdir, "actions-environment-and-context-tests", "push", "", platforms, secrets},
{workdir, "uses-action-with-pre-and-post-step", "push", "", platforms, secrets},
{workdir, "evalenv", "push", "", platforms, secrets},
{workdir, "docker-action-custom-path", "push", "", platforms, secrets},
{workdir, "GITHUB_ENV-use-in-env-ctx", "push", "", platforms, secrets},
{workdir, "ensure-post-steps", "push", "Job 'second-post-step-should-fail' failed", platforms, secrets},
{workdir, "workflow_call_inputs", "workflow_call", "", platforms, secrets},
{workdir, "workflow_dispatch", "workflow_dispatch", "", platforms, secrets},
{workdir, "workflow_dispatch_no_inputs_mapping", "workflow_dispatch", "", platforms, secrets},
{workdir, "workflow_dispatch-scalar", "workflow_dispatch", "", platforms, secrets},
{workdir, "workflow_dispatch-scalar-composite-action", "workflow_dispatch", "", platforms, secrets},
{workdir, "job-needs-context-contains-result", "push", "", platforms, secrets},
{"../model/testdata", "strategy", "push", "", platforms, secrets}, // TODO: move all testdata into pkg so we can validate it with planner and runner
{"../model/testdata", "container-volumes", "push", "", platforms, secrets},
{workdir, "path-handling", "push", "", platforms, secrets},
{workdir, "do-not-leak-step-env-in-composite", "push", "", platforms, secrets},
{workdir, "set-env-step-env-override", "push", "", platforms, secrets},
{workdir, "set-env-new-env-file-per-step", "push", "", platforms, secrets},
{workdir, "no-panic-on-invalid-composite-action", "push", "jobs failed due to invalid action", platforms, secrets},

// services
{workdir, "services", "push", "", platforms, secrets},
{workdir, "services-empty-image", "push", "", platforms, secrets},
{workdir, "services-host-network", "push", "", platforms, secrets},
{workdir, "services-with-container", "push", "", platforms, secrets},
{workdir, "mysql-service-container-with-health-check", "push", "", platforms, secrets},

// local remote action overrides
{workdir, "local-remote-action-overrides", "push", "", platforms, secrets},
// {workdir, "uses-action-with-pre-and-post-step", "push", "", platforms, secrets},
// {workdir, "evalenv", "push", "", platforms, secrets},
// {workdir, "docker-action-custom-path", "push", "", platforms, secrets},
// {workdir, "GITHUB_ENV-use-in-env-ctx", "push", "", platforms, secrets},
// {workdir, "ensure-post-steps", "push", "Job 'second-post-step-should-fail' failed", platforms, secrets},
// {workdir, "workflow_call_inputs", "workflow_call", "", platforms, secrets},
// {workdir, "workflow_dispatch", "workflow_dispatch", "", platforms, secrets},
// {workdir, "workflow_dispatch_no_inputs_mapping", "workflow_dispatch", "", platforms, secrets},
// {workdir, "workflow_dispatch-scalar", "workflow_dispatch", "", platforms, secrets},
// {workdir, "workflow_dispatch-scalar-composite-action", "workflow_dispatch", "", platforms, secrets},
// {workdir, "job-needs-context-contains-result", "push", "", platforms, secrets},
// {"../model/testdata", "strategy", "push", "", platforms, secrets}, // TODO: move all testdata into pkg so we can validate it with planner and runner
// {"../model/testdata", "container-volumes", "push", "", platforms, secrets},
// {workdir, "path-handling", "push", "", platforms, secrets},
// {workdir, "do-not-leak-step-env-in-composite", "push", "", platforms, secrets},
// {workdir, "set-env-step-env-override", "push", "", platforms, secrets},
// {workdir, "set-env-new-env-file-per-step", "push", "", platforms, secrets},
// {workdir, "no-panic-on-invalid-composite-action", "push", "jobs failed due to invalid action", platforms, secrets},

// // services
// {workdir, "services", "push", "", platforms, secrets},
// {workdir, "services-empty-image", "push", "", platforms, secrets},
// {workdir, "services-host-network", "push", "", platforms, secrets},
// {workdir, "services-with-container", "push", "", platforms, secrets},
// {workdir, "mysql-service-container-with-health-check", "push", "", platforms, secrets},

// // local remote action overrides
// {workdir, "local-remote-action-overrides", "push", "", platforms, secrets},
}

for _, table := range tables {
Expand Down

0 comments on commit 35918dd

Please sign in to comment.