diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml index e7fed6e..54e1739 100644 --- a/.github/workflows/auto-release.yml +++ b/.github/workflows/auto-release.yml @@ -61,55 +61,90 @@ jobs: with: fetch-depth: 0 - - name: Generate changelog - id: changelog + - name: Get current commit hash + id: get_commit run: | - NEW_VERSION="${{ needs.check-version.outputs.new_version }}" + COMMIT_SHORT=$(echo "${{ github.sha }}" | cut -c1-7) + echo "COMMIT_SHORT=$COMMIT_SHORT" >> $GITHUB_OUTPUT + + - name: Generate release notes + id: release_notes + run: | + VERSION="${{ needs.check-version.outputs.new_version }}" OLD_VERSION="${{ needs.check-version.outputs.old_version }}" - echo "## ๐ŸŽ‰ Release $NEW_VERSION" > changelog.md - echo "" >> changelog.md - - # ๅฆ‚ๆžœๆœ‰ไธŠไธ€ไธช็‰ˆๆœฌๆ ‡็ญพ๏ผŒ็”Ÿๆˆไธคไธช็‰ˆๆœฌไน‹้—ด็š„ๆไบคๆ—ฅๅฟ— - if git rev-parse "$OLD_VERSION" >/dev/null 2>&1; then - echo "### ๐Ÿ“ Changes since $OLD_VERSION" >> changelog.md - echo "" >> changelog.md - - # ่Žทๅ–ๆไบคไฟกๆฏๅนถๅˆ†็ฑป - git log "$OLD_VERSION..HEAD" --pretty=format:"%s|||%h|||%an" --no-merges | while IFS='|||' read -r subject hash author; do - # ๆ นๆฎๆไบคไฟกๆฏ็š„ๅ‰็ผ€่ฟ›่กŒๅˆ†็ฑป - if echo "$subject" | grep -qiE "^(feat|feature):"; then - echo "- โœจ **Feature**: ${subject#*: } (${hash})" >> changelog.md - elif echo "$subject" | grep -qiE "^fix:"; then - echo "- ๐Ÿ› **Fix**: ${subject#*: } (${hash})" >> changelog.md - elif echo "$subject" | grep -qiE "^docs:"; then - echo "- ๐Ÿ“š **Docs**: ${subject#*: } (${hash})" >> changelog.md - elif echo "$subject" | grep -qiE "^(refactor|style|perf|test|chore):"; then - prefix=$(echo "$subject" | cut -d: -f1) - echo "- ๐Ÿ”ง **${prefix^}**: ${subject#*: } (${hash})" >> changelog.md - else - echo "- ๐Ÿ“Œ $subject (${hash})" >> changelog.md - fi - done - else - echo "### ๐Ÿ“ Changes" >> changelog.md - echo "" >> changelog.md - echo "Initial release or no previous version tag found." >> changelog.md - echo "" >> changelog.md - echo "#### Recent commits:" >> changelog.md - git log -10 --pretty=format:"- %s (%h)" --no-merges >> changelog.md + # 1. ๅฐ่ฏ•ๆๅ– CHANGELOG.md + if [ -f "CHANGELOG.md" ]; then + awk -v ver="$VERSION" ' + /^## \[?v?/ && index($0, ver) { flag=1 } + /^## \[?v?/ && !index($0, ver) { flag=0 } + flag + ' CHANGELOG.md > release_notes.md fi - echo "" >> changelog.md - echo "---" >> changelog.md - echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/$OLD_VERSION...$NEW_VERSION" >> changelog.md + # ็กฎไฟ release_notes.md ๅญ˜ๅœจ + touch release_notes.md + + # 2. ็”Ÿๆˆๆไบคๅˆ—่กจ + echo "" >> release_notes.md + echo "### ๐Ÿ” Commits" >> release_notes.md + + process_log() { + local range="$1" + git log --pretty=format:"%s|%h|%H" "$range" > commits.txt + + # Helper to extract categories + print_category() { + local marker="$1" + local title="$2" + local pattern="$3" + local commits=$(grep -iE "$pattern" commits.txt) + if [ ! -z "$commits" ]; then + echo "#### $marker $title" >> release_notes.md + echo "$commits" | while IFS='|' read -r msg hash full_hash; do + echo "- $msg ([$hash](https://github.com/${{ github.repository }}/commit/$full_hash))" >> release_notes.md + done + echo "" >> release_notes.md + fi + } + + print_category "โœจ" "Features" "^(feat|feature):" + print_category "๐Ÿ›" "Fixes" "^fix:" + print_category "๐Ÿ“š" "Documentation" "^docs:" + print_category "๐Ÿ’„" "Style & Refactor" "^(style|refactor|perf):" + print_category "๐Ÿ”ง" "Chore & Test" "^(chore|test|ci|build):" + + # Other changes (inverse grep) + local others=$(grep -ivE "^(feat|feature|fix|docs|style|refactor|perf|chore|test|ci|build):" commits.txt) + if [ ! -z "$others" ]; then + echo "#### ๐Ÿ“Œ Other Changes" >> release_notes.md + echo "$others" | while IFS='|' read -r msg hash full_hash; do + echo "- $msg ([$hash](https://github.com/${{ github.repository }}/commit/$full_hash))" >> release_notes.md + done + fi + + rm commits.txt + } + + if [ "$OLD_VERSION" != "none" ] && git rev-parse "$OLD_VERSION" >/dev/null 2>&1; then + process_log "$OLD_VERSION..HEAD" + + echo "" >> release_notes.md + echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/$OLD_VERSION...${{ github.ref_name }}" >> release_notes.md + else + echo "Initial release or previous version tag not found." >> release_notes.md + echo "#### ๐Ÿ†• Initial Commits" >> release_notes.md + git log -10 --pretty=format:"- %s ([%h](https://github.com/${{ github.repository }}/commit/%H))" >> release_notes.md + fi + + cat release_notes.md - name: Create Release uses: softprops/action-gh-release@v1 with: tag_name: ${{ needs.check-version.outputs.new_version }} name: Release ${{ needs.check-version.outputs.new_version }} - body_path: changelog.md + body_path: release_notes.md draft: false prerelease: false generate_release_notes: false