From 89cb853aa7f4289f44dda6b09e4b2b033ce88516 Mon Sep 17 00:00:00 2001 From: Joshua Gilman Date: Fri, 6 Sep 2024 17:39:34 -0400 Subject: [PATCH] feat(forge/cli): adds ci flag --- forge/cli/cmd/cmds/run.go | 1 + forge/cli/cmd/cmds/util.go | 5 +++++ forge/cli/cmd/testdata/run/3.txt | 3 ++- forge/cli/pkg/earthly/earthly.go | 1 + forge/cli/pkg/earthly/earthly_test.go | 8 ++++++++ forge/cli/pkg/earthly/options.go | 7 +++++++ 6 files changed, 24 insertions(+), 1 deletion(-) diff --git a/forge/cli/cmd/cmds/run.go b/forge/cli/cmd/cmds/run.go index 1bb7ae0..4616b1a 100644 --- a/forge/cli/cmd/cmds/run.go +++ b/forge/cli/cmd/cmds/run.go @@ -12,6 +12,7 @@ import ( type RunCmd struct { Artifact string `short:"a" help:"Dump all produced artifacts to the given path."` + CI bool `help:"Run the target in CI mode."` Local bool `short:"l" help:"Forces the target to run locally (ignores satellite)."` Path string `arg:"" help:"The path to the target to execute (i.e., ./dir1+test)."` Platform string `short:"p" help:"Run the target with the given platform."` diff --git a/forge/cli/cmd/cmds/util.go b/forge/cli/cmd/cmds/util.go index 6c8a9c0..b894a12 100644 --- a/forge/cli/cmd/cmds/util.go +++ b/forge/cli/cmd/cmds/util.go @@ -61,6 +61,11 @@ func generateOpts(target string, flags *RunCmd, config *schema.Blueprint) []eart if flags.Artifact != "" { opts = append(opts, earthly.WithArtifact(flags.Artifact)) } + + if flags.CI { + opts = append(opts, earthly.WithCI()) + } + if flags.Platform != "" { opts = append(opts, earthly.WithPlatform(flags.Platform)) } diff --git a/forge/cli/cmd/testdata/run/3.txt b/forge/cli/cmd/testdata/run/3.txt index d80b03e..22824f0 100644 --- a/forge/cli/cmd/testdata/run/3.txt +++ b/forge/cli/cmd/testdata/run/3.txt @@ -1,8 +1,9 @@ -exec forge run --platform test ./dir1+test +exec forge run --ci --platform test ./dir1+test cmp stdout golden.txt -- golden.txt -- earthly +--ci --platform test ./dir1+test diff --git a/forge/cli/pkg/earthly/earthly.go b/forge/cli/pkg/earthly/earthly.go index 89b2d0b..5bc0de6 100644 --- a/forge/cli/pkg/earthly/earthly.go +++ b/forge/cli/pkg/earthly/earthly.go @@ -27,6 +27,7 @@ type EarthlySecret struct { // EarthlyExecutor. type earthlyExecutorOptions struct { artifact string + ci bool retries int } diff --git a/forge/cli/pkg/earthly/earthly_test.go b/forge/cli/pkg/earthly/earthly_test.go index 273b950..ab692d0 100644 --- a/forge/cli/pkg/earthly/earthly_test.go +++ b/forge/cli/pkg/earthly/earthly_test.go @@ -123,6 +123,14 @@ func TestEarthlyExecutor_buildArguments(t *testing.T) { ), expect: []string{"--artifact", "/test/dir+foo/*", "test/"}, }, + { + name: "with ci", + e: NewEarthlyExecutor("/test/dir", "foo", nil, secrets.SecretStore{}, + testutils.NewNoopLogger(), + WithCI(), + ), + expect: []string{"--ci", "/test/dir+foo"}, + }, { name: "with platform", e: NewEarthlyExecutor("/test/dir", "foo", nil, secrets.SecretStore{}, diff --git a/forge/cli/pkg/earthly/options.go b/forge/cli/pkg/earthly/options.go index a7a8580..e2578ad 100644 --- a/forge/cli/pkg/earthly/options.go +++ b/forge/cli/pkg/earthly/options.go @@ -18,6 +18,13 @@ func WithArtifact(path string) EarthlyExecutorOption { } } +func WithCI() EarthlyExecutorOption { + return func(e *EarthlyExecutor) { + e.opts.ci = true + e.earthlyArgs = append(e.earthlyArgs, "--ci") + } +} + // WithPlatform is an option for configuring an EarthlyExecutor to run the // Earthly target with the given platform. func WithPlatform(platform string) EarthlyExecutorOption {