|
| 1 | +--- |
| 2 | +name: CHANGELOG Unreleased Section |
| 3 | + |
| 4 | +"on": |
| 5 | + push: {branches: [main]} |
| 6 | + |
| 7 | +jobs: |
| 8 | + check-changelog: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + name: Verify CHANGELOG.md has unreleased entries |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Checkout repository |
| 14 | + uses: actions/checkout@v5 |
| 15 | + |
| 16 | + - name: Extract and validate Unreleased section |
| 17 | + uses: actions/github-script@v7 |
| 18 | + with: |
| 19 | + script: | |
| 20 | + const fs = require('fs'); |
| 21 | +
|
| 22 | + // Read CHANGELOG.md |
| 23 | + const changelog = fs.readFileSync('CHANGELOG.md', 'utf8'); |
| 24 | +
|
| 25 | + // Split into lines |
| 26 | + const lines = changelog.split('\n'); |
| 27 | +
|
| 28 | + // Find the "## Unreleased" section |
| 29 | + const unreleasedIndex = lines.findIndex(line => line.trim() === '## Unreleased'); |
| 30 | +
|
| 31 | + if (unreleasedIndex === -1) { |
| 32 | + core.setFailed('❌ ERROR: Could not find "## Unreleased" section in CHANGELOG.md'); |
| 33 | + return; |
| 34 | + } |
| 35 | +
|
| 36 | + // Find the next "## " section (next version) |
| 37 | + const nextSectionIndex = lines.findIndex((line, index) => |
| 38 | + index > unreleasedIndex && line.match(/^## \d+\.\d+\.\d+/) |
| 39 | + ); |
| 40 | +
|
| 41 | + // Extract content between sections |
| 42 | + const endIndex = nextSectionIndex === -1 ? lines.length : nextSectionIndex; |
| 43 | + const unreleasedLines = lines.slice(unreleasedIndex + 1, endIndex); |
| 44 | +
|
| 45 | + // Filter out empty lines and whitespace-only lines |
| 46 | + const contentLines = unreleasedLines.filter(line => |
| 47 | + line.trim().length > 0 |
| 48 | + ); |
| 49 | +
|
| 50 | + console.log('Extracted unreleased content:'); |
| 51 | + contentLines.forEach(line => console.log(line)); |
| 52 | + console.log('---'); |
| 53 | +
|
| 54 | + // Check if there's any actual content |
| 55 | + if (contentLines.length === 0) { |
| 56 | + 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.'); |
| 57 | + } else { |
| 58 | + console.log(`✅ SUCCESS: CHANGELOG.md "## Unreleased" section contains entries`); |
| 59 | + console.log(`Found ${contentLines.length} non-blank lines`); |
| 60 | + } |
0 commit comments