mirror of
https://github.com/therootcompany/golib.git
synced 2026-03-02 23:57:59 +00:00
fix(monorel): skip writing .goreleaser.yaml when content is unchanged
Both init (initModuleGroup) and release (processModule) now compare the generated content against the file on disk before writing. If identical, the file is left untouched — preserving any compatible local edits. Also fix processModule commit message scope to chore(<prefix>): add .goreleaser.yaml, matching the convention already used by initModuleGroup.
This commit is contained in:
parent
ed08958157
commit
833c68e708
@ -964,9 +964,10 @@ func processModule(group *moduleGroup, relPath string) {
|
||||
// on disk and leave committing to the user.
|
||||
yamlContent := goreleaserYAML(projectName, bins)
|
||||
yamlPath := filepath.Join(modRoot, ".goreleaser.yaml")
|
||||
isNewFile := true
|
||||
if existing, err := os.ReadFile(yamlPath); err == nil {
|
||||
isNewFile = false
|
||||
existing, readErr := os.ReadFile(yamlPath)
|
||||
isNewFile := readErr != nil
|
||||
isChanged := isNewFile || string(existing) != yamlContent
|
||||
if !isNewFile && isChanged {
|
||||
// Warn if a stock {{ .ProjectName }} template is in use.
|
||||
hasProjectName := strings.Contains(string(existing), "{{ .ProjectName }}") ||
|
||||
strings.Contains(string(existing), "{{.ProjectName}}")
|
||||
@ -977,16 +978,18 @@ func processModule(group *moduleGroup, relPath string) {
|
||||
fmt.Fprintf(os.Stderr, " replacing stock goreleaser config with monorel-generated config.\n")
|
||||
}
|
||||
}
|
||||
if err := os.WriteFile(yamlPath, []byte(yamlContent), 0o644); err != nil {
|
||||
fatalf("writing %s: %v", yamlPath, err)
|
||||
if isChanged {
|
||||
if err := os.WriteFile(yamlPath, []byte(yamlContent), 0o644); err != nil {
|
||||
fatalf("writing %s: %v", yamlPath, err)
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "wrote %s\n", yamlPath)
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "wrote %s\n", yamlPath)
|
||||
|
||||
// 2. Auto-commit + auto-tag — only when the file was newly created.
|
||||
if isNewFile {
|
||||
mustRunIn(modRoot, "git", "add", ".goreleaser.yaml")
|
||||
if status := runIn(modRoot, "git", "status", "--porcelain", "--", ".goreleaser.yaml"); status != "" {
|
||||
commitMsg := "chore(release): add .goreleaser.yaml for " + projectName
|
||||
commitMsg := "chore(" + prefix + "): add .goreleaser.yaml"
|
||||
mustRunIn(modRoot, "git", "commit", "-m", commitMsg)
|
||||
fmt.Fprintf(os.Stderr, "committed: %s\n", commitMsg)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user