From 25781032f91b4667318899170dc1098d5dc716c6 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sat, 28 Feb 2026 23:37:02 -0700 Subject: [PATCH] fix(monorel/release): auto-commit+tag only when .goreleaser.yaml is new MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If .goreleaser.yaml did not exist: → write it, commit it, auto-tag patch (if sole new commit since last tag) If .goreleaser.yaml already existed: → write the updated file, stop — no auto-commit, no auto-tag --- tools/monorel/main.go | 61 ++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/tools/monorel/main.go b/tools/monorel/main.go index 057a441..b5d1447 100644 --- a/tools/monorel/main.go +++ b/tools/monorel/main.go @@ -956,12 +956,16 @@ func processModule(group *moduleGroup, relPath string) { rawURL := mustRunIn(modRoot, "git", "remote", "get-url", "origin") repoPath := normalizeGitURL(rawURL) - // 1. Write .goreleaser.yaml, commit if the file changed. - // Warn if an existing file uses {{ .ProjectName }} (stock goreleaser - // config) and the module is a monorepo subdirectory. + // 1. Write .goreleaser.yaml (always regenerate). + // Track whether this is a first-time creation: auto-commit and auto-tag + // only apply when the file is new. If it already exists, just update it + // 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 + // Warn if a stock {{ .ProjectName }} template is in use. hasProjectName := strings.Contains(string(existing), "{{ .ProjectName }}") || strings.Contains(string(existing), "{{.ProjectName}}") gitInfo, gitErr := os.Stat(filepath.Join(modRoot, ".git")) @@ -975,33 +979,36 @@ func processModule(group *moduleGroup, relPath string) { fatalf("writing %s: %v", yamlPath, err) } fmt.Fprintf(os.Stderr, "wrote %s\n", yamlPath) - mustRunIn(modRoot, "git", "add", ".goreleaser.yaml") - if status := runIn(modRoot, "git", "status", "--porcelain", "--", ".goreleaser.yaml"); status != "" { - commitMsg := "chore(release): add .goreleaser.yaml for " + projectName - mustRunIn(modRoot, "git", "commit", "-m", commitMsg) - fmt.Fprintf(os.Stderr, "committed: %s\n", commitMsg) - } - // 2. Auto-tag patch if the goreleaser.yaml commit is the sole new commit - // since the last stable tag — same heuristic as 'monorel init'. - latestStable := findLatestStableTag(modRoot, prefix) - shouldBump := true - if latestStable != "" { - logOut := strings.TrimSpace(runIn(modRoot, "git", "log", "--oneline", latestStable+"..HEAD", "--", ".")) - count := 0 - if logOut != "" { - count = len(strings.Split(logOut, "\n")) + // 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 + mustRunIn(modRoot, "git", "commit", "-m", commitMsg) + fmt.Fprintf(os.Stderr, "committed: %s\n", commitMsg) } - if count > 1 { - fmt.Fprintf(os.Stderr, - "note: %d commits since %s; skipping auto-bump — run 'monorel bump' when ready\n", - count, latestStable) - shouldBump = false + // Auto-tag patch if the yaml commit is the sole new commit since the + // last stable tag — same heuristic as 'monorel init'. + latestStable := findLatestStableTag(modRoot, prefix) + shouldBump := true + if latestStable != "" { + logOut := strings.TrimSpace(runIn(modRoot, "git", "log", "--oneline", latestStable+"..HEAD", "--", ".")) + count := 0 + if logOut != "" { + count = len(strings.Split(logOut, "\n")) + } + if count > 1 { + fmt.Fprintf(os.Stderr, + "note: %d commits since %s; skipping auto-bump — run 'monorel bump' when ready\n", + count, latestStable) + shouldBump = false + } } - } - if shouldBump { - if newTag := bumpModuleTag(group, "patch", false, false); newTag != "" { - fmt.Fprintf(os.Stderr, "created tag: %s\n", newTag) + if shouldBump { + if newTag := bumpModuleTag(group, "patch", false, false); newTag != "" { + fmt.Fprintf(os.Stderr, "created tag: %s\n", newTag) + } } }