From 868261abe17837f987c57888616d658a7bf7860b Mon Sep 17 00:00:00 2001 From: tuti Date: Thu, 12 Sep 2024 16:39:11 -0700 Subject: [PATCH] halt hash release process if already published --- release/build/main.go | 7 +++++-- release/pkg/tasks/hashrelease.go | 15 +++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/release/build/main.go b/release/build/main.go index 81621148dc2..16d3414d16d 100644 --- a/release/build/main.go +++ b/release/build/main.go @@ -138,8 +138,11 @@ func hashreleaseSubCommands(cfg *config.Config, runner *registry.DockerRunner) [ tasks.PreReleaseValidate(cfg) } - // Create the pinned-version.yaml file and extract the versions. - ver, operatorVer := tasks.PinnedVersion(cfg) + // Create the pinned-version.yaml file and extract the versions and hash. + ver, operatorVer, hash := tasks.PinnedVersion(cfg) + + // Check if the hashrelease has already been published. If so, then we can skip + tasks.CheckIfHashReleasePublished(cfg, hash) // Build the operator. tasks.OperatorHashreleaseBuild(runner, cfg) diff --git a/release/pkg/tasks/hashrelease.go b/release/pkg/tasks/hashrelease.go index 3b49e13e101..4c72cc72ef6 100644 --- a/release/pkg/tasks/hashrelease.go +++ b/release/pkg/tasks/hashrelease.go @@ -31,7 +31,7 @@ func ciURL() string { // It clones the operator repository, // then call GeneratePinnedVersion to generate the pinned-version.yaml file. // The location of the pinned-version.yaml file is logged. -func PinnedVersion(cfg *config.Config) (string, string) { +func PinnedVersion(cfg *config.Config) (string, string, string) { tmpDir := cfg.TmpFolderPath() if err := os.MkdirAll(tmpDir, utils.DirPerms); err != nil { logrus.WithError(err).Fatal("Failed to create output directory") @@ -49,7 +49,7 @@ func PinnedVersion(cfg *config.Config) (string, string) { logrus.WithError(err).Fatal("Failed to generate pinned-version.yaml") } logrus.WithField("file", pinnedVersionFilePath).Info("Generated pinned-version.yaml") - return data.ProductVersion, data.Operator.Version + return data.ProductVersion, data.Operator.Version, data.Hash } type imageExistsResult struct { @@ -158,6 +158,13 @@ func HashreleaseValidate(cfg *config.Config, skipISS bool) { } } +func CheckIfHashReleasePublished(cfg *config.Config, hash string) { + sshConfig := command.NewSSHConfig(cfg.DocsHost, cfg.DocsUser, cfg.DocsKey, cfg.DocsPort) + if hashrelease.Exists(hash, sshConfig) { + logrus.WithField("hash", hash).Fatal("Hashrelease already exists") + } +} + // HashreleaseValidate publishes the hashrelease func HashreleasePush(cfg *config.Config, path string) { tmpDir := cfg.TmpFolderPath() @@ -186,10 +193,6 @@ func HashreleasePush(cfg *config.Config, path string) { if err != nil { logrus.WithError(err).Fatal("Failed to get release hash") } - if hashrelease.Exists(releaseHash, sshConfig) { - logrus.WithField("hashrelease", releaseHash).Warn("Hashrelease already exists") - return - } logrus.WithField("note", note).Info("Publishing hashrelease") if err := hashrelease.Publish(name, releaseHash, note, productBranch, path, sshConfig); err != nil { logrus.WithError(err).Fatal("Failed to publish hashrelease")