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:
AJ ONeal 2026-03-01 00:05:06 -07:00
parent ed08958157
commit 833c68e708
No known key found for this signature in database

View File

@ -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)
}