-
Notifications
You must be signed in to change notification settings - Fork 801
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
[Release Automation] Update Helm/SDK/Install Packages Version Numbers #3149
Changes from 1 commit
7d9cc5c
b7836b6
34e9a3f
477a7fa
4979cab
bd6171c
eb00496
5a07622
b6676f4
4cc2ef9
4f9c804
8aafd11
a7a2eb3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"regexp" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) < 2 { | ||
fmt.Println("Please provide the initial version as a command-line argument") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. log.Fatalf here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. used log instead fmt package |
||
return | ||
} | ||
|
||
initialVersion := os.Args[1] | ||
files := []string{ | ||
"install/helm/agones/Chart.yaml", | ||
"install/yaml/install.yaml", | ||
"install/helm/agones/values.yaml", | ||
"sdks/nodejs/package.json", | ||
"sdks/nodejs/package-lock.json", | ||
"sdks/unity/package.json", | ||
"sdks/csharp/sdk/AgonesSDK.nuspec", | ||
"sdks/csharp/sdk/csharp-sdk.csproj", | ||
} | ||
|
||
for _, filename := range files { | ||
err := UpdateVersionInFile(filename, initialVersion) | ||
if err != nil { | ||
fmt.Printf("Error updating file %s: %s\n", filename, err.Error()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. used log instead fmt |
||
} | ||
} | ||
} | ||
|
||
func UpdateVersionInFile(filename string, initialVersion string) error { | ||
fileBytes, err := ioutil.ReadFile(filename) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
content := string(fileBytes) | ||
|
||
// Check the file extension and update version accordingly | ||
ext := filepath.Ext(filename) | ||
switch ext { | ||
case ".yaml", ".yml", ".nuspec", ".csproj": | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this needs a case statement. It seems like you can just write it as
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to update the JSON files without a switch/case statement, but the syntax was slightly different. So created a switch/case statement to ensure that the files were updated correctly. |
||
content = updateVersion(content, initialVersion) | ||
case ".json": | ||
content = updateJSONVersion(content, initialVersion) | ||
} | ||
|
||
err = ioutil.WriteFile(filename, []byte(content), 0644) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func updateVersion(content string, initialVersion string) string { | ||
re := regexp.MustCompile(regexp.QuoteMeta(initialVersion)) | ||
newVersion := incrementVersion(initialVersion) | ||
return re.ReplaceAllString(content, newVersion+"-dev") | ||
} | ||
|
||
func updateJSONVersion(content string, initialVersion string) string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like the only difference here is handling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes that's correct |
||
re := regexp.MustCompile(`"` + regexp.QuoteMeta(initialVersion) + `"`) | ||
newVersion := incrementVersion(initialVersion) + "-dev" | ||
return re.ReplaceAllString(content, `"`+newVersion+`"`) | ||
} | ||
|
||
func incrementVersion(version string) string { | ||
segments := strings.Split(version, ".") | ||
lastButOneSegment, _ := strconv.Atoi(segments[len(segments)-2]) | ||
segments[len(segments)-2] = strconv.Itoa(lastButOneSegment + 1) | ||
return strings.Join(segments, ".") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"regexp" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) < 2 { | ||
fmt.Println("Please provide the value to update as a command-line argument") | ||
return | ||
} | ||
|
||
valueToUpdate := os.Args[1] | ||
|
||
files := []string{ | ||
"install/helm/agones/Chart.yaml", | ||
"install/yaml/install.yaml", | ||
"install/helm/agones/values.yaml", | ||
"sdks/nodejs/package.json", | ||
"sdks/nodejs/package-lock.json", | ||
"sdks/unity/package.json", | ||
"sdks/csharp/sdk/AgonesSDK.nuspec", | ||
"sdks/csharp/sdk/csharp-sdk.csproj", | ||
} | ||
|
||
for _, filename := range files { | ||
err := UpdateValueInFile(filename, valueToUpdate) | ||
if err != nil { | ||
fmt.Printf("Error updating file %s: %s\n", filename, err.Error()) | ||
} | ||
} | ||
} | ||
|
||
func UpdateValueInFile(filename string, valueToUpdate string) error { | ||
fileBytes, err := ioutil.ReadFile(filename) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
content := string(fileBytes) | ||
|
||
// Check the file extension and update values accordingly | ||
ext := filepath.Ext(filename) | ||
switch ext { | ||
case ".yaml", ".yml", ".nuspec", ".csproj": | ||
content = updateValues(content, valueToUpdate) | ||
case ".json": | ||
content = updateJSONValues(content, valueToUpdate) | ||
} | ||
|
||
err = ioutil.WriteFile(filename, []byte(content), 0644) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func updateValues(content string, valueToUpdate string) string { | ||
re := regexp.MustCompile(`(\d+\.\d+\.\d+)-dev`) | ||
return re.ReplaceAllString(content, "${1}") | ||
} | ||
|
||
func updateJSONValues(content string, valueToUpdate string) string { | ||
re := regexp.MustCompile(`"(\d+\.\d+\.\d+)-dev"`) | ||
return re.ReplaceAllString(content, `"$1"`) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rather than the heavy duplication between
after-release
andbefore-release
, I would recommend using a flag. For a script like this, no worries using the standard flag library: https://pkg.go.dev/flagExamples in our repo include: https://github.com/googleforgames/agones/blob/main/examples/simple-game-server/main.go#L41-L49
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated the code to make it a single script using Flag. Thanks!