Skip to content

fix(scripts): match both (#X) and [#X] PR-number forms in generate-changelog.sh#26

Merged
brettdavies merged 1 commit into
devfrom
fix/changelog-pr-number-regex
Jun 1, 2026
Merged

fix(scripts): match both (#X) and [#X] PR-number forms in generate-changelog.sh#26
brettdavies merged 1 commit into
devfrom
fix/changelog-pr-number-regex

Conversation

@brettdavies
Copy link
Copy Markdown
Owner

@brettdavies brettdavies commented Jun 1, 2026

Summary

The PR-number extraction regex in scripts/generate-changelog.sh was \(#\K\d+, which only matches the parenthesized form git-cliff emits on the initial prepend. The script's own Python step rewrites those into markdown-link form [#14](https://github.com/.../pull/14). A second run (e.g. --dry-run against an already-processed CHANGELOG.md, which is exactly the sync-dev-after-release.sh regen-idempotency check's mode of operation) extracts zero PR numbers.

Combined with set -euo pipefail, grep's exit-1-on-no-match aborts the whole script before summarize_and_exit can run, producing empty output and an opaque non-zero exit code.

Surfaced during the v0.5.0 release backport. The new regen-idempotency check warned "PR bodies have drifted" with no diff body. Root cause was the regex, not real drift.

Fix:

  • [\(\[]#\K\d+ accepts both (#14) from git-cliff and [#14] from the rewritten link.
  • || true lets the pipeline exit status survive the empty-match case so the downstream [[ -z "$PR_NUMBERS" ]]
    branch handles it cleanly via summarize_and_exit.

Known follow-up (not in this PR)

The dry-run comparison uses byte-exact cmp -s. The on-disk CHANGELOG.md is line-wrapped by the repo's
markdownlint / md-wrap hook; the script's direct writes are unwrapped. Even after this fix, the dry-run will
false-positive "drift" on every release until the comparison is made wrap-tolerant (paragraph-unwrap then diff). The
check is "warn, do not fail" so this does not block. Tracked in the sibling-repo plans and to be fixed alongside the
broader sync-script port.

Changelog

Fixed

  • scripts/generate-changelog.sh: PR-number extraction now matches both (#X) (git-cliff initial prepend) and [#X] (markdown-link form written by the Python expansion step). Re-runs and --dry-run no longer abort with empty output on an already-processed CHANGELOG.md.

Type of Change

  • fix: Bug fix (non-breaking change which fixes an issue)

Files Modified

Modified: scripts/generate-changelog.sh

Breaking Changes

  • No breaking changes

Deployment Notes

  • No special deployment steps required

Checklist

  • Code follows project conventions and style guidelines
  • Commit messages follow Conventional Commits
  • Self-review of code completed
  • No new warnings or errors introduced

…e-changelog.sh

The PR-number extraction regex `\(#\K\d+` only matches the parenthesized
form git-cliff emits on the initial prepend. The script's own Python
step rewrites those into markdown-link form `[#14](https://github.com/...)`,
so a second run (e.g. `--dry-run` against an already-processed
CHANGELOG.md, which is exactly the sync-dev-after-release.sh regen-
idempotency check's mode of operation) extracts zero PR numbers. With
`set -euo pipefail`, the grep's exit-1-on-no-match aborts the whole
script before reaching `summarize_and_exit`, producing empty output and
a misleading non-zero exit code.

Surfaced during the v0.5.0 release backport: the new regen-idempotency
check warned "PR bodies have drifted" with no diff body. Root cause was
the regex, not real drift.

Fix:

- Match both forms: `[\(\[]#\K\d+` accepts `(#14)` from git-cliff and
  `[#14]` from the rewritten link.
- Append `|| true` so the pipeline exit status survives the empty-match
  case and the downstream `[[ -z "$PR_NUMBERS" ]]` branch can handle it
  cleanly via `summarize_and_exit`.

Known follow-up (NOT in this PR): the dry-run comparison uses byte-exact
`cmp -s`. The on-disk CHANGELOG.md is line-wrapped by the repo's
markdownlint / md-wrap hook; the script's direct writes are unwrapped.
Even after this fix, the dry-run will report false-positive "drift" on
every release until the comparison is made wrap-tolerant (paragraph
unwrap then diff). The check is "warn, do not fail" so this does not
block; tracked in the sibling-repo plans and to be fixed alongside the
broader sync-script port.
@brettdavies brettdavies merged commit f24831c into dev Jun 1, 2026
4 checks passed
@brettdavies brettdavies deleted the fix/changelog-pr-number-regex branch June 1, 2026 18:33
brettdavies added a commit to brettdavies/agentnative that referenced this pull request Jun 1, 2026
Folds two new items into the existing P0 mirror plan: (A) the PR-number extraction regex fix shipped in brettdavies/agentnative-skill PR #26 — `\(#\K\d+` only matches git-cliff's `(#X)` form, not the markdown-link `[#X](…)` form the script's Python expansion rewrites those to, causing `set -euo pipefail` to abort a second run with empty output; and (B) the known follow-up the skill PR did not ship, where the dry-run's byte-exact `cmp -s` false-positives "drift" against a wrap-tolerant on-disk `CHANGELOG.md` until the comparison is paragraph-flattened.

Reference PR: brettdavies/agentnative-skill#26
brettdavies added a commit to brettdavies/agentnative-cli that referenced this pull request Jun 1, 2026
Expands the existing P0 mirror plan from three items to five by adding the two `generate-changelog.sh` fixes surfaced after the original PR #25 mirror was written: (A) the PR-number extraction regex fix shipped in brettdavies/agentnative-skill PR #26 — `\(#\K\d+` only matches git-cliff's `(#X)` form, not the markdown-link `[#X](…)` form the script's Python expansion rewrites those to, causing `set -euo pipefail` to abort a second run (i.e. the `sync-dev-after-release.sh` regen-idempotency check, item 2 in this plan) with empty output; and (B) the known follow-up the skill PR did not ship, where the dry-run's byte-exact `cmp -s` false-positives "drift" against a wrap-tolerant on-disk `CHANGELOG.md` until the comparison is paragraph-flattened. Without item B, the regen-idempotency warning fires on every release regardless of real drift.

Reference PR: brettdavies/agentnative-skill#26
brettdavies added a commit to brettdavies/agentnative-site that referenced this pull request Jun 1, 2026
Folds two additional items into the step-2 port list of the existing P0 applicability-evaluation plan, conditional on the same "if `generate-changelog.sh` lands here" gate as the rest of the step: (A) the PR-number extraction regex fix shipped in brettdavies/agentnative-skill PR #26 — `\(#\K\d+` only matches git-cliff's `(#X)` form, not the markdown-link `[#X](…)` form the script's Python expansion rewrites those to, causing `set -euo pipefail` to abort a second run with empty output; and (B) the known follow-up the skill PR did not ship, where the dry-run's byte-exact `cmp -s` false-positives "drift" against a wrap-tolerant on-disk `CHANGELOG.md` until the comparison is paragraph-flattened. Items 5 and 6 (the sync-script preconditions) are the consumers that make items 3 and 4 matter, so the dependencies between the four ported items are now spelled out in the plan.

Reference PR: brettdavies/agentnative-skill#26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant