forked from toolshed/abra
		
	feat: update new version in env file
This commit is contained in:
		| @ -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 | ||||
| 	}, | ||||
| } | ||||
|  | ||||
| @ -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 | ||||
| 	}, | ||||
| } | ||||
|  | ||||
| @ -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 | ||||
| 	}, | ||||
| } | ||||
|  | ||||
| @ -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) | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user