From 35918ddaaa8300e8ab90d93e4dc075af29489b9e Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Tue, 29 Oct 2024 21:50:52 +0000 Subject: [PATCH] fix bug --- pkg/runner/action.go | 24 ++--- pkg/runner/action_test.go | 4 + pkg/runner/runner_test.go | 190 +++++++++++++++++++------------------- 3 files changed, 111 insertions(+), 107 deletions(-) diff --git a/pkg/runner/action.go b/pkg/runner/action.go index 0db3c4e134c..8aa8a52d4bb 100644 --- a/pkg/runner/action.go +++ b/pkg/runner/action.go @@ -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 @@ -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() @@ -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 { @@ -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 } @@ -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 { @@ -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 { diff --git a/pkg/runner/action_test.go b/pkg/runner/action_test.go index 52658432e98..2e2003f37a0 100644 --- a/pkg/runner/action_test.go +++ b/pkg/runner/action_test.go @@ -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()) + envMatcher := mock.MatchedBy(func(env map[string]string) bool { for k, v := range tt.expectedEnv { if env[k] != v { @@ -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) diff --git a/pkg/runner/runner_test.go b/pkg/runner/runner_test.go index 82defd77661..df997c0c064 100644 --- a/pkg/runner/runner_test.go +++ b/pkg/runner/runner_test.go @@ -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 {