mirror of
https://github.com/therootcompany/golib.git
synced 2026-03-02 23:57:59 +00:00
fix(monorel/release): always write .goreleaser.yaml, never auto-commit
The previous commit was too conservative — it prevented release from
updating an existing config. Restore the original write-always behaviour
but keep the {{ .ProjectName }} monorepo warning. The file is written
unconditionally; the user commits it manually when satisfied.
This commit is contained in:
parent
1e766daa14
commit
56cce946a8
@ -1008,35 +1008,26 @@ func processModule(group *moduleGroup, relPath string) {
|
||||
"--pretty=format:- %h %s", "--", ".")
|
||||
}
|
||||
|
||||
// Write .goreleaser.yaml if it does not yet exist, then commit it.
|
||||
// If it already exists, leave it unchanged — updates require manual review.
|
||||
// Write .goreleaser.yaml next to go.mod.
|
||||
// Warn if an existing file uses {{ .ProjectName }} (stock goreleaser config)
|
||||
// and the module is a monorepo subdirectory (go.mod not adjacent to .git/).
|
||||
// The file is written but not committed; commit it manually when satisfied.
|
||||
yamlContent := goreleaserYAML(projectName, bins)
|
||||
yamlPath := filepath.Join(modRoot, ".goreleaser.yaml")
|
||||
if existing, err := os.ReadFile(yamlPath); err == nil {
|
||||
// File exists — leave it for manual review.
|
||||
hasProjectName := strings.Contains(string(existing), "{{ .ProjectName }}") ||
|
||||
strings.Contains(string(existing), "{{.ProjectName}}")
|
||||
gitInfo, gitErr := os.Stat(filepath.Join(modRoot, ".git"))
|
||||
atGitRoot := gitErr == nil && gitInfo.IsDir()
|
||||
if hasProjectName && !atGitRoot {
|
||||
fmt.Fprintf(os.Stderr, "warning: %s uses {{ .ProjectName }} in a monorepo subdirectory;\n", yamlPath)
|
||||
fmt.Fprintf(os.Stderr, " update it manually and re-run 'monorel release'\n")
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "note: %s exists; leaving unchanged\n", yamlPath)
|
||||
}
|
||||
} else {
|
||||
// File is missing — write it and commit it so goreleaser has a config.
|
||||
if err := os.WriteFile(yamlPath, []byte(yamlContent), 0o644); err != nil {
|
||||
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)
|
||||
fmt.Fprintf(os.Stderr, "warning: %s: contains {{ .ProjectName }} but module is a monorepo subdirectory;\n", yamlPath)
|
||||
fmt.Fprintf(os.Stderr, " replacing stock goreleaser config with monorel-generated config.\n")
|
||||
}
|
||||
}
|
||||
if err := os.WriteFile(yamlPath, []byte(yamlContent), 0o644); err != nil {
|
||||
fatalf("writing %s: %v", yamlPath, err)
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "wrote %s\n", yamlPath)
|
||||
|
||||
headSHA := mustRunIn(modRoot, "git", "rev-parse", "HEAD")
|
||||
printModuleScript(relPath, projectName, bins,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user