Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle creation of RELEASE file in new Go version Release #1342

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,24 @@ func bumpRelease(gClient git.Client, r *Release) error {

content, err := gClient.ReadFile(releasePath)
if err != nil {
logger.Error(err, "Reading file", "file", releasePath)
return err
}
// Check if there is a new line character at the end of the file, if so take all but the newline
if content[len(content)-1:] == "\n" {
content = content[0 : len(content)-1]
}
cr, err := strconv.Atoi(content)
if err != nil {
logger.Error(err, "Converting current release to int")
return err
if !strings.Contains(err.Error(), "file not found") {
logger.Error(err, "Reading file", "file", releasePath)
return err
}
r.Release = 0
} else {
// Check if there is a new line character at the end of the file, if so take all but the newline
if content[len(content)-1:] == "\n" {
content = content[0 : len(content)-1]
}
cr, err := strconv.Atoi(content)
if err != nil {
logger.Error(err, "Converting current release to int")
return err
}
// Increment release
r.Release = cr + 1
}
// Increment release
r.Release = cr + 1
logger.V(4).Info("release bumped to", "release", r.Release)

return nil
Expand All @@ -187,7 +191,13 @@ func updateRelease(gClient git.Client, r *Release) error {
releaseContent := fmt.Sprintf("%d", r.ReleaseNumber())
logger.V(4).Info("Update RELEASE", "path", releasePath, "content", releaseContent)
if err := gClient.ModifyFile(releasePath, []byte(releaseContent)); err != nil {
return err
if !strings.Contains(err.Error(), "file not found") {
return err
}
releaseContent = fmt.Sprintf("%d", 0)
if err := gClient.CreateFile(releasePath, []byte(releaseContent)); err != nil {
return err
}
}
if err := gClient.Add(releasePath); err != nil {
logger.Error(err, "git add", "file", releasePath)
Expand Down Expand Up @@ -269,7 +279,7 @@ func updateGoSpec(gClient git.Client, r *Release) error {

func addTempFilesForNewMinorVersion(gClient git.Client, r *Release) error {
// Add golang.spec
specFilePath := fmt.Sprintf(rpmSourcePathFmt, constants.EksGoProjectPath, r.GoMinorVersion(), goSpecFile)
specFilePath := fmt.Sprintf(specPathFmt, constants.EksGoProjectPath, r.GoMinorVersion(), goSpecFile)
rf, err := gClient.ReadFile(newReleaseFile)
if err != nil {
logger.Error(err, "Reading newRelease.txt file")
Expand Down
Loading