Skip to content

feat(push): Add tag support #3074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions internal/bundler/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,15 @@ func annotate() map[string]string {
return labels
}

func BuildRequest(ctx context.Context, dir, configPath string, results []*QuerySetArchive) (*pb.UploadArchiveRequest, error) {
func BuildRequest(ctx context.Context, dir, configPath string, results []*QuerySetArchive, tags []string) (*pb.UploadArchiveRequest, error) {
conf, err := readFile(dir, configPath)
if err != nil {
return nil, err
}
res := &pb.UploadArchiveRequest{
SqlcVersion: info.Version,
Config: conf,
Tags: tags,
Annotations: annotate(),
}
for i, result := range results {
Expand Down Expand Up @@ -126,12 +127,12 @@ func BuildRequest(ctx context.Context, dir, configPath string, results []*QueryS
return res, nil
}

func (up *Uploader) buildRequest(ctx context.Context, results []*QuerySetArchive) (*pb.UploadArchiveRequest, error) {
return BuildRequest(ctx, up.dir, up.configPath, results)
func (up *Uploader) buildRequest(ctx context.Context, results []*QuerySetArchive, tags []string) (*pb.UploadArchiveRequest, error) {
return BuildRequest(ctx, up.dir, up.configPath, results, tags)
}

func (up *Uploader) DumpRequestOut(ctx context.Context, result []*QuerySetArchive) error {
req, err := up.buildRequest(ctx, result)
req, err := up.buildRequest(ctx, result, []string{})
if err != nil {
return err
}
Expand All @@ -148,11 +149,11 @@ func (up *Uploader) DumpRequestOut(ctx context.Context, result []*QuerySetArchiv
return nil
}

func (up *Uploader) Upload(ctx context.Context, result []*QuerySetArchive) error {
func (up *Uploader) Upload(ctx context.Context, result []*QuerySetArchive, tags []string) error {
if err := up.Validate(); err != nil {
return err
}
req, err := up.buildRequest(ctx, result)
req, err := up.buildRequest(ctx, result, tags)
if err != nil {
return err
}
Expand Down
3 changes: 3 additions & 0 deletions internal/cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ type Options struct {
Env Env
Stderr io.Writer
MutateConfig func(*config.Config)
// TODO: Move these to a command-specific struct
Tags []string
Against string
Comment on lines +13 to +15
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is gross, right now we expect the syntax of the Verify and Push command to be the same. Will clean this up in another pull request.

}

func (o *Options) ReadConfig(dir, filename string) (string, *config.Config, error) {
Expand Down
11 changes: 10 additions & 1 deletion internal/cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,25 @@ import (
"github.com/sqlc-dev/sqlc/internal/config"
)

func init() {
pushCmd.Flags().StringSliceP("tag", "t", nil, "tag this push with a value")
}

var pushCmd = &cobra.Command{
Use: "push",
Aliases: []string{"upload"},
Short: "Push the schema, queries, and configuration for this project",
RunE: func(cmd *cobra.Command, args []string) error {
stderr := cmd.ErrOrStderr()
dir, name := getConfigPath(stderr, cmd.Flag("file"))
tags, err := cmd.Flags().GetStringSlice("tag")
if err != nil {
return err
}
opts := &Options{
Env: ParseEnv(cmd),
Stderr: stderr,
Tags: tags,
}
if err := Push(cmd.Context(), dir, name, opts); err != nil {
fmt.Fprintf(stderr, "error pushing: %s\n", err)
Expand Down Expand Up @@ -78,6 +87,6 @@ func Push(ctx context.Context, dir, filename string, opts *Options) error {
if e.DryRun {
return up.DumpRequestOut(ctx, p.results)
} else {
return up.Upload(ctx, p.results)
return up.Upload(ctx, p.results, opts.Tags)
}
}
16 changes: 13 additions & 3 deletions internal/cmd/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,24 @@ import (
quickdbv1 "github.com/sqlc-dev/sqlc/internal/quickdb/v1"
)

func init() {
verifyCmd.Flags().String("against", "", "compare against this tag")
}

var verifyCmd = &cobra.Command{
Use: "verify",
Short: "Verify schema, queries, and configuration for this project",
RunE: func(cmd *cobra.Command, args []string) error {
stderr := cmd.ErrOrStderr()
dir, name := getConfigPath(stderr, cmd.Flag("file"))
against, err := cmd.Flags().GetString("against")
if err != nil {
return err
}
opts := &Options{
Env: ParseEnv(cmd),
Stderr: stderr,
Env: ParseEnv(cmd),
Stderr: stderr,
Against: against,
}
if err := Verify(cmd.Context(), dir, name, opts); err != nil {
fmt.Fprintf(stderr, "error verifying: %s\n", err)
Expand All @@ -44,7 +53,7 @@ func Verify(ctx context.Context, dir, filename string, opts *Options) error {
if err := Process(ctx, p, dir, filename, opts); err != nil {
return err
}
req, err := bundler.BuildRequest(ctx, dir, configPath, p.results)
req, err := bundler.BuildRequest(ctx, dir, configPath, p.results, nil)
if err != nil {
return err
}
Expand All @@ -56,6 +65,7 @@ func Verify(ctx context.Context, dir, filename string, opts *Options) error {
}

resp, err := client.VerifyQuerySets(ctx, &quickdbv1.VerifyQuerySetsRequest{
Against: opts.Against,
SqlcVersion: req.SqlcVersion,
QuerySets: req.QuerySets,
Config: req.Config,
Expand Down
Loading