From 64d3fb1d84a974736570fc0d66b7f186e6f5db45 Mon Sep 17 00:00:00 2001 From: Michael Thomas Lee / Intility AS Date: Mon, 6 Dec 2021 15:11:51 +0100 Subject: [PATCH] Add tag support for push --- internal/experimental/action/push.go | 13 +++++++++++-- internal/experimental/uploader/chart_uploader.go | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/internal/experimental/action/push.go b/internal/experimental/action/push.go index b125ae1f4..6b26583ce 100644 --- a/internal/experimental/action/push.go +++ b/internal/experimental/action/push.go @@ -55,6 +55,15 @@ func NewPushWithOpts(opts ...PushOpt) *Push { // Run executes 'helm push' against the given chart archive. func (p *Push) Run(chartRef string, remote string) (string, error) { + remoteSplit := strings.SplitN(remote, ":", 1) + + remoteUrl := remoteSplit[0] + + tag := "" + if len(remoteSplit) > 1 { + tag = remoteSplit[1] + } + var out strings.Builder c := uploader.ChartUploader{ @@ -63,9 +72,9 @@ func (p *Push) Run(chartRef string, remote string) (string, error) { Options: []pusher.Option{}, } - if registry.IsOCI(remote) { + if registry.IsOCI(remoteUrl) { c.Options = append(c.Options, pusher.WithRegistryClient(p.cfg.RegistryClient)) } - return out.String(), c.UploadTo(chartRef, remote) + return out.String(), c.UploadTo(chartRef, remoteUrl, tag) } diff --git a/internal/experimental/uploader/chart_uploader.go b/internal/experimental/uploader/chart_uploader.go index 87a9d5772..5938f46fb 100644 --- a/internal/experimental/uploader/chart_uploader.go +++ b/internal/experimental/uploader/chart_uploader.go @@ -39,7 +39,7 @@ type ChartUploader struct { } // UploadTo uploads a chart. Depending on the settings, it may also upload a provenance file. -func (c *ChartUploader) UploadTo(ref, remote string) error { +func (c *ChartUploader) UploadTo(ref, remote string, tag string) error { u, err := url.Parse(remote) if err != nil { return errors.Errorf("invalid chart URL format: %s", remote) @@ -54,5 +54,5 @@ func (c *ChartUploader) UploadTo(ref, remote string) error { return err } - return p.Push(ref, u.String(), c.Options...) + return p.Push(ref, fmt.Sprintf("%s:%s", u.String(), tag), c.Options...) }