Skip to content

Commit

Permalink
[release tool] fix hashrelease failure (#9661)
Browse files Browse the repository at this point in the history
* fix checking if hashrelease already exists

* split hashrelease commands

* address review feedback
  • Loading branch information
radTuti committed Dec 31, 2024
1 parent 2b66fb7 commit 1b3d3de
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
8 changes: 6 additions & 2 deletions release/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ ci: static-checks
###############################################################################
# Hashrelease
###############################################################################
.PHONY: hashrelease
hashrelease: bin/release var-require-all-GITHUB_TOKEN
.PHONY: hashrelease hashrelease-build hashrelease-publish
hashrelease: hashrelease-build hashrelease-publish

hashrelease-build: bin/release var-require-all-GITHUB_TOKEN
@bin/release hashrelease build

hashrelease-publish: bin/release var-require-all-GITHUB_TOKEN
@bin/release hashrelease publish

###############################################################################
Expand Down
13 changes: 10 additions & 3 deletions release/internal/hashreleaseserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,17 @@ func remoteReleasesLibraryPath(user string) string {
func HasHashrelease(hash string, cfg *Config) (bool, error) {
logrus.WithField("hash", hash).Debug("Checking if hashrelease exists")
out, err := runSSHCommand(cfg, fmt.Sprintf("cat %s | grep %s", remoteReleasesLibraryPath(cfg.User), hash))
if err == nil {
return strings.Contains(out, hash), nil
if err != nil {
if strings.Contains(err.Error(), "exited with status 1") {
// Process exited with status 1 is from grep when no match is found
logrus.WithError(err).Error("Hashrelease not found")
return false, nil
} else {
logrus.WithError(err).Error("Failed to check hashrelease library")
return false, err
}
}
return false, err
return strings.Contains(out, hash), nil
}

// SetHashreleaseAsLatest sets the hashrelease as the latest for the stream
Expand Down
2 changes: 1 addition & 1 deletion release/internal/hashreleaseserver/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func runSSHCommand(cfg *Config, command string) (string, error) {
defer session.Close()
var stdoutBuf bytes.Buffer
session.Stdout = &stdoutBuf
logrus.WithField("command", command).Info("Running command in remote host")
logrus.WithField("command", command).Debug("Running command in remote host")
if err := session.Run(command); err != nil {
return "", err
}
Expand Down

0 comments on commit 1b3d3de

Please sign in to comment.