Skip to content

Commit 10c6a98

Browse files
committed
Release 0.0.2
Signed-off-by: Daniel Kampert <DanielKampert@kampis-elektroecke.de>
1 parent 8143be9 commit 10c6a98

File tree

4 files changed

+277
-127
lines changed

4 files changed

+277
-127
lines changed
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
name: Changelog Check
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'hardware/CHANGELOG.md'
7+
push:
8+
branches:
9+
- main
10+
- master
11+
- dev
12+
paths:
13+
- 'hardware/CHANGELOG.md'
14+
15+
env:
16+
# Master branch (main or master)
17+
master_branch: main
18+
19+
jobs:
20+
validate-changelog:
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- name: Checkout Repository
25+
uses: actions/checkout@v5
26+
27+
- name: Validate Changelog Format
28+
shell: bash
29+
run: |
30+
CHANGELOG_FILE="hardware/CHANGELOG.md"
31+
32+
if [ ! -f "$CHANGELOG_FILE" ]; then
33+
echo "Error: CHANGELOG.md not found in hardware directory"
34+
exit 1
35+
fi
36+
37+
echo "Validating CHANGELOG.md format..."
38+
39+
# Check if [Unreleased] section exists
40+
if ! grep -q "\[Unreleased\]" "$CHANGELOG_FILE"; then
41+
echo "Error: [Unreleased] section not found in CHANGELOG.md"
42+
exit 1
43+
fi
44+
45+
# Extract [Unreleased] section content
46+
UNRELEASED_CONTENT=$(awk '/\[Unreleased\]/,/^## \[/' "$CHANGELOG_FILE" | sed '1d;$d')
47+
48+
if [ -z "$UNRELEASED_CONTENT" ]; then
49+
echo "Warning: [Unreleased] section is empty"
50+
exit 0
51+
fi
52+
53+
echo "Checking [Unreleased] section content..."
54+
55+
# Valid section headers
56+
VALID_SECTIONS=("### Added" "### Changed" "### Fixed" "### Removed")
57+
58+
# Check for valid section headers
59+
FOUND_SECTIONS=false
60+
for section in "${VALID_SECTIONS[@]}"; do
61+
if echo "$UNRELEASED_CONTENT" | grep -q "^$section"; then
62+
FOUND_SECTIONS=true
63+
echo "✓ Found section: $section"
64+
fi
65+
done
66+
67+
if [ "$FOUND_SECTIONS" = false ]; then
68+
echo "Error: No valid sections found in [Unreleased]"
69+
echo "Expected sections: Added, Changed, Fixed, Removed"
70+
exit 1
71+
fi
72+
73+
# Validate entry format: must start with "- " (dash + space/tab) and contain issue reference "(#number)"
74+
ERROR_COUNT=0
75+
LINE_NUMBER=0
76+
77+
echo ""
78+
echo "Validating entry format..."
79+
80+
while IFS= read -r line; do
81+
LINE_NUMBER=$((LINE_NUMBER + 1))
82+
83+
# Skip empty lines and section headers
84+
if [[ -z "$line" ]] || [[ "$line" =~ ^### ]]; then
85+
continue
86+
fi
87+
88+
# Check if line is an entry (starts with -)
89+
if [[ "$line" =~ ^[[:space:]]*- ]]; then
90+
# Check for issue reference in format (#number)
91+
if ! [[ "$line" =~ \(#[0-9]+\) ]]; then
92+
echo "✗ Line $LINE_NUMBER: Missing or invalid issue reference (expected format: (#123))"
93+
echo " Content: $line"
94+
ERROR_COUNT=$((ERROR_COUNT + 1))
95+
else
96+
echo "✓ Line $LINE_NUMBER: Valid entry"
97+
fi
98+
elif [[ "$line" =~ ^[[:space:]]*[^-] ]]; then
99+
# Line has content but doesn't start with -
100+
echo "✗ Line $LINE_NUMBER: Entry must start with '- ' (dash + space)"
101+
echo " Content: $line"
102+
ERROR_COUNT=$((ERROR_COUNT + 1))
103+
fi
104+
done <<< "$UNRELEASED_CONTENT"
105+
106+
echo ""
107+
if [ $ERROR_COUNT -gt 0 ]; then
108+
echo "=========================================="
109+
echo "Changelog validation FAILED"
110+
echo "=========================================="
111+
echo "Found $ERROR_COUNT error(s)"
112+
echo ""
113+
echo "Requirements:"
114+
echo "1. All entries must be grouped under: Added, Changed, Fixed, or Removed"
115+
echo "2. Each entry must start with '- ' (dash + space or tab)"
116+
echo "3. Each entry must contain an issue reference in format (#number)"
117+
echo ""
118+
echo "Example:"
119+
echo "## [Unreleased]"
120+
echo ""
121+
echo "### Added"
122+
echo "- New feature description (#123)"
123+
echo "- Another feature (#124)"
124+
echo ""
125+
echo "### Fixed"
126+
echo "- Bug fix description (#125)"
127+
echo ""
128+
exit 1
129+
else
130+
echo "=========================================="
131+
echo "Changelog validation PASSED"
132+
echo "=========================================="
133+
echo "All entries in [Unreleased] are properly formatted"
134+
fi
135+
136+
- name: Check for duplicate issue numbers
137+
shell: bash
138+
run: |
139+
CHANGELOG_FILE="hardware/CHANGELOG.md"
140+
141+
echo "Checking for duplicate issue numbers in [Unreleased] section..."
142+
143+
# Extract issue numbers from [Unreleased] section
144+
UNRELEASED_CONTENT=$(awk '/\[Unreleased\]/,/^## \[/' "$CHANGELOG_FILE" | sed '1d;$d')
145+
146+
if [ -z "$UNRELEASED_CONTENT" ]; then
147+
echo "No content to check"
148+
exit 0
149+
fi
150+
151+
# Extract all issue numbers
152+
ISSUE_NUMBERS=$(echo "$UNRELEASED_CONTENT" | grep -oP '\(#\K[0-9]+(?=\))' || true)
153+
154+
if [ -z "$ISSUE_NUMBERS" ]; then
155+
echo "No issue numbers found"
156+
exit 0
157+
fi
158+
159+
# Check for duplicates
160+
DUPLICATES=$(echo "$ISSUE_NUMBERS" | sort | uniq -d)
161+
162+
if [ -n "$DUPLICATES" ]; then
163+
echo "Warning: Duplicate issue numbers found in [Unreleased] section:"
164+
echo "$DUPLICATES" | while read -r issue; do
165+
echo " - Issue #$issue appears multiple times"
166+
done
167+
echo ""
168+
echo "This is not an error, but you may want to review if this is intentional"
169+
else
170+
echo "✓ No duplicate issue numbers found"
171+
fi

0 commit comments

Comments
 (0)