fix(monorel): init only auto-commits new .goreleaser.yaml, not updates

- Track isNewFile before writing so updates to existing files are never
  auto-committed (mirrors the same rule already in processModule/release)
- Gate auto-bump on isNewFile as well — no tag when just refreshing yaml
- Fix commit message scope: chore(<prefix>): add .goreleaser.yaml
  (was chore(release): add .goreleaser.yaml for <name>)
This commit is contained in:
AJ ONeal 2026-02-28 23:59:59 -07:00
parent 455ceb7d69
commit 4bb350d61b
No known key found for this signature in database

View File

@ -312,9 +312,13 @@ 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. // 1. Write .goreleaser.yaml (always regenerate so it stays current).
yamlContent := goreleaserYAML(projectName, bins) yamlContent := goreleaserYAML(projectName, bins)
yamlPath := filepath.Join(modRoot, ".goreleaser.yaml") yamlPath := filepath.Join(modRoot, ".goreleaser.yaml")
isNewFile := true
if _, err := os.ReadFile(yamlPath); err == nil {
isNewFile = false
}
if dryRun { if dryRun {
fmt.Fprintf(os.Stderr, "[dry-run] would write %s\n", yamlPath) fmt.Fprintf(os.Stderr, "[dry-run] would write %s\n", yamlPath)
} else { } else {
@ -323,14 +327,15 @@ func initModuleGroup(group *moduleGroup, dryRun bool) {
} }
fmt.Fprintf(os.Stderr, "wrote %s\n", yamlPath) fmt.Fprintf(os.Stderr, "wrote %s\n", yamlPath)
// 2. Stage and commit if the file changed. // 2. Auto-commit — only when the file was newly created.
mustRunIn(modRoot, "git", "add", ".goreleaser.yaml") // Updates to an existing file require manual review and commit.
if status := runIn(modRoot, "git", "status", "--porcelain", "--", ".goreleaser.yaml"); status != "" { if isNewFile {
commitMsg := "chore(release): add .goreleaser.yaml for " + projectName mustRunIn(modRoot, "git", "add", ".goreleaser.yaml")
mustRunIn(modRoot, "git", "commit", "-m", commitMsg) if status := runIn(modRoot, "git", "status", "--porcelain", "--", ".goreleaser.yaml"); status != "" {
fmt.Fprintf(os.Stderr, "committed: %s\n", commitMsg) commitMsg := "chore(" + prefix + "): add .goreleaser.yaml"
} else { mustRunIn(modRoot, "git", "commit", "-m", commitMsg)
fmt.Fprintf(os.Stderr, "note: .goreleaser.yaml unchanged, skipping commit\n") fmt.Fprintf(os.Stderr, "committed: %s\n", commitMsg)
}
} }
} }
@ -338,8 +343,9 @@ func initModuleGroup(group *moduleGroup, dryRun bool) {
// commit since the last stable tag (the common "first setup" scenario). // commit since the last stable tag (the common "first setup" scenario).
// If other commits are already waiting to be tagged the user should choose // If other commits are already waiting to be tagged the user should choose
// the right semver component with an explicit 'monorel bump'. // the right semver component with an explicit 'monorel bump'.
shouldBump := true // Auto-bump only applies when the yaml was newly created.
if !dryRun { shouldBump := isNewFile
if !dryRun && isNewFile {
latestStable := findLatestStableTag(modRoot, prefix) latestStable := findLatestStableTag(modRoot, prefix)
if latestStable != "" { if latestStable != "" {
logOut := strings.TrimSpace(runIn(modRoot, "git", "log", "--oneline", latestStable+"..HEAD", "--", ".")) logOut := strings.TrimSpace(runIn(modRoot, "git", "log", "--oneline", latestStable+"..HEAD", "--", "."))