Skip to content

Commit e1309fb

Browse files
authored
feat(push): Add tag support (#3074)
Also support passing a tag to verify
1 parent ce95162 commit e1309fb

File tree

5 files changed

+136
-94
lines changed

5 files changed

+136
-94
lines changed

internal/bundler/upload.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,15 @@ func annotate() map[string]string {
8686
return labels
8787
}
8888

89-
func BuildRequest(ctx context.Context, dir, configPath string, results []*QuerySetArchive) (*pb.UploadArchiveRequest, error) {
89+
func BuildRequest(ctx context.Context, dir, configPath string, results []*QuerySetArchive, tags []string) (*pb.UploadArchiveRequest, error) {
9090
conf, err := readFile(dir, configPath)
9191
if err != nil {
9292
return nil, err
9393
}
9494
res := &pb.UploadArchiveRequest{
9595
SqlcVersion: info.Version,
9696
Config: conf,
97+
Tags: tags,
9798
Annotations: annotate(),
9899
}
99100
for i, result := range results {
@@ -126,12 +127,12 @@ func BuildRequest(ctx context.Context, dir, configPath string, results []*QueryS
126127
return res, nil
127128
}
128129

129-
func (up *Uploader) buildRequest(ctx context.Context, results []*QuerySetArchive) (*pb.UploadArchiveRequest, error) {
130-
return BuildRequest(ctx, up.dir, up.configPath, results)
130+
func (up *Uploader) buildRequest(ctx context.Context, results []*QuerySetArchive, tags []string) (*pb.UploadArchiveRequest, error) {
131+
return BuildRequest(ctx, up.dir, up.configPath, results, tags)
131132
}
132133

133134
func (up *Uploader) DumpRequestOut(ctx context.Context, result []*QuerySetArchive) error {
134-
req, err := up.buildRequest(ctx, result)
135+
req, err := up.buildRequest(ctx, result, []string{})
135136
if err != nil {
136137
return err
137138
}
@@ -148,11 +149,11 @@ func (up *Uploader) DumpRequestOut(ctx context.Context, result []*QuerySetArchiv
148149
return nil
149150
}
150151

151-
func (up *Uploader) Upload(ctx context.Context, result []*QuerySetArchive) error {
152+
func (up *Uploader) Upload(ctx context.Context, result []*QuerySetArchive, tags []string) error {
152153
if err := up.Validate(); err != nil {
153154
return err
154155
}
155-
req, err := up.buildRequest(ctx, result)
156+
req, err := up.buildRequest(ctx, result, tags)
156157
if err != nil {
157158
return err
158159
}

internal/cmd/options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ type Options struct {
1010
Env Env
1111
Stderr io.Writer
1212
MutateConfig func(*config.Config)
13+
// TODO: Move these to a command-specific struct
14+
Tags []string
15+
Against string
1316
}
1417

1518
func (o *Options) ReadConfig(dir, filename string) (string, *config.Config, error) {

internal/cmd/push.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,25 @@ import (
1313
"github.com/sqlc-dev/sqlc/internal/config"
1414
)
1515

16+
func init() {
17+
pushCmd.Flags().StringSliceP("tag", "t", nil, "tag this push with a value")
18+
}
19+
1620
var pushCmd = &cobra.Command{
1721
Use: "push",
1822
Aliases: []string{"upload"},
1923
Short: "Push the schema, queries, and configuration for this project",
2024
RunE: func(cmd *cobra.Command, args []string) error {
2125
stderr := cmd.ErrOrStderr()
2226
dir, name := getConfigPath(stderr, cmd.Flag("file"))
27+
tags, err := cmd.Flags().GetStringSlice("tag")
28+
if err != nil {
29+
return err
30+
}
2331
opts := &Options{
2432
Env: ParseEnv(cmd),
2533
Stderr: stderr,
34+
Tags: tags,
2635
}
2736
if err := Push(cmd.Context(), dir, name, opts); err != nil {
2837
fmt.Fprintf(stderr, "error pushing: %s\n", err)
@@ -78,6 +87,6 @@ func Push(ctx context.Context, dir, filename string, opts *Options) error {
7887
if e.DryRun {
7988
return up.DumpRequestOut(ctx, p.results)
8089
} else {
81-
return up.Upload(ctx, p.results)
90+
return up.Upload(ctx, p.results, opts.Tags)
8291
}
8392
}

internal/cmd/verify.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,24 @@ import (
1212
quickdbv1 "github.com/sqlc-dev/sqlc/internal/quickdb/v1"
1313
)
1414

15+
func init() {
16+
verifyCmd.Flags().String("against", "", "compare against this tag")
17+
}
18+
1519
var verifyCmd = &cobra.Command{
1620
Use: "verify",
1721
Short: "Verify schema, queries, and configuration for this project",
1822
RunE: func(cmd *cobra.Command, args []string) error {
1923
stderr := cmd.ErrOrStderr()
2024
dir, name := getConfigPath(stderr, cmd.Flag("file"))
25+
against, err := cmd.Flags().GetString("against")
26+
if err != nil {
27+
return err
28+
}
2129
opts := &Options{
22-
Env: ParseEnv(cmd),
23-
Stderr: stderr,
30+
Env: ParseEnv(cmd),
31+
Stderr: stderr,
32+
Against: against,
2433
}
2534
if err := Verify(cmd.Context(), dir, name, opts); err != nil {
2635
fmt.Fprintf(stderr, "error verifying: %s\n", err)
@@ -44,7 +53,7 @@ func Verify(ctx context.Context, dir, filename string, opts *Options) error {
4453
if err := Process(ctx, p, dir, filename, opts); err != nil {
4554
return err
4655
}
47-
req, err := bundler.BuildRequest(ctx, dir, configPath, p.results)
56+
req, err := bundler.BuildRequest(ctx, dir, configPath, p.results, nil)
4857
if err != nil {
4958
return err
5059
}
@@ -56,6 +65,7 @@ func Verify(ctx context.Context, dir, filename string, opts *Options) error {
5665
}
5766

5867
resp, err := client.VerifyQuerySets(ctx, &quickdbv1.VerifyQuerySetsRequest{
68+
Against: opts.Against,
5969
SqlcVersion: req.SqlcVersion,
6070
QuerySets: req.QuerySets,
6171
Config: req.Config,

0 commit comments

Comments
 (0)