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
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:
parent
4bb350d61b
commit
ed08958157
@ -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 {
|
||||||
fmt.Fprintf(os.Stderr, "[dry-run] would write %s\n", yamlPath)
|
if isChanged {
|
||||||
} else {
|
fmt.Fprintf(os.Stderr, "[dry-run] would write %s\n", yamlPath)
|
||||||
|
}
|
||||||
|
} 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)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user