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")
|
rawURL := mustRunIn(modRoot, "git", "remote", "get-url", "origin")
|
||||||
repoPath := normalizeGitURL(rawURL)
|
repoPath := normalizeGitURL(rawURL)
|
||||||
|
|
||||||
// 1. Write .goreleaser.yaml, commit if the file changed.
|
// 1. Write .goreleaser.yaml (always regenerate).
|
||||||
// Warn if an existing file uses {{ .ProjectName }} (stock goreleaser
|
// Track whether this is a first-time creation: auto-commit and auto-tag
|
||||||
// config) and the module is a monorepo subdirectory.
|
// 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)
|
yamlContent := goreleaserYAML(projectName, bins)
|
||||||
yamlPath := filepath.Join(modRoot, ".goreleaser.yaml")
|
yamlPath := filepath.Join(modRoot, ".goreleaser.yaml")
|
||||||
|
isNewFile := true
|
||||||
if existing, err := os.ReadFile(yamlPath); err == nil {
|
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 }}") ||
|
hasProjectName := strings.Contains(string(existing), "{{ .ProjectName }}") ||
|
||||||
strings.Contains(string(existing), "{{.ProjectName}}")
|
strings.Contains(string(existing), "{{.ProjectName}}")
|
||||||
gitInfo, gitErr := os.Stat(filepath.Join(modRoot, ".git"))
|
gitInfo, gitErr := os.Stat(filepath.Join(modRoot, ".git"))
|
||||||
@ -975,33 +979,36 @@ func processModule(group *moduleGroup, relPath string) {
|
|||||||
fatalf("writing %s: %v", yamlPath, err)
|
fatalf("writing %s: %v", yamlPath, err)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(os.Stderr, "wrote %s\n", yamlPath)
|
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
|
// 2. Auto-commit + auto-tag — only when the file was newly created.
|
||||||
// since the last stable tag — same heuristic as 'monorel init'.
|
if isNewFile {
|
||||||
latestStable := findLatestStableTag(modRoot, prefix)
|
mustRunIn(modRoot, "git", "add", ".goreleaser.yaml")
|
||||||
shouldBump := true
|
if status := runIn(modRoot, "git", "status", "--porcelain", "--", ".goreleaser.yaml"); status != "" {
|
||||||
if latestStable != "" {
|
commitMsg := "chore(release): add .goreleaser.yaml for " + projectName
|
||||||
logOut := strings.TrimSpace(runIn(modRoot, "git", "log", "--oneline", latestStable+"..HEAD", "--", "."))
|
mustRunIn(modRoot, "git", "commit", "-m", commitMsg)
|
||||||
count := 0
|
fmt.Fprintf(os.Stderr, "committed: %s\n", commitMsg)
|
||||||
if logOut != "" {
|
|
||||||
count = len(strings.Split(logOut, "\n"))
|
|
||||||
}
|
}
|
||||||
if count > 1 {
|
// Auto-tag patch if the yaml commit is the sole new commit since the
|
||||||
fmt.Fprintf(os.Stderr,
|
// last stable tag — same heuristic as 'monorel init'.
|
||||||
"note: %d commits since %s; skipping auto-bump — run 'monorel bump' when ready\n",
|
latestStable := findLatestStableTag(modRoot, prefix)
|
||||||
count, latestStable)
|
shouldBump := true
|
||||||
shouldBump = false
|
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 shouldBump {
|
if newTag := bumpModuleTag(group, "patch", false, false); newTag != "" {
|
||||||
if newTag := bumpModuleTag(group, "patch", false, false); newTag != "" {
|
fmt.Fprintf(os.Stderr, "created tag: %s\n", newTag)
|
||||||
fmt.Fprintf(os.Stderr, "created tag: %s\n", newTag)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user