From 6c5a99883fa66be2be6a6271b562158eb6ccbf24 Mon Sep 17 00:00:00 2001 From: Erich Blume Date: Tue, 3 Mar 2026 10:49:01 -0800 Subject: [PATCH] Add pre-commit check for changelog fragment placement Misfiled fragment from feature/ branch created a subdirectory under changelog.d/ which towncrier doesn't support. Move the fragment to the correct flat location and add a changelog-check mise task + prek hook to prevent this from happening again. Co-Authored-By: Claude Opus 4.6 --- ...feature-ha-cv-docs-zero-downtime.infra.md} | 0 docs/changelog.d/main.infra.md | 1 + mise-tasks/changelog-check | 26 +++++++++++++++++++ prek.toml | 12 +++++++++ 4 files changed, 39 insertions(+) rename docs/changelog.d/{feature/ha-cv-docs-zero-downtime.infra.md => feature-ha-cv-docs-zero-downtime.infra.md} (100%) create mode 100644 docs/changelog.d/main.infra.md create mode 100755 mise-tasks/changelog-check diff --git a/docs/changelog.d/feature/ha-cv-docs-zero-downtime.infra.md b/docs/changelog.d/feature-ha-cv-docs-zero-downtime.infra.md similarity index 100% rename from docs/changelog.d/feature/ha-cv-docs-zero-downtime.infra.md rename to docs/changelog.d/feature-ha-cv-docs-zero-downtime.infra.md diff --git a/docs/changelog.d/main.infra.md b/docs/changelog.d/main.infra.md new file mode 100644 index 0000000..6981077 --- /dev/null +++ b/docs/changelog.d/main.infra.md @@ -0,0 +1 @@ +Add pre-commit hook to prevent changelog fragments from being placed in subdirectories. diff --git a/mise-tasks/changelog-check b/mise-tasks/changelog-check new file mode 100755 index 0000000..2bc76ea --- /dev/null +++ b/mise-tasks/changelog-check @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +#MISE description="Validate changelog fragments are flat files in docs/changelog.d/" +# Ensures no fragments end up in subdirectories (e.g. from branch names like feature/foo). +# Towncrier expects flat ..md files, not nested paths. + +set -euo pipefail + +CHANGELOG_DIR="$(git rev-parse --show-toplevel)/docs/changelog.d" + +errors=0 +while IFS= read -r -d '' entry; do + rel="${entry#"$CHANGELOG_DIR/"}" + if [[ "$rel" == */* ]]; then + echo "ERROR: changelog fragment in subdirectory: docs/changelog.d/$rel" + echo " Move to: docs/changelog.d/$(echo "$rel" | tr '/' '-')" + errors=$((errors + 1)) + fi +done < <(find "$CHANGELOG_DIR" -name '*.md' -print0) + +if [ "$errors" -gt 0 ]; then + echo "" + echo "$errors fragment(s) in subdirectories. Towncrier requires flat files in docs/changelog.d/." + exit 1 +fi + +echo "All changelog fragments are correctly placed." diff --git a/prek.toml b/prek.toml index 7b9e06b..6acf7b7 100644 --- a/prek.toml +++ b/prek.toml @@ -120,6 +120,18 @@ language = "system" files = "^(containers/|service-versions\\.yaml)" pass_filenames = false +# Changelog fragment validation (no subdirectories) +[[repos]] +repo = "local" + +[[repos.hooks]] +id = "changelog-check" +name = "changelog-check" +entry = "mise run changelog-check" +language = "system" +files = '^docs/changelog\.d/' +pass_filenames = false + # Mikado Branch Invariant (C2 changes) [[repos]] repo = "local"