From 21492ffeb959cea926a0f6b2738a283541b7a9c8 Mon Sep 17 00:00:00 2001 From: codex-bot-andresmgsl <304681515+codex-bot-andresmgsl@users.noreply.github.com> Date: Fri, 24 Jul 2026 09:20:27 +0000 Subject: [PATCH] feat: arm changelogs in fragment mode --- actions/changelog-armed/action.yml | 5 ++ actions/changelog-armed/changelog-armed.sh | 74 +++++++++++++++++++++- test/changelog-armed.test.sh | 6 +- 3 files changed, 81 insertions(+), 4 deletions(-) diff --git a/actions/changelog-armed/action.yml b/actions/changelog-armed/action.yml index 6a63684..9ebff84 100644 --- a/actions/changelog-armed/action.yml +++ b/actions/changelog-armed/action.yml @@ -13,6 +13,10 @@ inputs: description: Path to the changelog, relative to the workspace required: false default: CHANGELOG.md + fragments-dir: + description: Fragment directory whose presence selects fragment mode + required: false + default: changelog.d runs: using: composite steps: @@ -21,4 +25,5 @@ runs: env: CHANGELOG: ${{ inputs.changelog }} VERSION_SOURCE: ${{ inputs.version-source }} + FRAGMENTS_DIR: ${{ inputs.fragments-dir }} run: bash "$GITHUB_ACTION_PATH/changelog-armed.sh" diff --git a/actions/changelog-armed/changelog-armed.sh b/actions/changelog-armed/changelog-armed.sh index 4e6130b..feaa427 100644 --- a/actions/changelog-armed/changelog-armed.sh +++ b/actions/changelog-armed/changelog-armed.sh @@ -1,9 +1,9 @@ #!/usr/bin/env bash set -euo pipefail -# changelog-armed.sh [] [] — assert that the -# changelog is ARMED: that there is a heading for the next PR's entry to -# land under, and that it is the right one for the state this tree is in. +# changelog-armed.sh [] [] [] — +# assert that the changelog is ARMED: that there is a place for the next PR's +# entry to land, and that it is the right one for the state this tree is in. # # Ported from box .github/scripts/changelog-armed.sh (box#108, confirmed # cross-repo as rig#66) — box is the only repo that carries this guard @@ -15,6 +15,14 @@ set -euo pipefail # tempted to simplify this back to the unconditional form should read # those two reverts first. # +# Fragment mode makes the directory itself the arming (#115): every PR gets +# its own issue-named file, so the box#108 clean-mismerge cannot happen because +# there is no shared heading to disappear under an open PR. The guard instead +# proves that the marker exists, Unreleased is gone, and every fragment is +# publishable before its author lets go of the PR. A bare release has no +# re-armed shape in this mode — there is nothing to re-arm — so it must have +# consumed every fragment and stamped its exact publishable section. +# # The failure it exists to catch (box#108, rig#66) leaves no trace: the # ceremony PR stamps '## Unreleased' into '## X.Y.Z — DATE' by hand, and # nothing puts the heading back. A PR authored BEFORE the release wrote its @@ -47,6 +55,7 @@ set -euo pipefail changelog="${1:-${CHANGELOG:-CHANGELOG.md}}" version_source="${2:-${VERSION_SOURCE:-file}}" +fragments_dir="${3:-${FRAGMENTS_DIR:-changelog.d}}" # The shared libs travel with this action: a consumer's # `uses: heavy-duty/ceremony/actions/changelog-armed@` downloads this @@ -67,6 +76,65 @@ ver="$(version_read "$version_source")" || { exit 1 } +if [ -d "$fragments_dir" ]; then + [ -f "$fragments_dir/README.md" ] || { + echo "changelog-armed: fragment mode requires the generated marker '$fragments_dir/README.md' — restore it so the empty directory remains tracked" >&2 + exit 1 + } + + if awk '$1 == "##" && $2 == "Unreleased" { found = 1 } END { exit !found }' "$changelog"; then + echo "changelog-armed: a '## Unreleased' section survived the adoption — move its entries into '$fragments_dir/.md' and delete the heading" >&2 + exit 1 + fi + + fragments="$(changelog_fragments "$fragments_dir")" + while IFS= read -r fragment; do + [ -n "$fragment" ] || continue + if ! diagnosis="$(changelog_fragment_problem "$fragment")"; then + printf 'changelog-armed: %s\n' "$diagnosis" >&2 + exit 1 + fi + done <<<"$fragments" + + if version_is_dev "$ver"; then + echo "changelog-armed: version '$ver' agrees with fragment mode ($fragments_dir)" + exit 0 + fi + + if [ -n "$fragments" ]; then + surviving="$(printf '%s' "$fragments" | paste -sd ', ' -)" + echo "changelog-armed: these fragments were not consumed: $surviving — re-run 'changelog-assemble $ver'" >&2 + exit 1 + fi + + top="$(grep -m1 '^## ' "$changelog" || true)" + [ -n "$top" ] || { + echo "changelog-armed: $changelog has no '## ' section at all — the release stamp for '$ver' is missing" >&2 + exit 1 + } + if ! diagnosis="$(changelog_section_problem "$changelog" "$ver")"; then + printf "changelog-armed: the stamped section for '%s' is not publishable: %s\n" \ + "$ver" "$diagnosis" >&2 + exit 1 + fi + top_ver="$(printf '%s\n' "$top" | awk '{ print $2 }')" + if [ "$top_ver" != "$ver" ]; then + cat >&2 <