Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 171 additions & 0 deletions .github/workflows/changelog-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
name: Changelog Check

on:
pull_request:
paths:
- 'hardware/CHANGELOG.md'
push:
branches:
- main
- master
- dev
paths:
- 'hardware/CHANGELOG.md'

env:
# Master branch (main or master)
master_branch: main

jobs:
validate-changelog:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v5

- name: Validate Changelog Format
shell: bash
run: |
CHANGELOG_FILE="hardware/CHANGELOG.md"

if [ ! -f "$CHANGELOG_FILE" ]; then
echo "Error: CHANGELOG.md not found in hardware directory"
exit 1
fi

echo "Validating CHANGELOG.md format..."

# Check if [Unreleased] section exists
if ! grep -q "\[Unreleased\]" "$CHANGELOG_FILE"; then
echo "Error: [Unreleased] section not found in CHANGELOG.md"
exit 1
fi

# Extract [Unreleased] section content
UNRELEASED_CONTENT=$(awk '/\[Unreleased\]/,/^## \[/' "$CHANGELOG_FILE" | sed '1d;$d')

if [ -z "$UNRELEASED_CONTENT" ]; then
echo "Warning: [Unreleased] section is empty"
exit 0
fi

echo "Checking [Unreleased] section content..."

# Valid section headers
VALID_SECTIONS=("### Added" "### Changed" "### Fixed" "### Removed")

# Check for valid section headers
FOUND_SECTIONS=false
for section in "${VALID_SECTIONS[@]}"; do
if echo "$UNRELEASED_CONTENT" | grep -q "^$section"; then
FOUND_SECTIONS=true
echo "✓ Found section: $section"
fi
done

if [ "$FOUND_SECTIONS" = false ]; then
echo "Error: No valid sections found in [Unreleased]"
echo "Expected sections: Added, Changed, Fixed, Removed"
exit 1
fi

# Validate entry format: must start with "- " (dash + space/tab) and contain issue reference "(#number)"
ERROR_COUNT=0
LINE_NUMBER=0

echo ""
echo "Validating entry format..."

while IFS= read -r line; do
LINE_NUMBER=$((LINE_NUMBER + 1))

# Skip empty lines and section headers
if [[ -z "$line" ]] || [[ "$line" =~ ^### ]]; then
continue
fi

# Check if line is an entry (starts with -)
if [[ "$line" =~ ^[[:space:]]*- ]]; then
# Check for issue reference in format (#number)
if ! [[ "$line" =~ \(#[0-9]+\) ]]; then
echo "✗ Line $LINE_NUMBER: Missing or invalid issue reference (expected format: (#123))"
echo " Content: $line"
ERROR_COUNT=$((ERROR_COUNT + 1))
else
echo "✓ Line $LINE_NUMBER: Valid entry"
fi
elif [[ "$line" =~ ^[[:space:]]*[^-] ]]; then
# Line has content but doesn't start with -
echo "✗ Line $LINE_NUMBER: Entry must start with '- ' (dash + space)"
echo " Content: $line"
ERROR_COUNT=$((ERROR_COUNT + 1))
fi
done <<< "$UNRELEASED_CONTENT"

echo ""
if [ $ERROR_COUNT -gt 0 ]; then
echo "=========================================="
echo "Changelog validation FAILED"
echo "=========================================="
echo "Found $ERROR_COUNT error(s)"
echo ""
echo "Requirements:"
echo "1. All entries must be grouped under: Added, Changed, Fixed, or Removed"
echo "2. Each entry must start with '- ' (dash + space or tab)"
echo "3. Each entry must contain an issue reference in format (#number)"
echo ""
echo "Example:"
echo "## [Unreleased]"
echo ""
echo "### Added"
echo "- New feature description (#123)"
echo "- Another feature (#124)"
echo ""
echo "### Fixed"
echo "- Bug fix description (#125)"
echo ""
exit 1
else
echo "=========================================="
echo "Changelog validation PASSED"
echo "=========================================="
echo "All entries in [Unreleased] are properly formatted"
fi

- name: Check for duplicate issue numbers
shell: bash
run: |
CHANGELOG_FILE="hardware/CHANGELOG.md"

echo "Checking for duplicate issue numbers in [Unreleased] section..."

# Extract issue numbers from [Unreleased] section
UNRELEASED_CONTENT=$(awk '/\[Unreleased\]/,/^## \[/' "$CHANGELOG_FILE" | sed '1d;$d')

if [ -z "$UNRELEASED_CONTENT" ]; then
echo "No content to check"
exit 0
fi

# Extract all issue numbers
ISSUE_NUMBERS=$(echo "$UNRELEASED_CONTENT" | grep -oP '\(#\K[0-9]+(?=\))' || true)

if [ -z "$ISSUE_NUMBERS" ]; then
echo "No issue numbers found"
exit 0
fi

# Check for duplicates
DUPLICATES=$(echo "$ISSUE_NUMBERS" | sort | uniq -d)

if [ -n "$DUPLICATES" ]; then
echo "Warning: Duplicate issue numbers found in [Unreleased] section:"
echo "$DUPLICATES" | while read -r issue; do
echo " - Issue #$issue appears multiple times"
done
echo ""
echo "This is not an error, but you may want to review if this is intentional"
else
echo "✓ No duplicate issue numbers found"
fi
Loading
Loading