rlls 0.0.36

Cut a version, tag it, and publish a GitHub Release with raw git notes
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
#![allow(dead_code, clippy::empty_line_after_outer_attr)]
use anyhow::anyhow;
use clap::{Parser, Subcommand};
use indicatif::MultiProgress;
use std::collections::BTreeMap;
use std::collections::HashSet;
use std::path::{Path, PathBuf};
use std::process;
use std::time::Instant;

mod changelog;
mod config;
mod git;
mod lock;
mod notes;
mod project;
mod release_kind;
mod rollback;
mod selfupdate;
mod semver;
mod shell;
mod ui;
mod util;
mod version;

use crate::release_kind::ReleaseKind;

#[derive(Parser)]
#[command(
    name = "rlls",
    about = "release utility for git + github",
    disable_help_subcommand = true,
    arg_required_else_help = true
)]
struct Cli {
    #[arg(value_enum)]
    kind: Option<ReleaseKind>,
    #[command(subcommand)]
    command: Option<Commands>,
    #[arg(long)]
    no_changelog: bool,
    #[arg(long)]
    repo: Option<String>,
    #[arg(long)]
    dry: bool,
    #[arg(long)]
    ignore_package: bool,
    #[arg(long, default_value = "rc")]
    id: String,
    #[arg(long)]
    bump: Option<ReleaseKind>,
    #[arg(long)]
    monorepo: bool,
    #[arg(long)]
    since: Option<String>,
}

#[derive(Subcommand)]
enum Commands {
    Prerelease,
    Finalize,
    Rollback {
        #[arg(long)]
        local: bool,
    },
    SelfUpdate,
    #[command(subcommand)]
    Lock(LockCommand),
    #[command(subcommand)]
    Tag(TagCommand),
    Monorepo {
        #[arg(value_enum)]
        kind: ReleaseKind,
        #[arg(long)]
        packages: Option<String>,
    },
}

#[derive(Subcommand)]
enum LockCommand {
    Rebuild {
        #[arg(long)]
        force: bool,
        #[arg(long, value_name = "PATH")]
        from_file: Option<PathBuf>,
        #[arg(long = "baseline", value_name = "NAME:REF")]
        baselines: Vec<String>,
    },
    Verify,
}

#[derive(Subcommand)]
enum TagCommand {
    Synthesize {
        #[arg(long = "baseline", value_name = "NAME:REF")]
        baselines: Vec<String>,
    },
}

enum Action<'a> {
    Release(ReleaseKind),
    Prerelease { id: &'a str, base: ReleaseKind },
    Finalize,
    Rollback { remote: bool },
}

#[tokio::main(flavor = "multi_thread")]
async fn main() -> anyhow::Result<()> {
    ui::clear_and_header();

    let cli = Cli::parse();
    let cfg = config::load(".rllsrc")?;

    if git::working_tree_dirty()
        && !matches!(cli.command, Some(Commands::Rollback { .. }))
        && !matches!(cli.command, Some(Commands::SelfUpdate))
    {
        if cfg.allow_dirty {
            ui::warn("working tree is dirty (allow_dirty=true)");
        } else {
            ui::err("working tree is not clean");
            process::exit(2);
        }
    }

    ui::section("rlls");
    let repo = cli.repo.clone().unwrap_or(git::current_repo_name()?);
    ui::info(&format!("loading config from {}", cfg.path.display()));
    ui::ok(&format!("detected repo: {}", repo));
    ui::divider();

    let root = std::env::current_dir()?;
    let auto_monorepo = project::looks_like_monorepo(&root)?;
    let monorepo_mode = cli.monorepo || auto_monorepo;

    if monorepo_mode && cli.kind.is_some() && cli.command.is_none() {
        ui::err("monorepo detected. do not use a global bump kind. run `rlls --monorepo` to use the interactive per-package flow");
        process::exit(2);
    }

    let action = match &cli.command {
        Some(Commands::Prerelease) => {
            let base = cli.bump.clone().unwrap_or_else(|| {
                cfg.default_bump.parse().unwrap_or(ReleaseKind::Patch)
            });
            Action::Prerelease { id: &cli.id, base }
        }
        Some(Commands::Finalize) => Action::Finalize,
        Some(Commands::Rollback { local }) => {
            Action::Rollback { remote: !*local }
        }
        Some(Commands::SelfUpdate) => {
            selfupdate::run(&repo).await?;
            return Ok(());
        }
        Some(Commands::Lock(cmd)) => match cmd {
            LockCommand::Verify => {
                lock::verify(&root)?;
                ui::ok("rlls.lock verified");
                return Ok(());
            }
            LockCommand::Rebuild {
                force,
                from_file,
                baselines,
            } => {
                lock::rebuild_with(
                    &root,
                    *force,
                    from_file.as_deref(),
                    baselines,
                )?;
                ui::ok("rlls.lock rebuilt");
                return Ok(());
            }
        },
        Some(Commands::Tag(TagCommand::Synthesize { baselines })) => {
            lock::synthesize_tags(&root, baselines)?;
            return Ok(());
        }
        Some(Commands::Monorepo {
            kind: _,
            packages: _,
        }) => Action::Release(
            cfg.default_bump.parse().unwrap_or(ReleaseKind::Patch),
        ),
        _ => {
            let k = cli.kind.clone().unwrap_or_else(|| {
                cfg.default_bump.parse().unwrap_or(ReleaseKind::Patch)
            });
            Action::Release(k)
        }
    };

    if let Action::Rollback { remote } = &action {
        rollback::run(&repo, *remote).await?;
        return Ok(());
    }

    let action_label = match action {
        Action::Release(_) => "release",
        Action::Prerelease { .. } => "prerelease",
        Action::Finalize => "finalize",
        Action::Rollback { .. } => unreachable!(),
    };

    ui::info(&format!("selected action: {}", action_label));
    if cli.no_changelog || !cfg.changelog_enabled {
        ui::warn("changelog disabled");
    }
    if cli.dry {
        ui::warn("dry run mode active");
    }
    ui::divider();

    if monorepo_mode {
        if !lock::exists(&root) {
            ui::err("monorepo detected but rlls.lock is missing. run `rlls lock rebuild` to create it");
            process::exit(2);
        }
        run_monorepo(&root, &repo, &cfg, &cli, action).await?;
        return Ok(());
    }

    run_single(&root, &repo, &cfg, &cli, action).await
}

async fn run_single(
    root: &Path,
    repo: &str,
    cfg: &config::Config,
    cli: &Cli,
    action: Action<'_>,
) -> anyhow::Result<()> {
    let current_ver = crate::project::read_current_version(root)?;
    let base_ver = crate::semver::base_of(&current_ver);

    let (next_version, next_tag) = match &action {
        Action::Release(kind) => {
            let bk: semver::BumpKind = kind.clone().into();
            let v = crate::semver::bump(&base_ver, bk)?;
            (v.clone(), format!("v{}", v))
        }
        Action::Prerelease { id, base } => {
            let bk: semver::BumpKind = base.clone().into();
            let bumped = crate::semver::bump(&base_ver, bk)?;
            let v = crate::semver::prerelease_new(&bumped, id)?;
            (v.clone(), format!("v{}", v))
        }
        Action::Finalize => {
            let latest = git::last_reachable_tag()
                .ok_or_else(|| anyhow!("no tags to finalize"))?;
            let core = latest.trim_start_matches('v');
            let core_only =
                core.split('-').next().unwrap_or(core).to_string();
            let stable_tag = format!("v{}", core_only);
            if git::tag_exists(&stable_tag)? {
                return Err(anyhow!(
                    "stable tag {} already exists",
                    stable_tag
                ));
            }
            (core_only.clone(), stable_tag)
        }
        _ => unreachable!(),
    };

    let changelog_path = cfg
        .changelog_path
        .clone()
        .unwrap_or_else(|| "CHANGELOG.md".into());

    ui::summary_block(&[
        ("Mode", "single"),
        (
            "Action",
            match action {
                Action::Release(_) => "release",
                Action::Prerelease { .. } => "prerelease",
                Action::Finalize => "finalize",
                _ => "",
            },
        ),
        ("Repo", repo),
        ("Next tag", &next_tag),
        (
            "Changelog",
            if cli.no_changelog || !cfg.changelog_enabled {
                "disabled"
            } else {
                &changelog_path
            },
        ),
        ("Dry run", if cli.dry { "yes" } else { "no" }),
    ]);

    if !ui::confirm("proceed with release?") {
        ui::err("aborted by user");
        process::exit(1);
    }

    let mp: MultiProgress = ui::mp();
    let pb_bump =
        ui::make_spinner(&mp, "[bump]", "updating project version");
    let start_bump = Instant::now();

    tokio::task::spawn_blocking({
        let next = next_version.clone();
        let ignore = cli.ignore_package;
        move || {
            if !ignore {
                crate::project::write_versions(
                    &std::env::current_dir()?,
                    &next,
                )?;
            }
            Ok::<(), anyhow::Error>(())
        }
    })
    .await??;

    pb_bump.finish_with_message(ui::done_style(&format!(
        "done in {:.2?}",
        start_bump.elapsed()
    )));

    let prev_tag = git::last_reachable_tag();
    let base_for_anchor = prev_tag.clone().or_else(git::first_commit);
    let notes_anchor = match &base_for_anchor {
        Some(b) => format!("{}..{}", b, next_tag),
        None => format!("{}^..{}", next_tag, next_tag),
    };

    if !cli.no_changelog && cfg.changelog_enabled {
        let pb =
            ui::make_spinner(&mp, "[changelog]", "writing changelog");
        let start = Instant::now();
        let notes = notes::build_release_notes(&notes_anchor, repo)
            .unwrap_or_else(|_| "(no changes)".to_string());
        tokio::task::spawn_blocking({
            let cfg = cfg.clone();
            let tag = next_tag.clone();
            move || changelog::maybe_update(&cfg, &tag, &notes, false)
        })
        .await??;
        pb.finish_with_message(ui::done_style(&format!(
            "done in {:.2?}",
            start.elapsed()
        )));
    }

    let pb_stage =
        ui::make_spinner(&mp, "[stage]", "staging changes");
    let start_stage = Instant::now();
    tokio::task::spawn_blocking(git::add_all).await??;
    pb_stage.finish_with_message(ui::done_style(&format!(
        "done in {:.2?}",
        start_stage.elapsed()
    )));

    let name_guess = project::read_current_name(root)
        .unwrap_or_else(|| "package".to_string());

    let pb_commit =
        ui::make_spinner(&mp, "[commit]", "creating commit");
    let start_commit = Instant::now();
    if tokio::task::spawn_blocking(git::has_staged_changes).await?? {
        let commit_msg = crate::util::render_template(
            &cfg.bump_commit_message,
            &[
                ("version", &next_version),
                ("name", &name_guess),
                ("count", "1"),
                ("list", ""),
            ],
        );
        let msg = commit_msg.clone();
        tokio::task::spawn_blocking(move || {
            git::commit_with_message(&msg)
        })
        .await??;
        pb_commit.finish_with_message(ui::done_style(&format!(
            "done in {:.2?}",
            start_commit.elapsed()
        )));
    } else {
        pb_commit.finish_with_message(ui::done_style("no changes"));
    }

    let pb_tag = ui::make_spinner(
        &mp,
        "[tag]",
        &format!("creating tag {}", next_tag),
    );
    let start_tag = Instant::now();
    let tag_msg_opt = cfg.bump_tag_message.as_deref().map(|t| {
        crate::util::render_template(
            t,
            &[("version", &next_version), ("name", &name_guess)],
        )
    });
    let tag_clone = next_tag.clone();
    tokio::task::spawn_blocking(move || {
        git::create_annotated_tag(&tag_clone, tag_msg_opt.as_deref())
    })
    .await??;
    pb_tag.finish_with_message(ui::done_style(&format!(
        "done in {:.2?}",
        start_tag.elapsed()
    )));

    let range = match prev_tag {
        Some(prev) => format!("{}..{}", prev, next_tag),
        None => {
            if let Some(root) = git::first_commit() {
                format!("{}..{}", root, next_tag)
            } else {
                format!("{}^..{}", next_tag, next_tag)
            }
        }
    };
    let notes_text = notes::build_release_notes(&range, repo)
        .unwrap_or_else(|_| "(no changes)".to_string());

    let pb_push_c =
        ui::make_spinner(&mp, "[push:commits]", "pushing commits");
    let dry = cli.dry;
    tokio::task::spawn_blocking(move || git::push_commits(dry))
        .await??;
    pb_push_c.finish_with_message(ui::done_style("done"));

    let pb_push_t =
        ui::make_spinner(&mp, "[push:tag]", "pushing tag");
    let dry2 = cli.dry;
    let tag2 = next_tag.clone();
    tokio::task::spawn_blocking(move || git::push_tag(&tag2, dry2))
        .await??;
    pb_push_t.finish_with_message(ui::done_style("done"));

    let pb_rel = ui::make_spinner(
        &mp,
        "[release]",
        &format!("creating GitHub release for {}", next_tag),
    );
    if !cli.dry {
        match crate::git::publish_github_release(
            &next_tag,
            repo,
            &notes_text,
        ) {
            Ok(_) => ui::ok(&format!(
                "GitHub release created for {}",
                next_tag
            )),
            Err(e) => ui::warn(&format!(
                "Failed to create GitHub release '{}': {}",
                next_tag, e
            )),
        }
    }
    pb_rel.finish_with_message(ui::done_style("done"));

    ui::ok("release completed successfully");
    Ok(())
}

async fn run_monorepo(
    root: &Path,
    owner_repo: &str,
    cfg: &config::Config,
    cli: &Cli,
    _action: Action<'_>,
) -> anyhow::Result<()> {
    let mut packages = project::discover_packages(root)?;
    let allow: HashSet<String> =
        cfg.packages.iter().cloned().collect();
    packages.retain(|p| allow.contains(&p.name));
    if packages.is_empty() {
        return Err(anyhow!(
            "no configured packages found (rlls.toml packages=[])"
        ));
    }
    if let Some(Commands::Monorepo {
        packages: Some(csv),
        ..
    }) = &cli.command
    {
        let subset: HashSet<String> =
            csv.split(',').map(|s| s.trim().to_string()).collect();
        packages.retain(|p| subset.contains(&p.name));
        if packages.is_empty() {
            return Err(anyhow!(
                "--packages filtered out all configured packages"
            ));
        }
    }

    if packages.is_empty() {
        return Err(anyhow!("no packages detected"));
    }

    let mut prev_by_pkg: BTreeMap<PathBuf, Option<String>> =
        BTreeMap::new();
    let mut changed_by_pkg: BTreeMap<PathBuf, usize> =
        BTreeMap::new();

    let lk = crate::lock::load(root)?;
    let baselines_by_name: BTreeMap<String, String> = lk
        .packages
        .iter()
        .filter_map(|p| {
            p.last_release
                .as_ref()
                .map(|r| (p.name.clone(), r.tag.clone()))
        })
        .collect();

    for p in &packages {
        let prev =
            baselines_by_name.get(&p.name).cloned().or_else(|| {
                project::last_tag_for_package(p, cfg).ok().flatten()
            });
        let commits =
            git::scoped_commits_since(prev.as_deref(), &p.path)?;
        prev_by_pkg.insert(p.path.clone(), prev);
        changed_by_pkg.insert(p.path.clone(), commits.len());
    }

    ui::summary_block(&[
        ("Mode", "monorepo"),
        ("Packages detected", &packages.len().to_string()),
        ("Note", "interactive per-package selection"),
    ]);
    ui::info(
        "commit counts since last package tag (or first commit):",
    );
    for p in &packages {
        let cnt = changed_by_pkg.get(&p.path).copied().unwrap_or(0);
        let prev = prev_by_pkg
            .get(&p.path)
            .and_then(|o| o.clone())
            .unwrap_or_else(|| "<none>".into());
        ui::info(&format!(
            "  - {:<18} {:>4} [{}] prev_tag={}",
            p.name,
            cnt,
            p.lang.as_str(),
            prev
        ));
    }
    ui::divider();

    let mut decisions: Vec<(
        project::Package,
        Option<semver::BumpKind>,
    )> = vec![];
    for p in &packages {
        let cnt = *changed_by_pkg.get(&p.path).unwrap_or(&0);
        let label = format!(
            "{} [{}] ({} commits since tag)",
            p.name,
            p.lang.as_str(),
            cnt
        );
        let choice = ui::prompt_bump(&label);
        decisions.push((p.clone(), choice));
    }

    decisions.retain(|(_, d)| d.is_some());
    if decisions.is_empty() {
        ui::warn("no packages selected for bump");
        return Ok(());
    }

    ui::info("selected package bumps:");
    for (pkg, kind) in &decisions {
        ui::info(&format!("  - {} -> {:?}", pkg.name, kind.unwrap()));
    }
    ui::divider();

    let mp: MultiProgress = ui::mp();
    let pb_bump =
        ui::make_spinner(&mp, "[bump]", "updating versions");
    let start_bump = Instant::now();

    let mut new_versions: Vec<(project::Package, String, usize)> =
        vec![];

    for (pkg, kind_opt) in &decisions {
        let kind = kind_opt.unwrap();
        let cur = project::read_current_version(&pkg.path)?;
        let base = semver::base_of(&cur);
        let next = semver::bump(&base, kind)?;
        project::write_one_package_version(pkg, &next)?;
        let cnt = changed_by_pkg.get(&pkg.path).copied().unwrap_or(0);
        ui::info(&format!("bumped {} -> {}", pkg.name, next));
        new_versions.push((pkg.clone(), next, cnt));
    }

    pb_bump.finish_with_message(ui::done_style(&format!(
        "done in {:.2?}",
        start_bump.elapsed()
    )));
    tokio::task::spawn_blocking(git::add_all).await??;

    let pb_commit =
        ui::make_spinner(&mp, "[commit]", "creating commit");
    let start_commit = Instant::now();

    let list_lines: Vec<String> = new_versions
        .iter()
        .map(|(pkg, v, cnt)| {
            format!(
                "- {}@{} ({} commits since tag)",
                pkg.name, v, cnt
            )
        })
        .collect();
    let count = new_versions.len();
    let tpl = cfg
        .monorepo_bump_commit_message
        .as_deref()
        .unwrap_or(&cfg.bump_commit_message);

    let commit_msg = crate::util::render_template(
        tpl,
        &[
            ("count", &count.to_string()),
            ("list", &list_lines.join("\n")),
            (
                "name",
                if count == 1 {
                    &new_versions[0].0.name
                } else {
                    "monorepo"
                },
            ),
            (
                "version",
                if count == 1 {
                    &new_versions[0].1
                } else {
                    "multi"
                },
            ),
        ],
    );

    if tokio::task::spawn_blocking(git::has_staged_changes).await?? {
        let s = if commit_msg.trim().is_empty() {
            format!(
                "bump {} packages\n\n{}",
                count,
                list_lines.join("\n")
            )
        } else {
            commit_msg
        };
        let msg = s.clone();
        tokio::task::spawn_blocking(move || {
            git::commit_with_message(&msg)
        })
        .await??;
        pb_commit.finish_with_message(ui::done_style(&format!(
            "done in {:.2?}",
            start_commit.elapsed()
        )));
    } else {
        pb_commit.finish_with_message(ui::done_style("no changes"));
    }

    let pb_tags = ui::make_spinner(&mp, "[tag]", "creating tags");
    let start_tags = Instant::now();

    let mut created_tags: Vec<(project::Package, String, String)> =
        vec![];
    for (pkg, v, _) in &new_versions {
        let tag = project::make_pkg_tag(pkg, v, cfg);
        let tag_tpl = cfg
            .bump_tag_message
            .as_deref()
            .unwrap_or("{{name}}@{{version}}");
        let msg = crate::util::render_template(
            tag_tpl,
            &[("name", &pkg.name), ("version", v)],
        );
        git::create_annotated_tag(&tag, Some(&msg))?;
        ui::info(&format!("created tag {}", tag));
        created_tags.push((pkg.clone(), v.clone(), tag));
    }
    pb_tags.finish_with_message(ui::done_style(&format!(
        "done in {:.2?}",
        start_tags.elapsed()
    )));

    let pb_push_c =
        ui::make_spinner(&mp, "[push:commits]", "pushing commits");
    let dry = cli.dry;
    tokio::task::spawn_blocking(move || git::push_commits(dry))
        .await??;
    pb_push_c.finish_with_message(ui::done_style("done"));

    let pb_push_t =
        ui::make_spinner(&mp, "[push:tags]", "pushing tags");
    for (_, _, t) in &created_tags {
        let dry = cli.dry;
        let tag = t.clone();
        let tag_for_thread = tag.clone();
        tokio::task::spawn_blocking(move || {
            git::push_tag(&tag_for_thread, dry)
        })
        .await??;
        ui::info(&format!("pushed tag {}", t));
    }
    pb_push_t.finish_with_message(ui::done_style("done"));

    if cfg.releases_per_package {
        let pb_rel = ui::make_spinner(
            &mp,
            "[release]",
            "creating GitHub releases",
        );
        let repo_root = crate::util::run_capture(
            "git",
            &["rev-parse", "--show-toplevel"],
        )
        .unwrap_or_else(|_| ".".to_string());
        let repo_root_pb = std::path::PathBuf::from(repo_root);

        for (pkg, _ver, tag) in &created_tags {
            let prev =
                prev_by_pkg.get(&pkg.path).and_then(|o| o.clone());
            let start = prev.unwrap_or_else(|| {
                crate::git::first_commit()
                    .unwrap_or_else(|| "HEAD".into())
            });
            let range = format!("{}..{}", start, tag);
            let rel = if pkg.path.is_absolute() {
                pkg.path
                    .strip_prefix(&repo_root_pb)
                    .unwrap_or(&pkg.path)
                    .to_path_buf()
            } else {
                pkg.path.clone()
            };
            let notes = crate::notes::build_release_notes_scoped(
                &range,
                owner_repo,
                &[rel],
            )
            .unwrap_or_else(|_| "(no changes)".to_string());
            crate::git::publish_github_release(
                tag, owner_repo, &notes,
            )?;
            ui::info(&format!("created GitHub release {}", tag));
        }
        pb_rel.finish_with_message(ui::done_style("done"));
    }

    if !cli.no_changelog && cfg.changelog_enabled {
        let pb = ui::make_spinner(
            &mp,
            "[changelog]",
            "writing monorepo changelog batch",
        );
        let mut doc = String::new();
        for (pkg, _ver, tag) in &created_tags {
            let prev =
                prev_by_pkg.get(&pkg.path).and_then(|o| o.clone());
            let start = prev.unwrap_or_else(|| {
                git::first_commit().unwrap_or_else(|| "HEAD".into())
            });
            let range = format!("{}..{}", start, tag);
            let scoped = notes::build_release_notes_scoped(
                &range,
                owner_repo,
                std::slice::from_ref(&pkg.path),
            )
            .unwrap_or_else(|_| "(no changes)".to_string());
            use std::fmt::Write;
            let _ =
                writeln!(&mut doc, "### {} ({})\n", pkg.name, tag);
            let _ = writeln!(&mut doc, "{}", scoped);
        }
        let batch_label = format!(
            "batch-{}",
            chrono::Utc::now().format("%Y%m%d%H%M%S")
        );
        changelog::maybe_update(cfg, &batch_label, &doc, false)?;
        pb.finish_with_message(ui::done_style("done"));
    }

    ui::ok("monorepo release completed successfully");
    Ok(())
}