Use git go module

This commit is contained in:
2025-03-29 22:59:37 +03:00
parent b243486822
commit 18a6569dcc
4 changed files with 231 additions and 37 deletions

View File

@@ -5,7 +5,6 @@ import (
"fmt"
"log"
"os"
"os/exec"
"regexp"
"strconv"
"strings"
@@ -127,34 +126,6 @@ func updateFiles(filePaths []string, oldVersion, newVersion string) {
}
}
// gitCommit выполняет коммит с внесёнными изменениями
func gitCommit(currentVersion, newVersion string, bc *BumpConfig) error {
commitMsg := strings.ReplaceAll(bc.Message, "{current_version}", currentVersion)
commitMsg = strings.ReplaceAll(commitMsg, "{new_version}", newVersion)
if bc.Commit {
if err := exec.Command("git", "add", ".").Run(); err != nil {
return fmt.Errorf("git add error: %w", err)
}
if err := exec.Command("git", "commit", "-m", commitMsg).Run(); err != nil {
return fmt.Errorf("git commit error: %w", err)
}
log.Printf("Committed with message: %s", commitMsg)
}
return nil
}
// gitTag ставит тэг на коммит
func gitTag(currentVersion, newVersion string, bc *BumpConfig) error {
if bc.Tag {
tagName := strings.ReplaceAll(bc.TagName, "{new_version}", newVersion)
if err := exec.Command("git", "tag", tagName).Run(); err != nil {
return fmt.Errorf("git tag error: %w", err)
}
log.Printf("Created git tag: %s", tagName)
}
return nil
}
// updateConfigFile обновляет исходный конфигурационный файл
func updateConfigFile(configPath string, newVersion string) error {
cfg, err := ini.Load(configPath)
@@ -238,16 +209,12 @@ func main() {
// Выполняем git commit и tag, если требуется
if shouldCommit {
if err := gitCommit(bc.CurrentVersion, newVersion, bc); err != nil {
log.Printf("Git commit error: %v", err)
}
gitCommit(bc, newVersion)
}
// Выполняем git commit и tag, если требуется
if shouldTag {
if err := gitTag(bc.CurrentVersion, newVersion, bc); err != nil {
log.Printf("Git tag error: %v", err)
}
gitTag(bc, newVersion)
}
// Обновляем конфигурационный файл