1- name : Check CHANGELOG Unreleased Section
1+ name : CHANGELOG Unreleased Section
22
3- on :
4- pull_request :
5- paths :
6- - ' CHANGELOG.md'
7- push :
8- branches :
9- - main
3+ " on " :
4+ push : {branches: [main]}
105
116jobs :
127 check-changelog :
@@ -18,26 +13,47 @@ jobs:
1813 uses : actions/checkout@v5
1914
2015 - name : Extract and validate Unreleased section
21- shell : bash
22- run : |
23- # Extract content between "## Unreleased" and the next "## " section
24- unreleased_content=$(cat CHANGELOG.md | \
25- sed -n '/^## Unreleased$/,/^## /p' | \
26- sed '$d' | \
27- tail -n +2 | \
28- sed '/^$/d' | \
29- sed '/^[[:space:]]*$/d')
30-
31- echo "Extracted unreleased content:"
32- echo "$unreleased_content"
33- echo "---"
34-
35- # Check if the content is empty or only contains whitespace
36- if [ -z "$unreleased_content" ]; then
37- echo "❌ ERROR: CHANGELOG.md '## Unreleased' section is empty or contains only blank lines"
38- echo "Please add at least one entry describing the changes in this release."
39- exit 1
40- else
41- echo "✅ SUCCESS: CHANGELOG.md '## Unreleased' section contains entries"
42- echo "Found $(echo "$unreleased_content" | wc -l) non-blank lines"
43- fi
16+ uses : actions/github-script@v7
17+ with :
18+ script : |
19+ const fs = require('fs');
20+
21+ // Read CHANGELOG.md
22+ const changelog = fs.readFileSync('CHANGELOG.md', 'utf8');
23+
24+ // Split into lines
25+ const lines = changelog.split('\n');
26+
27+ // Find the "## Unreleased" section
28+ const unreleasedIndex = lines.findIndex(line => line.trim() === '## Unreleased');
29+
30+ if (unreleasedIndex === -1) {
31+ core.setFailed('❌ ERROR: Could not find "## Unreleased" section in CHANGELOG.md');
32+ return;
33+ }
34+
35+ // Find the next "## " section (next version)
36+ const nextSectionIndex = lines.findIndex((line, index) =>
37+ index > unreleasedIndex && line.match(/^## \d+\.\d+\.\d+/)
38+ );
39+
40+ // Extract content between sections
41+ const endIndex = nextSectionIndex === -1 ? lines.length : nextSectionIndex;
42+ const unreleasedLines = lines.slice(unreleasedIndex + 1, endIndex);
43+
44+ // Filter out empty lines and whitespace-only lines
45+ const contentLines = unreleasedLines.filter(line =>
46+ line.trim().length > 0
47+ );
48+
49+ console.log('Extracted unreleased content:');
50+ contentLines.forEach(line => console.log(line));
51+ console.log('---');
52+
53+ // Check if there's any actual content
54+ if (contentLines.length === 0) {
55+ core.setFailed('❌ ERROR: CHANGELOG.md "## Unreleased" section is empty or contains only blank lines\nPlease add at least one entry describing the changes in this release.');
56+ } else {
57+ console.log(`✅ SUCCESS: CHANGELOG.md "## Unreleased" section contains entries`);
58+ console.log(`Found ${contentLines.length} non-blank lines`);
59+ }
0 commit comments