diff --git a/atlasaction/action.go b/atlasaction/action.go index 048615a8..67bba7f8 100644 --- a/atlasaction/action.go +++ b/atlasaction/action.go @@ -227,7 +227,7 @@ func WithRuntimeAction() Option { // WithAtlasPath sets the path to the atlas binary. func WithAtlasPath(bin string) Option { return func(c *config) { - c.atlas, c.err = atlasexec.NewClient("", bin) + c.atlas, c.err = atlasexec.NewClient(c.getenv("WORK"), bin) } } diff --git a/atlasaction/action_test.go b/atlasaction/action_test.go index f83ed665..8aed8f95 100644 --- a/atlasaction/action_test.go +++ b/atlasaction/action_test.go @@ -13,6 +13,7 @@ import ( "errors" "fmt" "io" + "log" "log/slog" "net/http" "net/http/httptest" @@ -2181,12 +2182,22 @@ func renderTemplate[T any](ts *testscript.TestScript, neg bool, args []string) { ts.Check(err) } +func TestMain(m *testing.M) { + os.Exit(testscript.RunMain(m, map[string]func() int{ + "atlas-action": func() int { + return atlasaction.Main("testscript", "dev") + }, + })) +} + func TestGitHubActions(t *testing.T) { var ( actions = "actions" output = filepath.Join(actions, "output.txt") summary = filepath.Join(actions, "summary.txt") ) + wd, err := os.Getwd() + require.NoError(t, err) testscript.Run(t, testscript.Params{ Dir: filepath.Join("testdata", "github"), Setup: func(e *testscript.Env) (err error) { @@ -2194,21 +2205,14 @@ func TestGitHubActions(t *testing.T) { if err := os.Mkdir(dir, 0700); err != nil { return err } + e.Setenv("SOURCE", wd) e.Setenv("GITHUB_ACTIONS", "true") e.Setenv("GITHUB_ENV", filepath.Join(dir, "env.txt")) e.Setenv("GITHUB_OUTPUT", filepath.Join(dir, "output.txt")) e.Setenv("GITHUB_STEP_SUMMARY", filepath.Join(dir, "summary.txt")) - c, err := atlasexec.NewClient(e.WorkDir, "atlas") - if err != nil { - return err - } - // Create a new actions for each test. - e.Values[atlasKey{}] = &atlasClient{c} return nil }, Cmds: map[string]func(ts *testscript.TestScript, neg bool, args []string){ - "atlas-action": atlasAction, - "mock-atlas": mockAtlasOutput, "summary": func(ts *testscript.TestScript, neg bool, args []string) { if len(args) == 0 { _, err := os.Stat(ts.MkAbs(summary)) @@ -2247,61 +2251,36 @@ func TestGitHubActions(t *testing.T) { }) } -type ( - atlasKey struct{} - atlasClient struct { - atlasaction.AtlasExec - } -) - -func atlasAction(ts *testscript.TestScript, neg bool, args []string) { +func atlasAction() int { + args := os.Args[1:] if len(args) != 1 { - ts.Fatalf("usage: atlas-action ") + log.Fatalf("usage: atlas-action ") } - client, ok := ts.Value(atlasKey{}).(*atlasClient) - if !ok || client == nil { - ts.Fatalf("client not found") + var atlasPath = "atlas" + if v := os.Getenv("ATLAS_PATH"); v != "" { + atlasPath = v } // The action need to be create for each call to read correct inputs act, err := atlasaction.New( - atlasaction.WithGetenv(ts.Getenv), - atlasaction.WithOut(ts.Stdout()), - atlasaction.WithAtlas(client.AtlasExec), + atlasaction.WithGetenv(os.Getenv), + atlasaction.WithOut(os.Stdout), + atlasaction.WithAtlasPath(atlasPath), atlasaction.WithVersion("testscript"), ) - ts.Check(err) + if err != nil { + log.Fatalf("failed to create action: %v", err) + } action := args[0] - ts.Setenv("ATLAS_ACTION_COMMAND", action) - ts.Defer(func() { - ts.Setenv("ATLAS_ACTION_COMMAND", "") - }) + os.Setenv("ATLAS_ACTION_COMMAND", action) + defer func() { + os.Setenv("ATLAS_ACTION_COMMAND", "") + }() // Run the action! - switch err := act.Run(context.Background(), action); { - case !neg: - ts.Check(err) - case err == nil: - ts.Fatalf("expected fail") - case neg: - // Print the error to asserting on the testscript - fmt.Fprint(ts.Stderr(), err.Error()) - } -} - -func mockAtlasOutput(ts *testscript.TestScript, neg bool, args []string) { - if len(args) != 1 { - ts.Fatalf("usage: mock-atlas ") - } - client, ok := ts.Value(atlasKey{}).(*atlasClient) - if !ok || client == nil { - ts.Fatalf("client not found") + err = act.Run(context.Background(), action) + if err != nil { + log.Fatalf("%v", err) } - m, err := atlasexec.NewClient("", "./mock-atlas.sh") - ts.Check(err) - ts.Check(m.SetEnv(map[string]string{ - "TEST_BATCH": args[0], - })) - // Replace the atlas client with a mock client. - client.AtlasExec = m + return 0 } func cmpFiles(ts *testscript.TestScript, neg bool, name1, name2 string) { diff --git a/atlasaction/bitbucket_test.go b/atlasaction/bitbucket_test.go index 8af9e5b1..74769927 100644 --- a/atlasaction/bitbucket_test.go +++ b/atlasaction/bitbucket_test.go @@ -5,8 +5,8 @@ import ( "path/filepath" "testing" - "ariga.io/atlas-go-sdk/atlasexec" "github.com/rogpeppe/go-internal/testscript" + "github.com/stretchr/testify/require" ) func TestBitbucketPipe(t *testing.T) { @@ -14,6 +14,8 @@ func TestBitbucketPipe(t *testing.T) { actions = "actions" outputs = filepath.Join("outputs.sh") ) + wd, err := os.Getwd() + require.NoError(t, err) testscript.Run(t, testscript.Params{ Dir: filepath.Join("testdata", "bitbucket"), Setup: func(e *testscript.Env) (err error) { @@ -21,20 +23,13 @@ func TestBitbucketPipe(t *testing.T) { if err := os.Mkdir(dir, 0700); err != nil { return err } + e.Setenv("SOURCE", wd) e.Setenv("BITBUCKET_PIPELINE_UUID", "fbfb4205-c666-42ed-983a-d27f47f2aad2") e.Setenv("BITBUCKET_PIPE_STORAGE_DIR", dir) e.Setenv("BITBUCKET_CLONE_DIR", e.WorkDir) - c, err := atlasexec.NewClient(e.WorkDir, "atlas") - if err != nil { - return err - } - // Create a new actions for each test. - e.Values[atlasKey{}] = &atlasClient{c} return nil }, Cmds: map[string]func(ts *testscript.TestScript, neg bool, args []string){ - "atlas-action": atlasAction, - "mock-atlas": mockAtlasOutput, "output": func(ts *testscript.TestScript, neg bool, args []string) { if len(args) == 0 { _, err := os.Stat(ts.MkAbs(outputs)) diff --git a/atlasaction/circleci_action_test.go b/atlasaction/circleci_action_test.go index add241ec..98745b90 100644 --- a/atlasaction/circleci_action_test.go +++ b/atlasaction/circleci_action_test.go @@ -13,7 +13,6 @@ import ( "testing" "ariga.io/atlas-action/atlasaction" - "ariga.io/atlas-go-sdk/atlasexec" "github.com/rogpeppe/go-internal/testscript" "github.com/stretchr/testify/require" ) @@ -63,6 +62,8 @@ func TestCircleCI(t *testing.T) { actions = "actions" output = filepath.Join(actions, "output.txt") ) + wd, err := os.Getwd() + require.NoError(t, err) testscript.Run(t, testscript.Params{ Dir: filepath.Join("testdata", "circleci"), Setup: func(e *testscript.Env) (err error) { @@ -70,21 +71,14 @@ func TestCircleCI(t *testing.T) { if err := os.Mkdir(dir, 0700); err != nil { return err } + e.Setenv("SOURCE", wd) e.Setenv("CIRCLECI", "true") e.Setenv("CIRCLE_PROJECT_REPONAME", "atlas-orb") e.Setenv("CIRCLE_SHA1", "1234567890") e.Setenv("BASH_ENV", filepath.Join(dir, "output.txt")) - c, err := atlasexec.NewClient(e.WorkDir, "atlas") - if err != nil { - return err - } - // Create a new actions for each test. - e.Values[atlasKey{}] = &atlasClient{c} return nil }, Cmds: map[string]func(ts *testscript.TestScript, neg bool, args []string){ - "atlas-action": atlasAction, - "mock-atlas": mockAtlasOutput, "output": func(ts *testscript.TestScript, neg bool, args []string) { if len(args) == 0 { _, err := os.Stat(ts.MkAbs(output)) diff --git a/atlasaction/gitlab_ci_test.go b/atlasaction/gitlab_ci_test.go index b3a7befa..db2d7d09 100644 --- a/atlasaction/gitlab_ci_test.go +++ b/atlasaction/gitlab_ci_test.go @@ -10,9 +10,9 @@ import ( "testing" "ariga.io/atlas-action/atlasaction" - "ariga.io/atlas-go-sdk/atlasexec" "github.com/gorilla/mux" "github.com/rogpeppe/go-internal/testscript" + "github.com/stretchr/testify/require" ) func newMockHandler(dir string) http.Handler { @@ -88,6 +88,8 @@ func newMockHandler(dir string) http.Handler { } func TestGitlabCI(t *testing.T) { + wd, err := os.Getwd() + require.NoError(t, err) testscript.Run(t, testscript.Params{ Dir: "testdata/gitlab", Setup: func(e *testscript.Env) error { @@ -97,21 +99,14 @@ func TestGitlabCI(t *testing.T) { return err } e.Defer(srv.Close) + e.Setenv("SOURCE", wd) e.Setenv("CI_API_V4_URL", srv.URL) e.Setenv("CI_PROJECT_ID", "1") e.Setenv("GITLAB_CI", "true") e.Setenv("GITLAB_TOKEN", "token") - c, err := atlasexec.NewClient(e.WorkDir, "atlas") - if err != nil { - return err - } - // Create a new actions for each test. - e.Values[atlasKey{}] = &atlasClient{c} return nil }, Cmds: map[string]func(ts *testscript.TestScript, neg bool, args []string){ - "atlas-action": atlasAction, - "mock-atlas": mockAtlasOutput, "output": func(ts *testscript.TestScript, neg bool, args []string) { if len(args) == 0 { _, err := os.Stat(ts.MkAbs(".env")) diff --git a/atlasaction/main.go b/atlasaction/main.go new file mode 100644 index 00000000..a8c39720 --- /dev/null +++ b/atlasaction/main.go @@ -0,0 +1,60 @@ +package atlasaction + +import ( + "context" + "errors" + "fmt" + "os" + + "ariga.io/atlas-action/atlasaction/cloud" + "github.com/alecthomas/kong" +) + +func Main(version, commit string) int { + atlasPath := "atlas" + if p := os.Getenv("ATLAS_PATH"); p != "" { + // The environment can provide the path to the atlas-cli binary. + // + // This is useful when running the action in a Docker container, + // and the user can mount the atlas-cli binary in the container and set the + // ATLAS_PATH environment variable to the path of the binary. + atlasPath = p + } + act, err := New( + WithAtlasPath(atlasPath), + WithCloudClient(cloud.New), + WithVersion(version), + ) + if err != nil { + fmt.Fprintf(os.Stderr, "failed to run action in the current environment: %s\n", err) + os.Exit(1) + } + cli := kong.Parse( + &RunActionCmd{}, + kong.BindTo(context.Background(), (*context.Context)(nil)), + kong.Vars{ + "version": fmt.Sprintf("atlas-action version %s-%s\n", version, commit), + }, + ) + if err := cli.Run(act); err != nil { + if uerr := errors.Unwrap(err); uerr != nil { + err = uerr + } + act.Fatalf(err.Error()) + } + return 0 +} + +// RunActionCmd is a command to run one of the Atlas GitHub Actions. +type RunActionCmd struct { + Action string `help:"Command to run" required:"" env:"ATLAS_ACTION"` + Version kong.VersionFlag `name:"version" help:"Print version information and quit"` +} + +func (r *RunActionCmd) Run(ctx context.Context, a *Actions) error { + _ = os.Setenv("ATLAS_ACTION_COMMAND", r.Action) + defer func() { + _ = os.Unsetenv("ATLAS_ACTION_COMMAND") + }() + return a.Run(ctx, r.Action) +} diff --git a/cmd/atlas-action/main_test.go b/atlasaction/main_test.go similarity index 91% rename from cmd/atlas-action/main_test.go rename to atlasaction/main_test.go index d28cadda..366fc690 100644 --- a/cmd/atlas-action/main_test.go +++ b/atlasaction/main_test.go @@ -2,7 +2,7 @@ // This source code is licensed under the Apache 2.0 license found // in the LICENSE file in the root directory of this source tree. -package main +package atlasaction_test import ( "context" @@ -19,7 +19,7 @@ func TestRunAction_Run(t *testing.T) { require.NoError(t, err) act := atlasaction.NewGHAction(os.Getenv, os.Stdout) t.Run("fake", func(t *testing.T) { - r := &RunActionCmd{Action: "fake"} + r := &atlasaction.RunActionCmd{Action: "fake"} c, err := atlasaction.New(atlasaction.WithAction(act), atlasaction.WithAtlas(client)) require.NoError(t, err) err = r.Run(context.Background(), c) diff --git a/atlasaction/testdata/bitbucket/schema-push.txtar b/atlasaction/testdata/bitbucket/schema-push.txtar index 29115ce2..ed04f7b0 100644 --- a/atlasaction/testdata/bitbucket/schema-push.txtar +++ b/atlasaction/testdata/bitbucket/schema-push.txtar @@ -1,15 +1,15 @@ # Mock atlas command outputs -mock-atlas $WORK/schema-push +env ATLAS_PATH=$SOURCE/mock-atlas.sh TEST_BATCH=$WORK/schema-push # Setup the action input variables env ATLAS_INPUT_ENV=test env ATLAS_INPUT_LATEST=true # Run the action without a tag -atlas-action schema/push +atlas-action --action=schema/push # Run the action with a tag env ATLAS_INPUT_TAG=98765 -atlas-action schema/push +atlas-action --action=schema/push exec cat .atlas-action/outputs.sh output outputs.sh diff --git a/atlasaction/testdata/circleci/migrate-lint.txtar b/atlasaction/testdata/circleci/migrate-lint.txtar index c823e203..83c3c90d 100644 --- a/atlasaction/testdata/circleci/migrate-lint.txtar +++ b/atlasaction/testdata/circleci/migrate-lint.txtar @@ -1,5 +1,5 @@ # Mock the atlas command outputs -mock-atlas $WORK/migrate-lint +env ATLAS_PATH=$SOURCE/mock-atlas.sh TEST_BATCH=$WORK/migrate-lint # Setup the action input variables env INPUT_CONFIG=file://testdata/config/atlas.hcl env INPUT_ENV=test @@ -12,7 +12,7 @@ env INPUT_RUN=example # The action's output should append the existing outputs cp output-pre.txt actions/output.txt -atlas-action migrate/lint +atlas-action --action=migrate/lint output output.txt -- migrate-lint/1/args -- diff --git a/atlasaction/testdata/github/migrate-lint.txtar b/atlasaction/testdata/github/migrate-lint.txtar index 4940ce0c..de0db665 100644 --- a/atlasaction/testdata/github/migrate-lint.txtar +++ b/atlasaction/testdata/github/migrate-lint.txtar @@ -1,5 +1,5 @@ # Mock the atlas command outputs -mock-atlas $WORK/migrate-lint +env ATLAS_PATH=$SOURCE/mock-atlas.sh TEST_BATCH=$WORK/migrate-lint # Setup the action input variables env INPUT_CONFIG=file://testdata/config/atlas.hcl env INPUT_ENV=test @@ -10,7 +10,7 @@ env INPUT_DIR=file://testdata/migrations env INPUT_DEV_URL=sqlite://file?mode=memory env INPUT_RUN=example -atlas-action migrate/lint +atlas-action --action=migrate/lint output output.txt -- migrate-lint/1/args -- diff --git a/atlasaction/testdata/github/migrate-test.txtar b/atlasaction/testdata/github/migrate-test.txtar index 67cc6a0f..b618a23b 100644 --- a/atlasaction/testdata/github/migrate-test.txtar +++ b/atlasaction/testdata/github/migrate-test.txtar @@ -1,5 +1,5 @@ # Mock the atlas command outputs -mock-atlas $WORK/migrate-test +env ATLAS_PATH=$SOURCE/mock-atlas.sh TEST_BATCH=$WORK/migrate-test # Setup the action input variables env INPUT_CONFIG=file://testdata/config/atlas.hcl env INPUT_ENV=test @@ -8,12 +8,12 @@ env INPUT_DIR=file://testdata/migrations env INPUT_DEV_URL=sqlite://file?mode=memory env INPUT_RUN=example -atlas-action migrate/test +atlas-action --action=migrate/test stdout '`atlas migrate test` completed successfully, no issues found' stdout 'Success' ! output -! atlas-action migrate/test +! atlas-action --action=migrate/test stderr '`atlas migrate test` completed with errors:' stderr 'Failure' ! output diff --git a/atlasaction/testdata/github/schema-apply-envs.txtar b/atlasaction/testdata/github/schema-apply-envs.txtar index 67d9e5fb..94ff7959 100644 --- a/atlasaction/testdata/github/schema-apply-envs.txtar +++ b/atlasaction/testdata/github/schema-apply-envs.txtar @@ -1,10 +1,10 @@ # Mock the atlas command outputs -mock-atlas $WORK/schema-apply +env ATLAS_PATH=$SOURCE/mock-atlas.sh TEST_BATCH=$WORK/schema-apply # Setup the action input variables env INPUT_ENV=test env INPUT_PLAN=file://20240910173744.plan.hcl # Run the action -! atlas-action schema/apply +! atlas-action --action=schema/apply stdout '"atlas schema apply" completed successfully on the target "sqlite://local-bu.db"' stdout '"atlas schema apply" completed successfully on the target "sqlite://local-pi.db"' stdout '"atlas schema apply" completed successfully on the target "sqlite://local-su.db"' diff --git a/atlasaction/testdata/github/schema-apply-lint.txtar b/atlasaction/testdata/github/schema-apply-lint.txtar index 4f35e02e..4746d4eb 100644 --- a/atlasaction/testdata/github/schema-apply-lint.txtar +++ b/atlasaction/testdata/github/schema-apply-lint.txtar @@ -1,9 +1,9 @@ # Mock the atlas command outputs -mock-atlas $WORK/schema-apply +env ATLAS_PATH=$SOURCE/mock-atlas.sh TEST_BATCH=$WORK/schema-apply # Setup the action input variables env INPUT_ENV=test # Run the action -! atlas-action schema/apply +! atlas-action --action=schema/apply summary summary.html output output.txt diff --git a/atlasaction/testdata/github/schema-push.txtar b/atlasaction/testdata/github/schema-push.txtar index e3f07700..e059f04b 100644 --- a/atlasaction/testdata/github/schema-push.txtar +++ b/atlasaction/testdata/github/schema-push.txtar @@ -1,15 +1,15 @@ # Mock atlas command outputs -mock-atlas $WORK/schema-push +env ATLAS_PATH=$SOURCE/mock-atlas.sh TEST_BATCH=$WORK/schema-push # Setup the action input variables env INPUT_ENV=test env INPUT_LATEST=true # Run the action without a tag -atlas-action schema/push +atlas-action --action=schema/push # Run the action with a tag env INPUT_TAG=98765 -atlas-action schema/push +atlas-action --action=schema/push -- schema-push/1/args -- schema push --format {{ json . }} --env test --context {"scmType":"GITHUB"} --tag latest diff --git a/atlasaction/testdata/github/schema-test.txtar b/atlasaction/testdata/github/schema-test.txtar index 8405ea20..e2c5c36f 100644 --- a/atlasaction/testdata/github/schema-test.txtar +++ b/atlasaction/testdata/github/schema-test.txtar @@ -1,5 +1,5 @@ # Mock the atlas command outputs -mock-atlas $WORK/schema-test +env ATLAS_PATH=$SOURCE/mock-atlas.sh TEST_BATCH=$WORK/schema-test # Setup the action input variables env INPUT_CONFIG=file://testdata/config/atlas.hcl env INPUT_ENV=test @@ -7,12 +7,12 @@ env INPUT_VARS='{"var1":"value1","var2":"value2"}' env INPUT_DEV_URL=sqlite://file?mode=memory env INPUT_RUN=example -atlas-action schema/test +atlas-action --action=schema/test stdout '`atlas schema test` completed successfully, no issues found' stdout 'Success' ! output -! atlas-action schema/test +! atlas-action --action=schema/test stderr '`atlas schema test` completed with errors:' stderr 'Failure' ! output diff --git a/atlasaction/testdata/gitlab/schema-plan-approve.txtar b/atlasaction/testdata/gitlab/schema-plan-approve.txtar index cd192034..9d161fda 100644 --- a/atlasaction/testdata/gitlab/schema-plan-approve.txtar +++ b/atlasaction/testdata/gitlab/schema-plan-approve.txtar @@ -1,15 +1,15 @@ -mock-atlas $WORK/schema-plan-approve +env ATLAS_PATH=$SOURCE/mock-atlas.sh TEST_BATCH=$WORK/schema-plan-approve # No plans found. -atlas-action schema/plan/approve +atlas-action --action=schema/plan/approve stdout 'No plan URL provided, searching for the pending plan' stdout 'No schema plan found' # One pending plan. -atlas-action schema/plan/approve +atlas-action --action=schema/plan/approve # Multiple pending plans. -! atlas-action schema/plan/approve +! atlas-action --action=schema/plan/approve stdout 'No plan URL provided, searching for the pending plan' stdout 'Found schema plan: atlas://plans/1234' stdout 'Found schema plan: atlas://plans/5678' diff --git a/atlasaction/testdata/gitlab/schema-plan.txtar b/atlasaction/testdata/gitlab/schema-plan.txtar index 7aff1c77..94518504 100644 --- a/atlasaction/testdata/gitlab/schema-plan.txtar +++ b/atlasaction/testdata/gitlab/schema-plan.txtar @@ -1,7 +1,7 @@ -! atlas-action schema/plan +! atlas-action --action=schema/plan stderr 'the action should be run in a pull request context' -mock-atlas $WORK/schema-plan +env ATLAS_PATH=$SOURCE/mock-atlas.sh TEST_BATCH=$WORK/schema-plan env CI_MERGE_REQUEST_IID=1 env CI_PROJECT_NAME=my-project env CI_PROJECT_URL=https://gitlab.com/projects/my-project @@ -11,7 +11,7 @@ env GITLAB_USER_NAME=user env GITLAB_USER_ID=123 env CI_MERGE_REQUEST_REF_PATH=$CI_PROJECT_URL/merge_requests/1 -atlas-action schema/plan +atlas-action --action=schema/plan stdout 'Schema plan does not exist, creating a new one with name "pr-1-3RRRcLHF"' cmp comments-expected/1 comments/1 diff --git a/cmd/atlas-action/main.go b/cmd/atlas-action/main.go index 47b0d7eb..5c97a159 100644 --- a/cmd/atlas-action/main.go +++ b/cmd/atlas-action/main.go @@ -5,14 +5,9 @@ package main import ( - "context" - "errors" - "fmt" "os" "ariga.io/atlas-action/atlasaction" - "ariga.io/atlas-action/atlasaction/cloud" - "github.com/alecthomas/kong" ) var ( @@ -25,56 +20,5 @@ var ( ) func main() { - atlasPath := "atlas" - if p := os.Getenv("ATLAS_PATH"); p != "" { - // The environment can provide the path to the atlas-cli binary. - // - // This is useful when running the action in a Docker container, - // and the user can mount the atlas-cli binary in the container and set the - // ATLAS_PATH environment variable to the path of the binary. - atlasPath = p - } - act, err := atlasaction.New( - atlasaction.WithAtlasPath(atlasPath), - atlasaction.WithCloudClient(cloud.New), - atlasaction.WithVersion(version), - ) - if err != nil { - fmt.Fprintf(os.Stderr, "failed to run action in the current environment: %s\n", err) - os.Exit(1) - } - cli := kong.Parse( - &RunActionCmd{}, - kong.BindTo(context.Background(), (*context.Context)(nil)), - ) - if err := cli.Run(act); err != nil { - if uerr := errors.Unwrap(err); uerr != nil { - err = uerr - } - act.Fatalf(err.Error()) - } -} - -// VersionFlag is a flag type that can be used to display a version number, stored in the "version" variable. -type VersionFlag bool - -// BeforeReset writes the version variable and terminates with a 0 exit status. -func (v VersionFlag) BeforeReset(app *kong.Kong) error { - _, err := fmt.Fprintf(app.Stdout, "atlas-action version %s-%s\n", version, commit) - app.Exit(0) - return err -} - -// RunActionCmd is a command to run one of the Atlas GitHub Actions. -type RunActionCmd struct { - Action string `help:"Command to run" required:"" env:"ATLAS_ACTION"` - Version VersionFlag `help:"Prints the version and exits"` -} - -func (r *RunActionCmd) Run(ctx context.Context, a *atlasaction.Actions) error { - _ = os.Setenv("ATLAS_ACTION_COMMAND", r.Action) - defer func() { - _ = os.Unsetenv("ATLAS_ACTION_COMMAND") - }() - return a.Run(ctx, r.Action) + os.Exit(atlasaction.Main(version, commit)) }