You've already forked go-semantic-release
chore(changelog): fix calculation of file name
This commit is contained in:
@@ -203,9 +203,7 @@ func (s *SemanticRelease) WriteChangeLog(changelogContent, file string, overwrit
|
|||||||
return os.WriteFile(file, []byte(changelogContent), 0644)
|
return os.WriteFile(file, []byte(changelogContent), 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
fileSizeMB := info.Size() / 1024 / 1024 / 1024
|
if bytesToMB(info.Size()) >= float64(maxChangelogFileSize) {
|
||||||
|
|
||||||
if fileSizeMB >= maxChangelogFileSize {
|
|
||||||
err := moveExistingChangelogFile(file)
|
err := moveExistingChangelogFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -214,6 +212,10 @@ func (s *SemanticRelease) WriteChangeLog(changelogContent, file string, overwrit
|
|||||||
return prependToFile(changelogContent, file)
|
return prependToFile(changelogContent, file)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func bytesToMB(bytes int64) float64 {
|
||||||
|
return float64(bytes) / 1024 / 1024 / 1024
|
||||||
|
}
|
||||||
|
|
||||||
func moveExistingChangelogFile(file string) error {
|
func moveExistingChangelogFile(file string) error {
|
||||||
filenameSeparated := strings.Split(filepath.Base(file), ".")
|
filenameSeparated := strings.Split(filepath.Base(file), ".")
|
||||||
|
|
||||||
@@ -221,7 +223,7 @@ func moveExistingChangelogFile(file string) error {
|
|||||||
// if yes the filename will be separated like this: "my.file.name", ".md"
|
// if yes the filename will be separated like this: "my.file.name", ".md"
|
||||||
if len(filenameSeparated) > 2 {
|
if len(filenameSeparated) > 2 {
|
||||||
separatedFilenameWithExtension := make([]string, 0)
|
separatedFilenameWithExtension := make([]string, 0)
|
||||||
separatedFilenameWithExtension = append(separatedFilenameWithExtension, strings.Join(filenameSeparated[:len(filenameSeparated)-2], "."))
|
separatedFilenameWithExtension = append(separatedFilenameWithExtension, strings.Join(filenameSeparated[:len(filenameSeparated)-1], "."))
|
||||||
separatedFilenameWithExtension = append(separatedFilenameWithExtension, filenameSeparated[len(filenameSeparated)-1])
|
separatedFilenameWithExtension = append(separatedFilenameWithExtension, filenameSeparated[len(filenameSeparated)-1])
|
||||||
filenameSeparated = separatedFilenameWithExtension
|
filenameSeparated = separatedFilenameWithExtension
|
||||||
}
|
}
|
||||||
@@ -253,7 +255,8 @@ func buildNewFileName(currentFileNameSeparated []string, counter int) string {
|
|||||||
if len(currentFileNameSeparated) == 1 {
|
if len(currentFileNameSeparated) == 1 {
|
||||||
return fmt.Sprintf("%s-%d", currentFileNameSeparated[0], counter)
|
return fmt.Sprintf("%s-%d", currentFileNameSeparated[0], counter)
|
||||||
}
|
}
|
||||||
fileNameWithoutExtension := strings.Join(currentFileNameSeparated[:len(currentFileNameSeparated)-2], ".")
|
|
||||||
|
fileNameWithoutExtension := strings.Join(currentFileNameSeparated[:len(currentFileNameSeparated)-1], ".")
|
||||||
fileExtension := currentFileNameSeparated[len(currentFileNameSeparated)-1]
|
fileExtension := currentFileNameSeparated[len(currentFileNameSeparated)-1]
|
||||||
return fmt.Sprintf("%s-%d.%s", fileNameWithoutExtension, counter, fileExtension)
|
return fmt.Sprintf("%s-%d.%s", fileNameWithoutExtension, counter, fileExtension)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user