| 1 | #!/usr/bin/env sh |
| 2 | # Regenerate crates/tui/CHANGELOG.md from the workspace root CHANGELOG.md. |
| 3 | # The /change command embeds this file into the binary via include_str!, so |
| 4 | # it deliberately keeps only the most recent release sections. |
| 5 | # |
| 6 | # The `## [Unreleased]` section is always kept but does NOT count toward the |
| 7 | # keep window: it is not a release, and counting it silently dropped the |
| 8 | # oldest retained release whenever Unreleased had content (#3768). The window |
| 9 | # therefore tracks a stable number of *released* versions regardless of |
| 10 | # in-progress notes. |
| 11 | # |
| 12 | # Usage: scripts/sync-changelog.sh [--check] [sections-to-keep] |
| 13 | # --check verify crates/tui/CHANGELOG.md is up to date without writing |
| 14 | # (exit 1 if regeneration would change it) |
| 15 | # sections-to-keep defaults to 15 (released versions, excluding Unreleased) |
| 16 | set -eu |
| 17 | CHECK=0 |
| 18 | if [ "${1:-}" = "--check" ]; then |
| 19 | CHECK=1 |
| 20 | shift |
| 21 | fi |
| 22 | KEEP="${1:-15}" |
| 23 | root="$(cd "$(dirname "$0")/.." && pwd)" |
| 24 | tmp="$(mktemp)" |
| 25 | trap 'rm -f "$tmp"' EXIT |
| 26 | awk -v keep="$KEEP" ' |
| 27 | /^\[/ && /\]: http/ { exit } |
| 28 | # Count only released versions toward the keep window; the Unreleased |
| 29 | # section is always printed but never consumes a slot (#3768). |
| 30 | /^## \[/ && $0 !~ /\[Unreleased\]/ { count++ } |
| 31 | count > keep { exit } |
| 32 | { print } |
| 33 | ' "$root/CHANGELOG.md" > "$tmp" |
| 34 | printf '%s\n' \ |
| 35 | '---' \ |
| 36 | '' \ |
| 37 | 'Older releases: [CHANGELOG.md](https://github.com/Hmbown/CodeWhale/blob/main/CHANGELOG.md) and [docs/CHANGELOG_ARCHIVE.md](https://github.com/Hmbown/CodeWhale/blob/main/docs/CHANGELOG_ARCHIVE.md).' \ |
| 38 | >> "$tmp" |
| 39 | if [ "$CHECK" = 1 ]; then |
| 40 | if cmp -s "$tmp" "$root/crates/tui/CHANGELOG.md"; then |
| 41 | echo "crates/tui/CHANGELOG.md is up to date" |
| 42 | else |
| 43 | echo "crates/tui/CHANGELOG.md is out of date; run scripts/sync-changelog.sh" >&2 |
| 44 | exit 1 |
| 45 | fi |
| 46 | else |
| 47 | cp "$tmp" "$root/crates/tui/CHANGELOG.md" |
| 48 | echo "wrote crates/tui/CHANGELOG.md ($(wc -l < "$root/crates/tui/CHANGELOG.md") lines, $KEEP sections kept)" |
| 49 | fi |
| 50 |