From 7e3134349ebb78b581ac2688eb10dbe0d75a70e9 Mon Sep 17 00:00:00 2001 From: Guilherme Caulada Date: Mon, 16 Oct 2023 11:14:30 -0300 Subject: [PATCH] Fix wrongfully publishing nightly versions as beta --- cmd/flags.go | 8 ++++++++ containers/opts_gcom.go | 4 ++++ pipelines/gcom_publish.go | 14 +++++++------- scripts/drone_publish_nightly_enterprise.sh | 3 ++- scripts/drone_publish_nightly_grafana.sh | 3 ++- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/cmd/flags.go b/cmd/flags.go index e8dd5707..e590b0b1 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -340,6 +340,14 @@ var GCOMFlags = []cli.Flag{ Usage: "URL used to download packages from grafana.com", Required: true, }, + &cli.BoolFlag{ + Name: "beta", + Usage: "Use when publishing a beta version", + }, + &cli.BoolFlag{ + Name: "nightly", + Usage: "Use when publishing a nightly version", + }, } // JoinFlags combines several slices of flags into one slice of flags. diff --git a/containers/opts_gcom.go b/containers/opts_gcom.go index eec684a7..63cc974f 100644 --- a/containers/opts_gcom.go +++ b/containers/opts_gcom.go @@ -11,6 +11,8 @@ type GCOMOpts struct { URL *url.URL DownloadURL *url.URL ApiKey string + Beta bool + Nightly bool } func GCOMOptsFromFlags(c cliutil.CLIContext) (*GCOMOpts, error) { @@ -26,5 +28,7 @@ func GCOMOptsFromFlags(c cliutil.CLIContext) (*GCOMOpts, error) { URL: apiUrl, DownloadURL: downloadUrl, ApiKey: c.String("api-key"), + Beta: c.Bool("beta"), + Nightly: c.Bool("nightly"), }, nil } diff --git a/pipelines/gcom_publish.go b/pipelines/gcom_publish.go index a2ee4c1f..19036184 100644 --- a/pipelines/gcom_publish.go +++ b/pipelines/gcom_publish.go @@ -15,26 +15,26 @@ import ( "golang.org/x/sync/semaphore" ) -func VersionPayloadFromFileName(name string) *containers.GCOMVersionPayload { +func VersionPayloadFromFileName(name string, opts *containers.GCOMOpts) *containers.GCOMVersionPayload { var ( - opts = TarOptsFromFileName(name) - splitVersion = strings.Split(opts.Version, ".") + tarOpts = TarOptsFromFileName(name) + splitVersion = strings.Split(tarOpts.Version, ".") stable = true nightly = false beta = false ) - if strings.Contains(opts.Version, "-") { + if opts.Beta { stable = false beta = true } - if strings.Contains(opts.Version, "nightly") { + if opts.Nightly { beta = false nightly = true } return &containers.GCOMVersionPayload{ - Version: opts.Version, + Version: tarOpts.Version, ReleaseDate: time.Now().Format(time.RFC3339Nano), Stable: stable, Beta: beta, @@ -95,7 +95,7 @@ func PublishGCOM(ctx context.Context, d *dagger.Client, args PipelineArgs) error tarOpts := TarOptsFromFileName(name) if _, ok := versionPayloads[tarOpts.Version]; !ok { log.Printf("[%s] Building version payload", tarOpts.Version) - versionPayloads[tarOpts.Version] = VersionPayloadFromFileName(name) + versionPayloads[tarOpts.Version] = VersionPayloadFromFileName(name, opts) } } diff --git a/scripts/drone_publish_nightly_enterprise.sh b/scripts/drone_publish_nightly_enterprise.sh index c62008c5..05c5eb1c 100644 --- a/scripts/drone_publish_nightly_enterprise.sh +++ b/scripts/drone_publish_nightly_enterprise.sh @@ -20,4 +20,5 @@ dagger run --silent go run ./cmd gcom publish \ $(find $local_dir | grep -e .rpm -e .tar.gz -e .exe -e .zip -e .deb | grep -v sha256 | awk '{print "--package=file://"$0}') \ --api-key=${GCOM_API_KEY} \ --api-url="https://grafana-dev.com/api/grafana-enterprise" \ - --download-url="https://dl.grafana.com/enterprise/release" \ No newline at end of file + --download-url="https://dl.grafana.com/enterprise/release" \ + --nightly \ No newline at end of file diff --git a/scripts/drone_publish_nightly_grafana.sh b/scripts/drone_publish_nightly_grafana.sh index c1c3d6b3..8c7d531d 100755 --- a/scripts/drone_publish_nightly_grafana.sh +++ b/scripts/drone_publish_nightly_grafana.sh @@ -39,4 +39,5 @@ dagger run --silent go run ./cmd gcom publish \ $(find $local_dir | grep -e .rpm -e .tar.gz -e .exe -e .zip -e .deb | grep -v sha256 | awk '{print "--package=file://"$0}') \ --api-key=${GCOM_API_KEY} \ --api-url="https://grafana.com/api/grafana" \ - --download-url="https://dl.grafana.com/oss/release" \ No newline at end of file + --download-url="https://dl.grafana.com/oss/release" \ + --nightly \ No newline at end of file