Skip to content

Commit

Permalink
feat: update tag script to handle telemetryservice image from control…
Browse files Browse the repository at this point in the history
…ler (#1061)
  • Loading branch information
tomqin93 authored Dec 3, 2024
1 parent 539475c commit 4196d40
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions tools/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ import (

func main() {
args := os.Args
if len(args) < 3 {
if len(args) < 4 {
panic("few parameters")
}

path, oldTag, newTag := args[1], args[2], args[3]
files, err := traverseDir(path)
workDir, oldTag, newTag := args[1], args[2], args[3]
files, err := traverseDir(workDir)
if err != nil {
fmt.Printf("err cannot get all deployment.yaml file! %v", err)
fmt.Printf("err cannot get all deployment.yaml and .go files! %v", err)
panic(err)
}

Expand All @@ -36,7 +36,7 @@ func main() {

func traverseDir(workPath string) ([]string, error) {
var files []string
var yamls []string
var targetFiles []string
err := filepath.Walk(workPath, func(path string, info os.FileInfo, err error) error {
files = append(files, path)
return nil
Expand All @@ -47,16 +47,17 @@ func traverseDir(workPath string) ([]string, error) {
}

for _, file := range files {
if path.Ext(file) == ".yaml" {
if path.Ext(file) == ".yaml" || path.Ext(file) == ".go" {
filename := path.Base(file)
if strings.Contains(filename, "deployment") ||
strings.Contains(filename, "install") {
yamls = append(yamls, file)
strings.Contains(filename, "install") ||
filename == "telemetryservice_controller.go" {
targetFiles = append(targetFiles, file)
}
}
}

return yamls, nil
return targetFiles, nil
}

func updateTag(files []string, oldTag string, newTag string) error {
Expand Down Expand Up @@ -100,14 +101,16 @@ func replaceTag(file *os.File, oldTag string, newTag string) error {
return err
}

if strings.Contains(line, "image") &&
// Handle image updates in both deployment files and controller constants
if (strings.Contains(line, "image") &&
(strings.Contains(line, "deviceshifu") ||
strings.Contains(line, "mockdevice") ||
strings.Contains(line, "telemetryservice") ||
strings.Contains(line, "mockserver") ||
strings.Contains(line, "humidity")) ||
strings.Contains(line, "gateway") &&
strings.Contains(line, oldTag) {
strings.Contains(line, "humidity") ||
strings.Contains(line, "gateway"))) ||
(strings.Contains(line, "const IMAGE = ") &&
strings.Contains(line, "edgehub/telemetryservice")) {
line = strings.Replace(line, oldTag, newTag, 1)
}

Expand Down

0 comments on commit 4196d40

Please sign in to comment.