Skip to content

Conversation

@kevalyq
Copy link
Contributor

@kevalyq kevalyq commented Nov 2, 2025

🔄 Sync: CHANGELOG Validation from API Repo

Context: Multi-repo script synchronization initiative. Brings CHANGELOG validation improvements from api #77 to contracts.

🎯 Problem Solved

Before: Contracts had no automated CHANGELOG validation

  • ❌ Easy to forget updating CHANGELOG.md
  • ❌ No early feedback (only discovered in PR reviews)
  • ❌ Inconsistent enforcement between repos

After: Automated validation matches api repo behavior

  • ✅ Validates [Unreleased] section exists
  • ✅ Checks for minimum content (catches empty sections)
  • ✅ Smart exemptions for docs/chore/ci/test branches
  • ✅ Early feedback in local preflight (before CI)

📝 Changes

File: scripts/preflight.sh

Added Section (after Node.js/npm checks, before PR size check):

# 3) CHANGELOG validation (for non-docs branches)
# Branch prefixes that are exempt from CHANGELOG updates (configuration)
CHANGELOG_EXEMPT_PREFIXES="^(docs|chore|ci|test)/"
# Minimum lines in [Unreleased] to consider it non-empty
MIN_CHANGELOG_LINES=3

CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ -f CHANGELOG.md ] && [ "$CURRENT_BRANCH" != "main" ] && 
   [[ ! "$CURRENT_BRANCH" =~ $CHANGELOG_EXEMPT_PREFIXES ]]; then
  # Validate [Unreleased] section exists and has content
  # Robust parsing handles edge cases (last section, etc.)
fi

Key Features:

  1. Configurable variables (CHANGELOG_EXEMPT_PREFIXES, MIN_CHANGELOG_LINES)
  2. Robust parsing handles [Unreleased] as last/only section
  3. Smart exemptions for non-feature branches
  4. Helpful error messages guide developers

✅ Benefits

Consistency:

  • ✅ Same CHANGELOG policy enforcement across api/frontend/contracts
  • ✅ Reduces "forgot CHANGELOG" PR comments
  • ✅ Ensures documentation stays current

Developer Experience:

  • Early feedback (local preflight vs CI failure)
  • Clear errors with actionable tips
  • Smart exemptions don't block docs-only work

Maintainability:

  • Configurable via variables (easy to adjust)
  • Documented inline comments explain logic
  • Tested extensively in api repo (PR #77)

🔗 Related

Original Implementation:

  • api #77 ✅ Merged - Original CHANGELOG validation
  • api docs/SELF_REVIEW_CHECKLIST.md - Documents CHANGELOG policy

Copilot Feedback Integration:

  • Magic numbers → Config variables
  • Hardcoded patterns → Extractable config
  • Fragile parsing → Robust line-number extraction

Multi-Repo Sync:

🧪 Testing

Syntax validation:

$ bash -n scripts/preflight.sh
✓ Syntax OK

Expected behavior:

  • Feature branch without CHANGELOG update → ❌ Fails with helpful message
  • Feature branch with empty [Unreleased] → ⚠️ Warning
  • docs/* branches → ✅ Skipped (no CHANGELOG requirement)
  • main branch → ✅ Skipped

OpenAPI-specific note: Since contracts repo primarily contains OpenAPI specifications (not source code), most changes will still benefit from CHANGELOG documentation for API version tracking and client notifications.


Review Focus: Verify CHANGELOG validation logic matches api repo exactly. Confirm error messages are contracts-appropriate.

SPDX-FileCopyrightText: 2025 SecPal
SPDX-License-Identifier: MIT

Syncs CHANGELOG validation logic from api repo (PR #77) to contracts.

Changes:
- Validates [Unreleased] section exists on feature/fix/refactor branches
- Checks for minimum content (MIN_CHANGELOG_LINES=3)
- Exempts docs/*, chore/*, ci/*, test/* branches
- Robust parsing handles [Unreleased] as last section (edge case fix)
- Uses configurable variables for maintainability

Context: Multi-repo script synchronization initiative. Ensures
consistent CHANGELOG policy enforcement across all SecPal repos.

Benefits:
- ✅ Prevents "forgot to update CHANGELOG" PR comments
- ✅ Catches empty [Unreleased] sections (copy-paste artifacts)
- ✅ Smart exemptions for docs-only branches
- ✅ Early feedback (local preflight vs CI failure)

Related:
- api #77: Original CHANGELOG validation implementation
- frontend #55: Parallel sync to frontend repo
- .github #168: Template documentation
Copilot AI review requested due to automatic review settings November 2, 2025 17:56
@github-actions
Copy link

github-actions bot commented Nov 2, 2025

💡 Tip: Consider Using Draft PRs

Benefits of opening PRs as drafts initially:

  • 💰 Saves CI runtime and Copilot review credits
  • 🎯 Automatically sets linked issues to "🚧 In Progress" status
  • 🚀 Mark "Ready for review" when done to trigger full CI pipeline

How to convert:

  1. Click "Still in progress? Convert to draft" in the sidebar, OR
  2. Use gh pr ready when ready for review

This is just a friendly reminder - feel free to continue as is! 😊

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request adds CHANGELOG.md validation to the preflight script to ensure developers document their changes before pushing code. The validation checks for the presence and content of the [Unreleased] section in non-exempt branches.

Key changes:

  • Adds automatic validation that CHANGELOG.md contains an [Unreleased] section with meaningful content
  • Exempts documentation-only branches (docs/, chore/, ci/, test/) from CHANGELOG requirements
  • Provides helpful error messages when validation fails

…s, MIN_CHANGELOG_LINES)

- Replace bash-specific [[ =~ ]] with POSIX case statement for portability
- Use grep -nE for robust [Unreleased] matching (supports Keep a Changelog links)
- Extract duplicated grep chains to filter_changelog_content() with whitespace tolerance
- Clarify MIN_CHANGELOG_LINES comment about what is counted (substantive content only)

Addresses all 4 Copilot review comments on PR #39
@kevalyq kevalyq merged commit d213ab2 into main Nov 2, 2025
8 checks passed
@kevalyq kevalyq deleted the feat/sync-changelog-validation branch November 2, 2025 18:17
@github-actions
Copy link

github-actions bot commented Nov 2, 2025

💡 Tip: Consider Using Draft PRs

Benefits of opening PRs as drafts initially:

  • 💰 Saves CI runtime and Copilot review credits
  • 🎯 Automatically sets linked issues to "🚧 In Progress" status
  • 🚀 Mark "Ready for review" when done to trigger full CI pipeline

How to convert:

  1. Click "Still in progress? Convert to draft" in the sidebar, OR
  2. Use gh pr ready when ready for review

This is just a friendly reminder - feel free to continue as is! 😊

kevalyq added a commit that referenced this pull request Nov 2, 2025
* feat: add CHANGELOG validation to preflight script

SPDX-FileCopyrightText: 2025 SecPal
SPDX-License-Identifier: MIT

Syncs CHANGELOG validation logic from api repo (PR #77) to contracts.

Changes:
- Validates [Unreleased] section exists on feature/fix/refactor branches
- Checks for minimum content (MIN_CHANGELOG_LINES=3)
- Exempts docs/*, chore/*, ci/*, test/* branches
- Robust parsing handles [Unreleased] as last section (edge case fix)
- Uses configurable variables for maintainability

Context: Multi-repo script synchronization initiative. Ensures
consistent CHANGELOG policy enforcement across all SecPal repos.

Benefits:
- ✅ Prevents "forgot to update CHANGELOG" PR comments
- ✅ Catches empty [Unreleased] sections (copy-paste artifacts)
- ✅ Smart exemptions for docs-only branches
- ✅ Early feedback (local preflight vs CI failure)

Related:
- api #77: Original CHANGELOG validation implementation
- frontend #55: Parallel sync to frontend repo
- .github #168: Template documentation

* fix: address Copilot feedback (case statement, grep -nE, HTML patterns, MIN_CHANGELOG_LINES)

- Replace bash-specific [[ =~ ]] with POSIX case statement for portability
- Use grep -nE for robust [Unreleased] matching (supports Keep a Changelog links)
- Extract duplicated grep chains to filter_changelog_content() with whitespace tolerance
- Clarify MIN_CHANGELOG_LINES comment about what is counted (substantive content only)

Addresses all 4 Copilot review comments on PR #39

* fix: improve pre-push error message for PR size violations

Same fix as SecPal/api#81 - enhanced error message clarity with:
- Visual separators for attention
- Exact breakdown (insertions + deletions)
- Numbered options for bypass
- Clear "Push aborted" message

See SecPal/api#80 for problem description

* fix: remove --no-verify suggestion per Copilot review

* refactor: optimize CHANGELOG validation per Copilot review

- Combine multiple grep -Ev calls into single grep with pattern group
- Use grep -m 1 for early termination (performance improvement)
- Fix sed range calculation (UNRELEASED_END is relative, not absolute)
- Add clarifying comments about CHANGELOG_EXEMPT_PREFIXES and case sync
- Improve warning message with specific line count and non-blocking note

Addresses Copilot review comments in PR #40
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.

2 participants