Skip to content

Commit

Permalink
Handle creation of RELEASE file in new Go version Release (#1342)
Browse files Browse the repository at this point in the history
* Handle creation of RELEASE file in new Go version Release

* handle creation of SPECS/golang.spec instead of SOURCES/golang.spec
  • Loading branch information
xdu31 authored Feb 14, 2024
1 parent 4fed5a4 commit 68e1ffc
Showing 1 changed file with 25 additions and 15 deletions.
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

0 comments on commit 68e1ffc

Please sign in to comment.