Skip to content

Release 2.2.1

Release 2.2.1 #2

name: Changelog Check
on:
pull_request:
branches:
- main
- master
push:
branches:
- main
- master
- dev
env:
# Input directory with the KiCad project and the KiBot files
kibot_input_dir: extension
jobs:
validate-changelog:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v5
- name: Validate Changelog Format
shell: bash
run: |
CHANGELOG_FILE="${{ env.kibot_input_dir }}/CHANGELOG.md"
if [ ! -f "$CHANGELOG_FILE" ]; then
echo "Error: CHANGELOG.md not found in 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 "? [Unreleased] section is empty (allowed during development)"
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 "Warning: No valid sections found in [Unreleased], but content exists"
echo "Expected sections: Added, Changed, Fixed, Removed"
echo "This is allowed during early development"
exit 0
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="${{ env.kibot_input_dir }}/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