Skip to content

Commit

Permalink
halt hash release process if already published
Browse files Browse the repository at this point in the history
  • Loading branch information
radTuti committed Sep 12, 2024
1 parent 756c62e commit 868261a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
7 changes: 5 additions & 2 deletions release/build/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 9 additions & 6 deletions release/pkg/tasks/hashrelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 868261a

Please sign in to comment.