@@ -2,6 +2,7 @@ package cmd
22
33import (
44 "bytes"
5+ "context"
56 "fmt"
67 "io"
78 "os"
@@ -21,19 +22,21 @@ import (
2122
2223func compareCmd () * cobra.Command {
2324 var provider , repository , oldCommit , newCommit string
25+ var maxChanges int
2426
2527 command := & cobra.Command {
2628 Use : "compare" ,
2729 Short : "Compare two versions of a Pulumi schema" ,
2830 RunE : func (cmd * cobra.Command , args []string ) error {
29- return compare (provider , repository , oldCommit , newCommit )
31+ return compare (provider , repository , oldCommit , newCommit , maxChanges )
3032 },
3133 }
3234
3335 command .Flags ().StringVarP (& provider , "provider" , "p" , "" , "the provider whose schema we are comparing" )
3436 _ = command .MarkFlagRequired ("provider" )
3537
36- command .Flags ().StringVarP (& repository , "repository" , "r" , "github://api.github.com/pulumi" , "the Git repository to download the schema file from" )
38+ command .Flags ().StringVarP (& repository , "repository" , "r" ,
39+ "github://api.github.com/pulumi" , "the Git repository to download the schema file from" )
3740 _ = command .MarkFlagRequired ("provider" )
3841
3942 command .Flags ().StringVarP (& oldCommit , "old-commit" , "o" , "master" ,
@@ -43,22 +46,33 @@ func compareCmd() *cobra.Command {
4346 "the new commit to compare against the old commit" )
4447 _ = command .MarkFlagRequired ("new-commit" )
4548
49+ command .Flags ().IntVarP (& maxChanges , "max-changes" , "m" , 500 ,
50+ "the maximum number of breaking changes to display. Pass -1 to display all changes" )
51+
4652 return command
4753}
4854
49- func compare (provider string , repository string , oldCommit string , newCommit string ) error {
50- schOld , err := pkg .DownloadSchema (repository , provider , oldCommit )
51- if err != nil {
52- return err
53- }
55+ func compare (provider string , repository string , oldCommit string , newCommit string , maxChanges int ) error {
56+ ctx , cancel := context .WithCancel (context .Background ())
57+ defer cancel ()
58+ var schOld schema.PackageSpec
59+ schOldDone := make (chan error )
60+ go func () {
61+ var err error
62+ schOld , err = pkg .DownloadSchema (ctx , repository , provider , oldCommit )
63+ if err != nil {
64+ cancel ()
65+ }
66+ schOldDone <- err
67+ }()
5468
5569 var schNew schema.PackageSpec
56-
5770 if newCommit == "--local" {
5871 usr , _ := user .Current ()
5972 basePath := fmt .Sprintf ("%s/go/src/github.com/pulumi/%s" , usr .HomeDir , provider )
6073 schemaFile := pkg .StandardSchemaPath (provider )
6174 schemaPath := filepath .Join (basePath , schemaFile )
75+ var err error
6276 schNew , err = pkg .LoadLocalPackageSpec (schemaPath )
6377 if err != nil {
6478 return err
@@ -74,12 +88,18 @@ func compare(provider string, repository string, oldCommit string, newCommit str
7488 return err
7589 }
7690 } else {
77- schNew , err = pkg .DownloadSchema (repository , provider , newCommit )
91+ var err error
92+ schNew , err = pkg .DownloadSchema (ctx , repository , provider , newCommit )
7893 if err != nil {
7994 return err
8095 }
8196 }
82- compareSchemas (os .Stdout , provider , schOld , schNew )
97+
98+ if err := <- schOldDone ; err != nil {
99+ return err
100+ }
101+
102+ compareSchemas (os .Stdout , provider , schOld , schNew , maxChanges )
83103 return nil
84104}
85105
@@ -184,6 +204,24 @@ func breakingChanges(oldSchema, newSchema schema.PackageSpec) *diagtree.Node {
184204 }
185205 }
186206
207+ // The upstream issue is tracked at
208+ // https://github.com/pulumi/pulumi/issues/13563.
209+ isNonZeroArgs := func (ts * schema.ObjectTypeSpec ) bool {
210+ if ts == nil {
211+ return false
212+ }
213+ return len (ts .Properties ) > 0
214+ }
215+ type nonZeroArgs struct { old , new bool }
216+ switch (nonZeroArgs {old : isNonZeroArgs (f .Inputs ), new : isNonZeroArgs (newFunc .Inputs )}) {
217+ case nonZeroArgs {false , true }:
218+ msg .SetDescription (diagtree .Danger ,
219+ "signature change (pulumi.InvokeOptions)->T => (Args, pulumi.InvokeOptions)->T" )
220+ case nonZeroArgs {true , false }:
221+ msg .SetDescription (diagtree .Danger ,
222+ "signature change (Args, pulumi.InvokeOptions)->T => (pulumi.InvokeOptions)->T" )
223+ }
224+
187225 if f .Outputs != nil {
188226 msg := msg .Label ("outputs" )
189227 for propName , prop := range f .Outputs .Properties {
@@ -260,11 +298,11 @@ func breakingChanges(oldSchema, newSchema schema.PackageSpec) *diagtree.Node {
260298 return msg
261299}
262300
263- func compareSchemas (out io.Writer , provider string , oldSchema , newSchema schema.PackageSpec ) {
301+ func compareSchemas (out io.Writer , provider string , oldSchema , newSchema schema.PackageSpec , maxChanges int ) {
264302 fmt .Fprintf (out , "### Does the PR have any schema changes?\n \n " )
265303 violations := breakingChanges (oldSchema , newSchema )
266304 displayedViolations := new (bytes.Buffer )
267- lenViolations := violations .Display (displayedViolations , 500 )
305+ lenViolations := violations .Display (displayedViolations , maxChanges )
268306 switch lenViolations {
269307 case 0 :
270308 fmt .Fprintln (out , "Looking good! No breaking changes found." )
0 commit comments