fix(monorel): skip writing .goreleaser.yaml when content is unchanged

Compare generated content against the file on disk before writing.
If identical, do nothing — no write, no "wrote" message, no commit attempt.
This commit is contained in:
AJ ONeal 2026-03-01 00:02:16 -07:00
parent 4bb350d61b
commit ed08958157
No known key found for this signature in database

View File

@ -312,16 +312,17 @@ func initModuleGroup(group *moduleGroup, dryRun bool) {
prefixParts := strings.Split(prefix, "/") prefixParts := strings.Split(prefix, "/")
projectName := prefixParts[len(prefixParts)-1] projectName := prefixParts[len(prefixParts)-1]
// 1. Write .goreleaser.yaml (always regenerate so it stays current). // 1. Write .goreleaser.yaml only when the content has changed.
yamlContent := goreleaserYAML(projectName, bins) yamlContent := goreleaserYAML(projectName, bins)
yamlPath := filepath.Join(modRoot, ".goreleaser.yaml") yamlPath := filepath.Join(modRoot, ".goreleaser.yaml")
isNewFile := true existing, readErr := os.ReadFile(yamlPath)
if _, err := os.ReadFile(yamlPath); err == nil { isNewFile := readErr != nil
isNewFile = false isChanged := isNewFile || string(existing) != yamlContent
}
if dryRun { if dryRun {
if isChanged {
fmt.Fprintf(os.Stderr, "[dry-run] would write %s\n", yamlPath) fmt.Fprintf(os.Stderr, "[dry-run] would write %s\n", yamlPath)
} else { }
} else if isChanged {
if err := os.WriteFile(yamlPath, []byte(yamlContent), 0o644); err != nil { if err := os.WriteFile(yamlPath, []byte(yamlContent), 0o644); err != nil {
fatalf("writing %s: %v", yamlPath, err) fatalf("writing %s: %v", yamlPath, err)
} }