Skip to content
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

Adding option to skip existing releases #111

Merged
merged 3 commits into from
Mar 15, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions cr/cmd/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion pkg/releaser/releaser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if len(existingRelease.Assets) > 0 makes sense. I'd tend to remove that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@unguiculus thank you! removed the check

continue
}
}
if err := r.github.CreateRelease(context.TODO(), release); err != nil {
return errors.Wrap(err, "error creating GitHub release")
}
Expand Down