forked from toolshed/abra
fix: avoid overwriting non version env vars
See coop-cloud/organising#630
This commit is contained in:
@ -569,7 +569,7 @@ func ReadAbraShCmdNames(abraSh string) ([]string, error) {
|
||||
return cmdNames, nil
|
||||
}
|
||||
|
||||
func (a App) WriteRecipeVersion(version string) error {
|
||||
func (a App) WriteRecipeVersion(version string, dryRun bool) error {
|
||||
file, err := os.Open(a.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -581,7 +581,7 @@ func (a App) WriteRecipeVersion(version string) error {
|
||||
lines := []string{}
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
if !strings.Contains(line, "RECIPE=") && !strings.Contains(line, "TYPE") {
|
||||
if !strings.HasPrefix(line, "RECIPE=") && !strings.HasPrefix(line, "TYPE=") {
|
||||
lines = append(lines, line)
|
||||
continue
|
||||
}
|
||||
@ -606,8 +606,12 @@ func (a App) WriteRecipeVersion(version string) error {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
if err := os.WriteFile(a.Path, []byte(strings.Join(lines, "\n")), os.ModePerm); err != nil {
|
||||
log.Fatal(err)
|
||||
if !dryRun {
|
||||
if err := os.WriteFile(a.Path, []byte(strings.Join(lines, "\n")), os.ModePerm); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
log.Debugf("skipping writing version %s because dry run", version)
|
||||
}
|
||||
|
||||
if !skipped {
|
||||
|
Reference in New Issue
Block a user