mirror of
https://github.com/therootcompany/golib.git
synced 2026-03-02 23:57:59 +00:00
fix(monorel/release): auto-commit+tag only when .goreleaser.yaml is new
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
This commit is contained in:
parent
c4a31cbee8
commit
25781032f9
@ -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,15 +979,17 @@ func processModule(group *moduleGroup, relPath string) {
|
||||
fatalf("writing %s: %v", yamlPath, err)
|
||||
}
|
||||
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
|
||||
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'.
|
||||
// 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 != "" {
|
||||
@ -1004,6 +1010,7 @@ func processModule(group *moduleGroup, relPath string) {
|
||||
fmt.Fprintf(os.Stderr, "created tag: %s\n", newTag)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Collect and semver-sort tags — done after yaml commit + auto-tag so
|
||||
// the version computation reflects any tag just created above.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user