|
| 1 | +# Backup: Generate Release Notes from commits |
| 2 | +# This workflow generates release notes from commits when PRs are not available. |
| 3 | +# For PR-based releases, use GitHub's built-in "Generate release notes" button |
| 4 | +# which uses .github/release.yml configuration. |
| 5 | + |
| 6 | +name: Generate Release Notes (Backup) |
| 7 | + |
| 8 | +# DISABLED - Using GitHub's built-in "Generate release notes" instead |
| 9 | +# This workflow is kept for reference but will NOT run automatically. |
| 10 | +# To enable: uncomment the "on:" section below and remove workflow_dispatch |
| 11 | + |
| 12 | +# on: |
| 13 | +# release: |
| 14 | +# types: [created] |
| 15 | + |
| 16 | +# Only allows manual trigger, prevents automatic execution |
| 17 | +on: |
| 18 | + workflow_dispatch: |
| 19 | + |
| 20 | +jobs: |
| 21 | + generate-release-notes: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + permissions: |
| 24 | + contents: write |
| 25 | + steps: |
| 26 | + - name: Checkout |
| 27 | + uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + fetch-depth: 0 |
| 30 | + |
| 31 | + - name: Generate Release Notes from Commits |
| 32 | + id: generate_notes |
| 33 | + uses: actions/github-script@v7 |
| 34 | + with: |
| 35 | + script: | |
| 36 | + const { data: release } = await github.rest.repos.getRelease({ |
| 37 | + owner: context.repo.owner, |
| 38 | + repo: context.repo.repo, |
| 39 | + release_id: context.payload.release.id, |
| 40 | + }); |
| 41 | + |
| 42 | + const tagName = release.tag_name; |
| 43 | + const previousTag = await github.rest.repos.listTags({ |
| 44 | + owner: context.repo.owner, |
| 45 | + repo: context.repo.repo, |
| 46 | + per_page: 2, |
| 47 | + }); |
| 48 | + |
| 49 | + let previousTagName = ''; |
| 50 | + if (previousTag.data.length > 1) { |
| 51 | + previousTagName = previousTag.data[1].name; |
| 52 | + } |
| 53 | + |
| 54 | + // Get commits between tags |
| 55 | + const { data: commits } = await github.rest.repos.compareCommits({ |
| 56 | + owner: context.repo.owner, |
| 57 | + repo: context.repo.repo, |
| 58 | + base: previousTagName || 'HEAD~50', |
| 59 | + head: tagName, |
| 60 | + }); |
| 61 | + |
| 62 | + // Categorize commits |
| 63 | + const breaking = []; |
| 64 | + const features = []; |
| 65 | + const fixes = []; |
| 66 | + const improvements = []; |
| 67 | + const docs = []; |
| 68 | + const other = []; |
| 69 | + |
| 70 | + commits.commits.forEach(commit => { |
| 71 | + const message = commit.commit.message; |
| 72 | + const firstLine = message.split('\n')[0]; |
| 73 | + |
| 74 | + if (firstLine.toLowerCase().includes('breaking') || firstLine.includes('!:')) { |
| 75 | + breaking.push(`- ${firstLine}`); |
| 76 | + } else if (firstLine.toLowerCase().startsWith('feat') || firstLine.toLowerCase().includes('feature')) { |
| 77 | + features.push(`- ${firstLine}`); |
| 78 | + } else if (firstLine.toLowerCase().startsWith('fix') || firstLine.toLowerCase().includes('bug')) { |
| 79 | + fixes.push(`- ${firstLine}`); |
| 80 | + } else if (firstLine.toLowerCase().startsWith('refactor') || firstLine.toLowerCase().includes('improve')) { |
| 81 | + improvements.push(`- ${firstLine}`); |
| 82 | + } else if (firstLine.toLowerCase().startsWith('docs') || firstLine.toLowerCase().includes('doc')) { |
| 83 | + docs.push(`- ${firstLine}`); |
| 84 | + } else if (!firstLine.toLowerCase().startsWith('chore') && !firstLine.toLowerCase().startsWith('ci') && !firstLine.toLowerCase().startsWith('build')) { |
| 85 | + other.push(`- ${firstLine}`); |
| 86 | + } |
| 87 | + }); |
| 88 | + |
| 89 | + // Build release notes |
| 90 | + let releaseNotes = `## Release ${tagName}\n\n`; |
| 91 | + |
| 92 | + if (breaking.length > 0) { |
| 93 | + releaseNotes += `### Breaking Changes\n${breaking.join('\n')}\n\n`; |
| 94 | + } |
| 95 | + if (features.length > 0) { |
| 96 | + releaseNotes += `### New Features\n${features.join('\n')}\n\n`; |
| 97 | + } |
| 98 | + if (fixes.length > 0) { |
| 99 | + releaseNotes += `### Bug Fixes\n${fixes.join('\n')}\n\n`; |
| 100 | + } |
| 101 | + if (improvements.length > 0) { |
| 102 | + releaseNotes += `### Improvements\n${improvements.join('\n')}\n\n`; |
| 103 | + } |
| 104 | + if (docs.length > 0) { |
| 105 | + releaseNotes += `### Documentation\n${docs.join('\n')}\n\n`; |
| 106 | + } |
| 107 | + if (other.length > 0) { |
| 108 | + releaseNotes += `### Other Changes\n${other.join('\n')}\n\n`; |
| 109 | + } |
| 110 | + |
| 111 | + if (previousTagName) { |
| 112 | + releaseNotes += `\n**Full Changelog**: ${previousTagName}...${tagName}`; |
| 113 | + } |
| 114 | + |
| 115 | + // Update release |
| 116 | + await github.rest.repos.updateRelease({ |
| 117 | + owner: context.repo.owner, |
| 118 | + repo: context.repo.repo, |
| 119 | + release_id: context.payload.release.id, |
| 120 | + body: releaseNotes |
| 121 | + }); |
| 122 | + |
| 123 | + console.log('Release notes generated successfully!'); |
| 124 | +
|
0 commit comments