fix(monorel): skip repo-root modules; add found binary/module headers

- All three subcommands now print "found binary …" and "found module …"
  before processing each module group, with a blank line between groups
- initModuleGroup, bumpModuleTag, processModule: downgrade the prefix==""
  (repository root) case from fatal error to a skip warning so that
  -recursive runs continue past root-level go.mod packages instead of
  aborting
This commit is contained in:
AJ ONeal 2026-02-28 16:13:47 -07:00
parent e3ada72168
commit a28fe8ed55
No known key found for this signature in database

View File

@ -145,7 +145,11 @@ func runRelease(args []string) {
fmt.Println("# Generated by monorel — review carefully before running!") fmt.Println("# Generated by monorel — review carefully before running!")
fmt.Println("set -euo pipefail") fmt.Println("set -euo pipefail")
for _, group := range groups { for i, group := range groups {
if i > 0 {
fmt.Fprintln(os.Stderr)
}
printGroupHeader(cwd, group)
relPath, _ := filepath.Rel(cwd, group.root) relPath, _ := filepath.Rel(cwd, group.root)
relPath = filepath.ToSlash(relPath) relPath = filepath.ToSlash(relPath)
processModule(group, relPath) processModule(group, relPath)
@ -206,7 +210,12 @@ func runBump(args []string) {
if err != nil { if err != nil {
fatalf("%v", err) fatalf("%v", err)
} }
for _, group := range groups { cwd, _ := os.Getwd()
for i, group := range groups {
if i > 0 {
fmt.Fprintln(os.Stderr)
}
printGroupHeader(cwd, group)
newTag := bumpModuleTag(group, component, force, dryRun) newTag := bumpModuleTag(group, component, force, dryRun)
switch { switch {
case newTag == "": case newTag == "":
@ -259,7 +268,12 @@ func runInit(args []string) {
if err != nil { if err != nil {
fatalf("%v", err) fatalf("%v", err)
} }
for _, group := range groups { cwd, _ := os.Getwd()
for i, group := range groups {
if i > 0 {
fmt.Fprintln(os.Stderr)
}
printGroupHeader(cwd, group)
initModuleGroup(group, dryRun) initModuleGroup(group, dryRun)
} }
} }
@ -274,7 +288,8 @@ func initModuleGroup(group *moduleGroup, dryRun bool) {
prefix := mustRunIn(modRoot, "git", "rev-parse", "--show-prefix") prefix := mustRunIn(modRoot, "git", "rev-parse", "--show-prefix")
prefix = strings.TrimSuffix(prefix, "/") prefix = strings.TrimSuffix(prefix, "/")
if prefix == "" { if prefix == "" {
fatalf("%s appears to be the repo root; the module must be in a subdirectory", modRoot) fmt.Fprintf(os.Stderr, "monorel: skip: %s is at the repository root; binaries at the repo root cannot have prefixed tags\n", modRoot)
return
} }
prefixParts := strings.Split(prefix, "/") prefixParts := strings.Split(prefix, "/")
projectName := prefixParts[len(prefixParts)-1] projectName := prefixParts[len(prefixParts)-1]
@ -379,7 +394,8 @@ func bumpModuleTag(group *moduleGroup, component string, force, dryRun bool) str
prefix := mustRunIn(modRoot, "git", "rev-parse", "--show-prefix") prefix := mustRunIn(modRoot, "git", "rev-parse", "--show-prefix")
prefix = strings.TrimSuffix(prefix, "/") prefix = strings.TrimSuffix(prefix, "/")
if prefix == "" { if prefix == "" {
fatalf("%s appears to be the repo root; the module must be in a subdirectory", modRoot) fmt.Fprintf(os.Stderr, "monorel: skip: %s is at the repository root; binaries at the repo root cannot have prefixed tags\n", modRoot)
return ""
} }
latestStable := findLatestStableTag(modRoot, prefix) latestStable := findLatestStableTag(modRoot, prefix)
@ -653,6 +669,29 @@ func groupByModule(args []string) ([]*moduleGroup, error) {
// ── Per-module processing ────────────────────────────────────────────────── // ── Per-module processing ──────────────────────────────────────────────────
// printGroupHeader writes "found binary …" and "found module …" lines to
// stderr before each module is processed, providing progress feedback during
// recursive operations.
func printGroupHeader(cwd string, group *moduleGroup) {
modRel, _ := filepath.Rel(cwd, group.root)
modRel = filepath.ToSlash(modRel)
for _, bin := range group.bins {
suffix := strings.TrimPrefix(bin.mainPath, "./")
var binPath string
if suffix == "." || suffix == "" {
binPath = "./" + modRel
} else {
binPath = "./" + filepath.ToSlash(filepath.Join(modRel, suffix))
}
fmt.Fprintf(os.Stderr, "found binary %s\n", binPath)
}
modLabel := "./" + modRel
if !strings.HasSuffix(modLabel, "/") {
modLabel += "/"
}
fmt.Fprintf(os.Stderr, "found module %s\n", modLabel)
}
// processModule writes .goreleaser.yaml and emits the release-script section // processModule writes .goreleaser.yaml and emits the release-script section
// for one module group. relPath is the path from the caller's CWD to the // for one module group. relPath is the path from the caller's CWD to the
// module root; it is used in the script for all paths so that the script can // module root; it is used in the script for all paths so that the script can
@ -666,7 +705,8 @@ func processModule(group *moduleGroup, relPath string) {
prefix := mustRunIn(modRoot, "git", "rev-parse", "--show-prefix") prefix := mustRunIn(modRoot, "git", "rev-parse", "--show-prefix")
prefix = strings.TrimSuffix(prefix, "/") prefix = strings.TrimSuffix(prefix, "/")
if prefix == "" { if prefix == "" {
fatalf("%s appears to be the repo root; the module must be in a subdirectory", modRoot) fmt.Fprintf(os.Stderr, "monorel: skip: %s is at the repository root; binaries at the repo root cannot have prefixed tags\n", modRoot)
return
} }
prefixParts := strings.Split(prefix, "/") prefixParts := strings.Split(prefix, "/")