From b7d380b3f096e079f2c1ba91a9377752fc4c9751 Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Tue, 7 Jun 2022 16:19:30 +0200 Subject: [PATCH] fix: dryrun skip local actions + enable Tests (#1199) * Update step_action_local.go * Enable Tests for DRYRUN * Update runner_test.go * Update runner_test.go * Move DRYRUN Test in it's own function Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- pkg/runner/runner_test.go | 30 ++++++++++++++++++++++++++++++ pkg/runner/step_action_local.go | 6 ++++++ 2 files changed, 36 insertions(+) diff --git a/pkg/runner/runner_test.go b/pkg/runner/runner_test.go index 224d101..4e88fed 100644 --- a/pkg/runner/runner_test.go +++ b/pkg/runner/runner_test.go @@ -13,6 +13,7 @@ import ( log "github.com/sirupsen/logrus" assert "github.com/stretchr/testify/assert" + "github.com/nektos/act/pkg/common" "github.com/nektos/act/pkg/model" ) @@ -186,6 +187,35 @@ func TestRunEvent(t *testing.T) { } } +func TestDryrunEvent(t *testing.T) { + if testing.Short() { + t.Skip("skipping integration test") + } + + ctx := common.WithDryrun(context.Background(), true) + + tables := []TestJobFileInfo{ + // Shells + {workdir, "shells/defaults", "push", "", platforms}, + {workdir, "shells/pwsh", "push", "", map[string]string{"ubuntu-latest": "ghcr.io/justingrote/act-pwsh:latest"}}, // custom image with pwsh + {workdir, "shells/bash", "push", "", platforms}, + {workdir, "shells/python", "push", "", map[string]string{"ubuntu-latest": "node:16-buster"}}, // slim doesn't have python + {workdir, "shells/sh", "push", "", platforms}, + + // Local action + {workdir, "local-action-docker-url", "push", "", platforms}, + {workdir, "local-action-dockerfile", "push", "", platforms}, + {workdir, "local-action-via-composite-dockerfile", "push", "", platforms}, + {workdir, "local-action-js", "push", "", platforms}, + } + + for _, table := range tables { + t.Run(table.workflowPath, func(t *testing.T) { + table.runTest(ctx, t, &Config{}) + }) + } +} + func TestRunDifferentArchitecture(t *testing.T) { if testing.Short() { t.Skip("skipping integration test") diff --git a/pkg/runner/step_action_local.go b/pkg/runner/step_action_local.go index be4303a..ad0e5af 100644 --- a/pkg/runner/step_action_local.go +++ b/pkg/runner/step_action_local.go @@ -28,6 +28,9 @@ func (sal *stepActionLocal) pre() common.Executor { sal.env = map[string]string{} return func(ctx context.Context) error { + if common.Dryrun(ctx) { + return nil + } actionDir := filepath.Join(sal.getRunContext().Config.Workdir, sal.Step.Uses) localReader := func(ctx context.Context) actionYamlReader { @@ -65,6 +68,9 @@ func (sal *stepActionLocal) pre() common.Executor { func (sal *stepActionLocal) main() common.Executor { return runStepExecutor(sal, stepStageMain, func(ctx context.Context) error { + if common.Dryrun(ctx) { + return nil + } actionDir := filepath.Join(sal.getRunContext().Config.Workdir, sal.Step.Uses) return sal.runAction(sal, actionDir, nil)(ctx) })