From 4d04024e571dadf1c072eae8b925980a867bd20c Mon Sep 17 00:00:00 2001 From: "Giau. Tran Minh" Date: Thu, 19 Sep 2024 14:11:20 +0700 Subject: [PATCH] schema/push: fix URL and support Link output --- atlasaction/action.go | 22 ++++++++++++---------- atlasaction/action_test.go | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- schema/push/action.yml | 4 ++++ 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/atlasaction/action.go b/atlasaction/action.go index 8ff1c8f..e9ea219 100644 --- a/atlasaction/action.go +++ b/atlasaction/action.go @@ -78,7 +78,7 @@ type AtlasExec interface { // MigrateTest runs the `migrate test` command. MigrateTest(context.Context, *atlasexec.MigrateTestParams) (string, error) // SchemaPush runs the `schema push` command. - SchemaPush(context.Context, *atlasexec.SchemaPushParams) (string, error) + SchemaPush(context.Context, *atlasexec.SchemaPushParams) (*atlasexec.SchemaPush, error) // SchemaTest runs the `schema test` command. SchemaTest(context.Context, *atlasexec.SchemaTestParams) (string, error) // SchemaPlan runs the `schema plan` command. @@ -452,15 +452,8 @@ func (a *Actions) SchemaPush(ctx context.Context) error { ConfigURL: a.GetInput("config"), Env: a.GetInput("env"), Vars: a.GetVarsInput("vars"), + Tag: a.GetInput("tag"), } - if a.GetBoolInput("latest") { - // Push the "latest" tag. - _, err := a.Atlas.SchemaPush(ctx, params) - if err != nil { - return fmt.Errorf("failed to push schema: %v", err) - } - } - params.Tag = a.GetInput("tag") if params.Tag == "" { // If the tag is not provided, use the commit SHA. params.Tag = params.Context.Commit @@ -469,8 +462,17 @@ func (a *Actions) SchemaPush(ctx context.Context) error { if err != nil { return fmt.Errorf("failed to push schema tag: %w", err) } + if a.GetBoolInput("latest") { + // Push the "latest" tag. + params.Tag = "latest" + if _, err := a.Atlas.SchemaPush(ctx, params); err != nil { + return fmt.Errorf("failed to push schema for latest tag: %v", err) + } + } a.Infof(`"atlas schema push" completed successfully to: %s`, resp) - a.SetOutput("url", resp) + a.SetOutput("link", resp.Link) + a.SetOutput("slug", resp.Slug) + a.SetOutput("url", resp.URL) return nil } diff --git a/atlasaction/action_test.go b/atlasaction/action_test.go index c0895da..fea0416 100644 --- a/atlasaction/action_test.go +++ b/atlasaction/action_test.go @@ -262,7 +262,7 @@ func TestMigrateDown(t *testing.T) { type mockAtlas struct { migrateDown func(context.Context, *atlasexec.MigrateDownParams) (*atlasexec.MigrateDown, error) - schemaPush func(context.Context, *atlasexec.SchemaPushParams) (string, error) + schemaPush func(context.Context, *atlasexec.SchemaPushParams) (*atlasexec.SchemaPush, error) schemaPlan func(context.Context, *atlasexec.SchemaPlanParams) (*atlasexec.SchemaPlan, error) schemaPlanList func(context.Context, *atlasexec.SchemaPlanListParams) ([]atlasexec.SchemaPlanFile, error) schemaPlanLint func(context.Context, *atlasexec.SchemaPlanLintParams) (*atlasexec.SchemaPlan, error) @@ -297,7 +297,7 @@ func (m *mockAtlas) MigrateTest(context.Context, *atlasexec.MigrateTestParams) ( } // SchemaPush implements AtlasExec. -func (m *mockAtlas) SchemaPush(ctx context.Context, p *atlasexec.SchemaPushParams) (string, error) { +func (m *mockAtlas) SchemaPush(ctx context.Context, p *atlasexec.SchemaPushParams) (*atlasexec.SchemaPush, error) { return m.schemaPush(ctx, p) } diff --git a/go.mod b/go.mod index e52a8c4..fdde845 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.23 require ( ariga.io/atlas v0.21.2-0.20240418081819-02b3f6239b04 - ariga.io/atlas-go-sdk v0.5.9-0.20240917095830-41bde7d654aa + ariga.io/atlas-go-sdk v0.6.0 github.com/alecthomas/kong v0.8.0 github.com/mattn/go-sqlite3 v1.14.17 github.com/mitchellh/mapstructure v1.1.2 diff --git a/go.sum b/go.sum index 420f3df..5486c49 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ ariga.io/atlas v0.21.2-0.20240418081819-02b3f6239b04 h1:YF3qiqtnhn+y4tfhZKTfZKfizpjqHYt7rWPUb+eA4ZA= ariga.io/atlas v0.21.2-0.20240418081819-02b3f6239b04/go.mod h1:VPlcXdd4w2KqKnH54yEZcry79UAhpaWaxEsmn5JRNoE= -ariga.io/atlas-go-sdk v0.5.9-0.20240917095830-41bde7d654aa h1:zdQVDEW8c8n7SbBDjY7vcuaoOTnhfh/QKqhTKrZ1aqQ= -ariga.io/atlas-go-sdk v0.5.9-0.20240917095830-41bde7d654aa/go.mod h1:9Q+/04PVyJHUse1lEE9Kp6E18xj/6mIzaUTcWYSjSnQ= +ariga.io/atlas-go-sdk v0.6.0 h1:+i4+M1Lug5BwaLWf62CP+j5S/vrlTJgQKnY6gKHNDco= +ariga.io/atlas-go-sdk v0.6.0/go.mod h1:9Q+/04PVyJHUse1lEE9Kp6E18xj/6mIzaUTcWYSjSnQ= github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM= github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo= diff --git a/schema/push/action.yml b/schema/push/action.yml index adbb4cb..b671a2b 100644 --- a/schema/push/action.yml +++ b/schema/push/action.yml @@ -46,6 +46,10 @@ inputs: default: "true" required: false outputs: + link: + description: Link to the schema version on Atlas. + slug: + description: The slug of the pushed schema version. url: description: The URL of the pushed schema version. runs: