feat: update new version in env file
All checks were successful
continuous-integration/drone/pr Build is passing

This commit is contained in:
p4u1 2024-07-08 17:55:40 +02:00
parent 4085eb6654
commit 7596982282
4 changed files with 48 additions and 0 deletions

View File

@ -240,6 +240,13 @@ EXAMPLE:
log.Fatalf("attempting to run post deploy commands, saw: %s", err)
}
}
if app.Recipe.Version != "" && specificVersion != "" && specificVersion != app.Recipe.Version {
err := app.WriteRecipeVersion(specificVersion)
if err != nil {
log.Fatalf("writing new recipe version in env file: %s", err)
}
}
return nil
},
}

View File

@ -211,6 +211,13 @@ EXAMPLE:
log.Fatal(err)
}
if app.Recipe.Version != "" {
err := app.WriteRecipeVersion(chosenDowngrade)
if err != nil {
log.Fatalf("writing new recipe version in env file: %s", err)
}
}
return nil
},
}

View File

@ -267,6 +267,13 @@ EXAMPLE:
}
}
if app.Recipe.Version != "" {
err := app.WriteRecipeVersion(chosenUpgrade)
if err != nil {
log.Fatalf("writing new recipe version in env file: %s", err)
}
}
return nil
},
}

View File

@ -568,3 +568,30 @@ func ReadAbraShCmdNames(abraSh string) ([]string, error) {
return cmdNames, nil
}
func (a App) WriteRecipeVersion(version string) error {
file, err := os.Open(a.Path)
if err != nil {
return err
}
defer file.Close()
scanner := bufio.NewScanner(file)
lines := []string{}
for scanner.Scan() {
line := scanner.Text()
if !strings.Contains(line, "RECIPE=") && !strings.Contains(line, "TYPE") {
lines = append(lines, line)
continue
}
splitted := strings.Split(line, ":")
line = fmt.Sprintf("%s:%s", splitted[0], version)
lines = append(lines, line)
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
return os.WriteFile(a.Path, []byte(strings.Join(lines, "\n")), os.ModePerm)
}