Skip to content

Commit

Permalink
schema/push: fix URL and support Link output
Browse files Browse the repository at this point in the history
  • Loading branch information
giautm committed Sep 19, 2024
1 parent f1d2bde commit a31c1cb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 15 deletions.
22 changes: 12 additions & 10 deletions atlasaction/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions atlasaction/action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.5.9-0.20240919071359-7e984b1ef89d
github.com/alecthomas/kong v0.8.0
github.com/mattn/go-sqlite3 v1.14.17
github.com/mitchellh/mapstructure v1.1.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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.5.9-0.20240919071359-7e984b1ef89d h1:HlYsJ+WmExi5gYHvPlxQcgCyXThE4lNvPGxNn4mWAQk=
ariga.io/atlas-go-sdk v0.5.9-0.20240919071359-7e984b1ef89d/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=
Expand Down
4 changes: 4 additions & 0 deletions schema/push/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a31c1cb

Please sign in to comment.