From 9861a14ae41db80ba0470d3bb694fcf3f2f40b2b Mon Sep 17 00:00:00 2001 From: Eduardo Solis Date: Fri, 12 Mar 2021 15:41:45 -0600 Subject: [PATCH 1/3] Adding option to skip existing releases Signed-off-by: Eduardo Solis --- cr/cmd/upload.go | 1 + pkg/config/config.go | 1 + pkg/releaser/releaser.go | 7 ++++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cr/cmd/upload.go b/cr/cmd/upload.go index 8699fd25..492a45be 100644 --- a/cr/cmd/upload.go +++ b/cr/cmd/upload.go @@ -51,5 +51,6 @@ func init() { uploadCmd.Flags().StringP("git-base-url", "b", "https://api.github.com/", "GitHub Base URL (only needed for private GitHub)") uploadCmd.Flags().StringP("git-upload-url", "u", "https://uploads.github.com/", "GitHub Upload URL (only needed for private GitHub)") uploadCmd.Flags().StringP("commit", "c", "", "Target commit for release") + uploadCmd.Flags().Bool("skip-existing", false, "Skip upload if release exists") uploadCmd.Flags().String("release-name-template", "{{ .Name }}-{{ .Version }}", "Go template for computing release names, using chart metadata") } diff --git a/pkg/config/config.go b/pkg/config/config.go index b9f7dfa1..84cdd64a 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -56,6 +56,7 @@ type Options struct { PR bool `mapstructure:"pr"` Remote string `mapstructure:"remote"` ReleaseNameTemplate string `mapstructure:"release-name-template"` + SkipExisting bool `mapstructure:"skip-existing"` } func LoadConfiguration(cfgFile string, cmd *cobra.Command, requiredFlags []string) (*Options, error) { diff --git a/pkg/releaser/releaser.go b/pkg/releaser/releaser.go index 23263b23..118d9730 100644 --- a/pkg/releaser/releaser.go +++ b/pkg/releaser/releaser.go @@ -326,7 +326,12 @@ func (r *Releaser) CreateReleases() error { asset := &github.Asset{Path: provFile} release.Assets = append(release.Assets, asset) } - + if r.config.SkipExisting { + existingRelease, _ := r.github.GetRelease(context.TODO(), releaseName) + if existingRelease != nil && len(existingRelease.Assets) > 0 { + continue + } + } if err := r.github.CreateRelease(context.TODO(), release); err != nil { return errors.Wrap(err, "error creating GitHub release") } From 8c643f9c3c447eb7fdcfb3a44fc60aa3762a09a0 Mon Sep 17 00:00:00 2001 From: Eduardo Solis Date: Fri, 12 Mar 2021 16:36:20 -0600 Subject: [PATCH 2/3] fixing format Signed-off-by: Eduardo Solis --- pkg/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 84cdd64a..79ae19a0 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -56,7 +56,7 @@ type Options struct { PR bool `mapstructure:"pr"` Remote string `mapstructure:"remote"` ReleaseNameTemplate string `mapstructure:"release-name-template"` - SkipExisting bool `mapstructure:"skip-existing"` + SkipExisting bool `mapstructure:"skip-existing"` } func LoadConfiguration(cfgFile string, cmd *cobra.Command, requiredFlags []string) (*Options, error) { From 529538007ca2002c4794a6f74c603dd6d739a248 Mon Sep 17 00:00:00 2001 From: Eduardo Solis Date: Mon, 15 Mar 2021 09:32:40 -0500 Subject: [PATCH 3/3] removing secondary check for assets Signed-off-by: Eduardo Solis --- pkg/releaser/releaser.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/releaser/releaser.go b/pkg/releaser/releaser.go index 118d9730..ccb12a6d 100644 --- a/pkg/releaser/releaser.go +++ b/pkg/releaser/releaser.go @@ -328,7 +328,7 @@ func (r *Releaser) CreateReleases() error { } if r.config.SkipExisting { existingRelease, _ := r.github.GetRelease(context.TODO(), releaseName) - if existingRelease != nil && len(existingRelease.Assets) > 0 { + if existingRelease != nil { continue } }