From 42c9297ad85237cb4be6cf91607768e0597f19bf Mon Sep 17 00:00:00 2001 From: Estee Tey Date: Sat, 3 May 2025 21:29:42 +0800 Subject: [PATCH] fix generate version script to put commits in correct tags (#128) --- public/CHANGELOG.md | 199 +++++++++++------------ scripts/generate-version.sh | 310 +++++++++++++++++------------------- 2 files changed, 239 insertions(+), 270 deletions(-) diff --git a/public/CHANGELOG.md b/public/CHANGELOG.md index 6317abc..160f8a7 100644 --- a/public/CHANGELOG.md +++ b/public/CHANGELOG.md @@ -1,149 +1,128 @@ -## v0.17.1 (2025-04-26) +## v0.18.0 (2025-05-03) +- ✨ Add changelog footer ([#126](https://github.com/lyqht/mini-qr/pull/126)) +- 🐛 script adding extra linebreaks in changelog.md +- 🐛 improve URL detection regex to support more comprehensive URLs ([#125](https://github.com/lyqht/mini-qr/pull/125)) +- 🔧 disable pwa in dev ([#121](https://github.com/lyqht/mini-qr/pull/121)) -- 🐛 fix(QRCodeScan.vue): improve URL detection regex to support more comprehensive URLs - ([#125](https://github.com/lyqht/mini-qr/pull/125)) +## v0.17.1 (2025-04-26) +- 🔧 revert removing SVG option ([#120](https://github.com/lyqht/mini-qr/pull/120)) + +## v0.17.0 (2025-04-26) +- ✨ Add frame text support for batch QR code generation ([#117](https://github.com/lyqht/mini-qr/pull/117)) +- 🔧 Enhance form styling and fix drawer z-index ([#115](https://github.com/lyqht/mini-qr/pull/115)) ## v0.16.0 (2025-04-25) - -- ✨ Add frame text support for batch QR code generation - ([#117](https://github.com/lyqht/mini-qr/pull/117)) +- ✨ Add data templates for QR codes ([#109](https://github.com/lyqht/mini-qr/pull/109)) +- ✨ Add Playwright E2E testing framework ([#106](https://github.com/lyqht/mini-qr/pull/106)) +- 🐛 italian translations +- 🐛 add overflow-hidden class to the element-to-export div to prevent overflow issues +- 🔧 New Crowdin updates ([#108](https://github.com/lyqht/mini-qr/pull/108)) +- 🔧 add crowdin translations +- 🔧 Remove svg export option ([#112](https://github.com/lyqht/mini-qr/pull/112)) ## v0.15.0 (2025-03-30) - -- ✨ Add data templates for QR codes - ([#109](https://github.com/lyqht/mini-qr/pull/109)) -- ✨ Add Playwright E2E testing framework - ([#106](https://github.com/lyqht/mini-qr/pull/106)) -- 🐛 italian translations - ([#109](https://github.com/lyqht/mini-qr/pull/109)) -- 🐛 fix(QRCodeCreate.vue): add overflow-hidden class to the element-to-export div to prevent overflow issues - ([#109](https://github.com/lyqht/mini-qr/pull/109)) -- 🔧 New Crowdin updates - ([#108](https://github.com/lyqht/mini-qr/pull/108)) -- Remove svg export option - ([#112](https://github.com/lyqht/mini-qr/pull/112)) +- ✨ Add camera switching feature to QR code scanner ([#103](https://github.com/lyqht/mini-qr/pull/103)) +- ✨ Add QR code frame feature with customizable text and styling ([#100](https://github.com/lyqht/mini-qr/pull/100)) +- ✨ Add jpg export ([#99](https://github.com/lyqht/mini-qr/pull/99)) +- 🐛 Update README.md +- 🔧 Add translations ([#104](https://github.com/lyqht/mini-qr/pull/104)) ## v0.14.0 (2025-03-17) +- ✨ Add PWA support for desktop and mobile installation ([#96](https://github.com/lyqht/mini-qr/pull/96)) -- ✨ Add camera switching feature to QR code scanner - ([#103](https://github.com/lyqht/mini-qr/pull/103)) -- ✨ Add QR code frame feature with customizable text and styling - ([#100](https://github.com/lyqht/mini-qr/pull/100)) -- ✨ Add jpg export - ([#99](https://github.com/lyqht/mini-qr/pull/99)) -- 🐛 Update README.md - ([#104](https://github.com/lyqht/mini-qr/pull/104)) -- 🔧 Add translations - ([#104](https://github.com/lyqht/mini-qr/pull/104)) +## v0.13.1 (2025-03-13) +- 🐛 Improve QR code mobile drawer styling ([#97](https://github.com/lyqht/mini-qr/pull/97)) ## v0.13.0 (2025-03-12) +- ✨ Add language selector with auto-detection and persistence ([#90](https://github.com/lyqht/mini-qr/pull/90)) +- 🔧 v0.13.0 ([#94](https://github.com/lyqht/mini-qr/pull/94)) -- Improve QR code mobile drawer styling - ([#97](https://github.com/lyqht/mini-qr/pull/97)) +## v0.12.0 (2025-03-05) +- 🐛 Improve MiniQR UI ([#88](https://github.com/lyqht/mini-qr/pull/88)) +- 🔧 update dependencies versions ([#89](https://github.com/lyqht/mini-qr/pull/89)) ## v0.11.0 (2025-02-25) - -- 🔧 chore(package.json): update dependencies versions - ([#89](https://github.com/lyqht/mini-qr/pull/89)) +- ✨ add hackomania 2025 qr code preset ([#86](https://github.com/lyqht/mini-qr/pull/86)) +- 🐛 Update ja.json ([#67](https://github.com/lyqht/mini-qr/pull/67)) +- 🔧 Update Crowdin configuration file +- 🔧 Put icon into language selector ([#87](https://github.com/lyqht/mini-qr/pull/87)) ## v0.10.0 (2024-11-01) - -- 🔧 Update Crowdin configuration file - ([#86](https://github.com/lyqht/mini-qr/pull/86)) -- Put icon into language selector - ([#87](https://github.com/lyqht/mini-qr/pull/87)) -- add hackomania 2025 qr code preset - ([#86](https://github.com/lyqht/mini-qr/pull/86)) +- ✨ Add plain preset ([#66](https://github.com/lyqht/mini-qr/pull/66)) +- ✨ Add light/dark mode toggle ## v0.9.3 (2024-10-23) - -- ✨ Add plain preset - ([#66](https://github.com/lyqht/mini-qr/pull/66)) +- ✨ Add contributing guidelines ([#57](https://github.com/lyqht/mini-qr/pull/57)) +- ✨ Create FUNDING.yml +- 🐛 border radius not respected for svg output ([#62](https://github.com/lyqht/mini-qr/pull/62)) +- 🐛 svg output not rendering in image editor softwares ([#54](https://github.com/lyqht/mini-qr/pull/54)) ## v0.9.2 (2024-10-06) - -- ✨ Add contributing guidelines - ([#57](https://github.com/lyqht/mini-qr/pull/57)) -- 🐛 border radius not respected for svg output - ([#62](https://github.com/lyqht/mini-qr/pull/62)) -- 🐛 svg output not rendering in image editor softwares - ([#54](https://github.com/lyqht/mini-qr/pull/54)) +- ✨ Create FUNDING.yml +- 🐛 svg output not rendering in image editor softwares ([#54](https://github.com/lyqht/mini-qr/pull/54)) ## v0.9.1 (2024-10-06) +- 🐛 aria-hidden a11y issue on dnd div -- 🐛 svg output not rendering in image editor softwares - ([#54](https://github.com/lyqht/mini-qr/pull/54)) +## v0.9.0 (2024-10-06) +- 🐛 Update README.md +- 🔧 Batch data export ([#53](https://github.com/lyqht/mini-qr/pull/53)) +- 🔧 bump vite from 5.1.2 to 5.1.7 ([#49](https://github.com/lyqht/mini-qr/pull/49)) +- 🔧 bump braces from 3.0.2 to 3.0.3 ([#48](https://github.com/lyqht/mini-qr/pull/48)) ## v0.8.0 (2024-08-13) - -- 🐛 Update README.md - ([#54](https://github.com/lyqht/mini-qr/pull/54)) -- Batch data export - ([#53](https://github.com/lyqht/mini-qr/pull/53)) -- 🔧 chore(deps): bump vite from 5.1.2 to 5.1.7 - ([#49](https://github.com/lyqht/mini-qr/pull/49)) +- ✨ Add support for error correction levels ([#46](https://github.com/lyqht/mini-qr/pull/46)) ## v0.7.0 (2024-08-08) - -- ✨ Add support for error correction levels - ([#46](https://github.com/lyqht/mini-qr/pull/46)) +- ✨ support transparent background ([#42](https://github.com/lyqht/mini-qr/pull/42)) +- ✨ Added Docker support ([#37](https://github.com/lyqht/mini-qr/pull/37)) +- ✨ add video demo +- 🐛 a11y issues +- 🐛 combobox dark mode ui +- 🔧 translation of locales/en.json ## v0.6.1 (2024-02-16) - -- ✨ support transparent background - ([#42](https://github.com/lyqht/mini-qr/pull/42)) -- ✨ Added Docker support - ([#37](https://github.com/lyqht/mini-qr/pull/37)) -- 🐛 a11y issues - ([#37](https://github.com/lyqht/mini-qr/pull/37)) -- 🔧 translation of locales/en.json - ([#37](https://github.com/lyqht/mini-qr/pull/37)) -- add video demo - ([#37](https://github.com/lyqht/mini-qr/pull/37)) +- ✨ add some hackomania2024 presets ([#31](https://github.com/lyqht/mini-qr/pull/31)) +- 🐛 combobox dark mode ui +- 🐛 dark mode ui ([#36](https://github.com/lyqht/mini-qr/pull/36)) +- 🐛 update dependencies ([#35](https://github.com/lyqht/mini-qr/pull/35)) +- 🐛 styling on mobile viewport ## v0.6.0 (2024-02-13) - -- 🐛 combobox dark mode ui - ([#37](https://github.com/lyqht/mini-qr/pull/37)) -- 🐛 Fix dark mode ui - ([#36](https://github.com/lyqht/mini-qr/pull/36)) -- 🐛 styling on mobile viewport - ([#35](https://github.com/lyqht/mini-qr/pull/35)) -- update dependencies - ([#35](https://github.com/lyqht/mini-qr/pull/35)) +- ✨ Add shadcn-vue combobox components ([#30](https://github.com/lyqht/mini-qr/pull/30)) +- 🔧 update translate github action to only run if PRs are merged +- 🔧 translation of locales/en.json +- 🔧 Rename project and update readme ## v0.5.0 (2024-01-05) - -- ✨ Add shadcn-vue combobox components - ([#30](https://github.com/lyqht/mini-qr/pull/30)) -- 🔧 update translate github action to only run if PRs are merged - ([#30](https://github.com/lyqht/mini-qr/pull/30)) +- ✨ add clarity to project - 🔧 translation of locales/en.json - ([#30](https://github.com/lyqht/mini-qr/pull/30)) +- 🔧 Feature: Save & Load preset from local storage ([#28](https://github.com/lyqht/mini-qr/pull/28)) +- 🔧 Hide copy to clipboard if API is not supported on the browser ([#27](https://github.com/lyqht/mini-qr/pull/27)) ## v0.4.0 (2023-12-31) - -- 🔧 translation of locales/en.json - ([#30](https://github.com/lyqht/mini-qr/pull/30)) -- Feature: Save & Load preset from local storage - ([#28](https://github.com/lyqht/mini-qr/pull/28)) -- Hide copy to clipboard if API is not supported on the browser - ([#27](https://github.com/lyqht/mini-qr/pull/27)) +- ✨ Add SupabasePurple & ViteConf2023 presets ([#19](https://github.com/lyqht/mini-qr/pull/19)) +- 🐛 update Padlet preset image URL ([#23](https://github.com/lyqht/mini-qr/pull/23)) +- 🐛 og image +- 🐛 missing preset typing +- 🔧 Upgraded dependencies ([#25](https://github.com/lyqht/mini-qr/pull/25)) +- 🔧 A11y fixes ([#16](https://github.com/lyqht/mini-qr/pull/16)) ## v0.3.0 (2023-08-07) - -- ✨ Add SupabasePurple & ViteConf2023 presets - ([#19](https://github.com/lyqht/mini-qr/pull/19)) -- 🐛 fix(presets.ts): update Padlet preset image URL - ([#23](https://github.com/lyqht/mini-qr/pull/23)) -- 🐛 og image - ([#19](https://github.com/lyqht/mini-qr/pull/19)) -- 🐛 missing preset typing - ([#16](https://github.com/lyqht/mini-qr/pull/16)) -- Upgraded dependencies - ([#25](https://github.com/lyqht/mini-qr/pull/25)) -- A11y fixes - ([#16](https://github.com/lyqht/mini-qr/pull/16)) +- ✨ add Pejuang Kode Preset ([#12](https://github.com/lyqht/mini-qr/pull/12)) +- ✨ add support for border radius configuration in QR Code generator +- 🐛 update readme and changelog +- 🐛 Update README.md +- 🐛 order of inputs +- 🐛 QR Code Resizing Visually ([#6](https://github.com/lyqht/mini-qr/pull/6)) +- 🔧 translation of locales/en.json +- 🔧 rename keys for i18n +- 🔧 translation of locales/en.json +- 🔧 translation of locales/en.json +- 🔧 Add translation, save/load qr config features and update styles ([#1](https://github.com/lyqht/mini-qr/pull/1)) +- 🔧 V0.3 ([#15](https://github.com/lyqht/mini-qr/pull/15)) +- 🔧 V0.2.0: Add presets feature, eslint/prettier pre-commit husky hook ([#7](https://github.com/lyqht/mini-qr/pull/7)) +- 🔧 V0.1 ([#2](https://github.com/lyqht/mini-qr/pull/2)) ### v0.2.0 (2023-08-06) @@ -166,3 +145,5 @@ - ✨ Add Randomize style button - 🔧 Available in 29 languages (via deepl-translate-github-action) - ✨ Save & Load QR Code config + +*Changelog generated by `scripts/generate-version.sh`* diff --git a/scripts/generate-version.sh b/scripts/generate-version.sh index 3e784c1..bc7f049 100755 --- a/scripts/generate-version.sh +++ b/scripts/generate-version.sh @@ -6,200 +6,182 @@ mkdir -p public # Clear the changelog file before starting > public/CHANGELOG.md -# Get all tags sorted by version number (v prefix is handled) +# Get all tags sorted by version number (newest first) tags=($(git for-each-ref --sort=-version:refname --format '%(refname:short)' refs/tags/v*)) +repo_url="https://github.com/lyqht/mini-qr" # Define repo URL here -# Process each tag +# Process each tag (version) for ((i=0; i<${#tags[@]}; i++)); do - tag="${tags[$i]}" + current_tag="${tags[$i]}" - # Get the range for commits - if [ $i -eq 0 ]; then - range="$tag..HEAD" + # Determine the previous tag or commit hash + if [ $((i + 1)) -lt ${#tags[@]} ]; then + previous_tag="${tags[$i+1]}" else - next_tag="${tags[$i-1]}" - range="$tag..$next_tag" + # For the oldest tag, find its commit hash + oldest_tag_commit=$(git rev-list -n 1 "$current_tag" 2>/dev/null) + # Find the parent commit hash (commit before the tag) + previous_tag=$(git rev-parse "$oldest_tag_commit^" 2>/dev/null) + # If no parent (initial commit), use the hash of the initial commit + if [ -z "$previous_tag" ] || [ $? -ne 0 ]; then + previous_tag=$(git rev-list --max-parents=0 HEAD) + fi fi - - # Add a newline before each version section *except* the very first one - if [ $i -gt 0 ]; then - echo "" >> public/CHANGELOG.md - fi - - # Arrays to store different types of commits + + # Define the range for the current tag's commits: from previous tag/commit up to current tag + range="$previous_tag..$current_tag" + + # Arrays to store different types of commits for this version features=() fixes=() translations=() others=() + + # Get commits in this range (Hash and Subject), ignore merges + commit_data=$(git log --no-merges --pretty=format:"%H %s" "$range") + + # Skip if no commits found for this range + if [ -z "$commit_data" ]; then + continue + fi - # Get commits in this range - while IFS= read -r commit_msg; do - # Skip version bump commits - if [[ $commit_msg =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]]; then + while IFS= read -r line; do + # commit_hash=$(echo "$line" | cut -d' ' -f1) # Hash available if needed + commit_msg=$(echo "$line" | cut -d' ' -f2-) + + # Extract PR number first + pr_num="" + if [[ $commit_msg =~ \ \(#([0-9]+)\)$ ]]; then # Match PR number strictly at the end + pr_num=${BASH_REMATCH[1]} + fi + + # Skip simple version bump commits like "vX.Y.Z" unless they have a PR number + if [[ $commit_msg =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ && -z "$pr_num" ]]; then continue fi # Skip chore, docs, style, refactor commits unless they have a PR number - if [[ $commit_msg =~ ^(chore|docs|style|refactor) && ! $commit_msg =~ \(#[0-9]+\) ]]; then - continue - fi + # Check various forms like chore(...):, chore:, chore + # Use case-insensitive matching for the type prefix + shopt -s nocasematch + should_skip=false + if [[ $commit_msg =~ ^(chore|docs|style|refactor)(\(.*\))?: && -z "$pr_num" ]]; then should_skip=true; fi + if [[ $commit_msg =~ ^(chore|docs|style|refactor)[[:space:]] && -z "$pr_num" ]]; then should_skip=true; fi + shopt -u nocasematch # Turn off case-insensitivity immediately after use + if $should_skip; then continue; fi - # Skip commits that are just version numbers - if [[ $commit_msg =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - continue + # Get message without the PR part like " (#123)" at the end + if [ -n "$pr_num" ]; then + commit_msg_no_pr=$(echo "$commit_msg" | sed -E "s/[[:space:]]*\\(#${pr_num}\\)$//") + else + commit_msg_no_pr=$commit_msg fi - - # Extract PR number if exists - if [[ $commit_msg =~ \(#([0-9]+)\) ]]; then - pr_num=${BASH_REMATCH[1]} - commit_msg=${commit_msg/ (#$pr_num)/} - fi - - # Remove file-specific prefixes like "fix(QRCodeScan.vue):" - # Quote the regex to prevent shell interpretation issues - if [[ $commit_msg =~ '^[a-zA-Z]+\([^)]+\):' ]]; then - commit_msg=${commit_msg#*): } - fi - - # Format the commit message + + # Use commit_msg_no_pr for classification and extracting content + content_msg=$commit_msg_no_pr # Start with the message without PR link formatted_msg="" commit_type="other" - # First try conventional commit format - if [[ $commit_msg =~ ^feat: ]]; then - formatted_msg="- ✨ ${commit_msg#feat: }" - commit_type="feature" - elif [[ $commit_msg =~ ^fix: ]]; then - formatted_msg="- 🐛 ${commit_msg#fix: }" - commit_type="fix" - elif [[ $commit_msg =~ ^perf: ]]; then - formatted_msg="- ⚡️ ${commit_msg#perf: }" - commit_type="other" - elif [[ $commit_msg =~ ^chore: ]]; then - formatted_msg="- 🔧 ${commit_msg#chore: }" - commit_type="other" - elif [[ $commit_msg =~ ^docs: ]]; then - formatted_msg="- 📝 ${commit_msg#docs: }" - commit_type="other" - elif [[ $commit_msg =~ ^style: ]]; then - formatted_msg="- 💄 ${commit_msg#style: }" - commit_type="other" - elif [[ $commit_msg =~ ^refactor: ]]; then - formatted_msg="- ♻️ ${commit_msg#refactor: }" - commit_type="other" - elif [[ $commit_msg =~ ^test: ]]; then - formatted_msg="- ✅ ${commit_msg#test: }" - commit_type="other" - # Then try without colon - elif [[ $commit_msg =~ ^feat ]]; then - formatted_msg="- ✨ ${commit_msg#feat }" - commit_type="feature" - elif [[ $commit_msg =~ ^fix ]]; then - formatted_msg="- 🐛 ${commit_msg#fix }" - commit_type="fix" - elif [[ $commit_msg =~ ^perf ]]; then - formatted_msg="- ⚡️ ${commit_msg#perf }" - commit_type="other" - elif [[ $commit_msg =~ ^chore ]]; then - formatted_msg="- 🔧 ${commit_msg#chore }" - commit_type="other" - elif [[ $commit_msg =~ ^docs ]]; then - formatted_msg="- 📝 ${commit_msg#docs }" - commit_type="other" - elif [[ $commit_msg =~ ^style ]]; then - formatted_msg="- 💄 ${commit_msg#style }" - commit_type="other" - elif [[ $commit_msg =~ ^refactor ]]; then - formatted_msg="- ♻️ ${commit_msg#refactor }" - commit_type="other" - elif [[ $commit_msg =~ ^test ]]; then - formatted_msg="- ✅ ${commit_msg#test }" - commit_type="other" - # Translation detection - elif [[ $commit_msg =~ [Tt]ranslat(e|ion|ions)|locales|i18n|[Cc]rowdin ]]; then - formatted_msg="- 🔧 ${commit_msg}" - commit_type="translation" - # Finally, try to infer type from content + # Try conventional commit format (case insensitive for prefix) + shopt -s nocasematch + if [[ $commit_msg_no_pr =~ ^feat(:|[[:space:]]|(\(.*\):)) ]]; then + content_msg=$(echo "$commit_msg_no_pr" | sed -E 's/^feat(\(.*\))?(:|[[:space:]])[[:space:]]*//I') # Remove prefix/scope + formatted_msg="- ✨ ${content_msg}"; commit_type="feature"; + elif [[ $commit_msg_no_pr =~ ^fix(:|[[:space:]]|(\(.*\):)) ]]; then + content_msg=$(echo "$commit_msg_no_pr" | sed -E 's/^fix(\(.*\))?(:|[[:space:]])[[:space:]]*//I') + formatted_msg="- 🐛 ${content_msg}"; commit_type="fix"; + elif [[ $commit_msg_no_pr =~ ^perf(:|[[:space:]]|(\(.*\):)) ]]; then + content_msg=$(echo "$commit_msg_no_pr" | sed -E 's/^perf(\(.*\))?(:|[[:space:]])[[:space:]]*//I') + formatted_msg="- ⚡️ ${content_msg}"; commit_type="other"; + elif [[ $commit_msg_no_pr =~ ^chore(:|[[:space:]]|(\(.*\):)) ]]; then + content_msg=$(echo "$commit_msg_no_pr" | sed -E 's/^chore(\(.*\))?(:|[[:space:]])[[:space:]]*//I') + formatted_msg="- 🔧 ${content_msg}"; commit_type="other"; + elif [[ $commit_msg_no_pr =~ ^docs(:|[[:space:]]|(\(.*\):)) ]]; then + content_msg=$(echo "$commit_msg_no_pr" | sed -E 's/^docs(\(.*\))?(:|[[:space:]])[[:space:]]*//I') + formatted_msg="- 📝 ${content_msg}"; commit_type="other"; + elif [[ $commit_msg_no_pr =~ ^style(:|[[:space:]]|(\(.*\):)) ]]; then + content_msg=$(echo "$commit_msg_no_pr" | sed -E 's/^style(\(.*\))?(:|[[:space:]])[[:space:]]*//I') + formatted_msg="- 💄 ${content_msg}"; commit_type="other"; + elif [[ $commit_msg_no_pr =~ ^refactor(:|[[:space:]]|(\(.*\):)) ]]; then + content_msg=$(echo "$commit_msg_no_pr" | sed -E 's/^refactor(\(.*\))?(:|[[:space:]])[[:space:]]*//I') + formatted_msg="- ♻️ ${content_msg}"; commit_type="other"; + elif [[ $commit_msg_no_pr =~ ^test(:|[[:space:]]|(\(.*\):)) ]]; then + content_msg=$(echo "$commit_msg_no_pr" | sed -E 's/^test(\(.*\))?(:|[[:space:]])[[:space:]]*//I') + formatted_msg="- ✅ ${content_msg}"; commit_type="other"; + # Translation detection (use the original message part) + elif [[ $commit_msg_no_pr =~ [Tt]ranslat(e|ion|ions)|local(e|es)|i18n|[Cc]rowdin ]]; then + content_msg=$commit_msg_no_pr # Use full message for translation items + formatted_msg="- 🔧 ${content_msg}"; commit_type="translation"; + # Fallback: Infer type from keywords using the original message part else - # Common feature-related words - if [[ $commit_msg =~ ^Add|^Create|^Implement|^Support ]]; then - formatted_msg="- ✨ ${commit_msg}" - commit_type="feature" - # Common fix-related words - elif [[ $commit_msg =~ ^Fix|^Resolve|^Correct|improve|^Update ]]; then - formatted_msg="- 🐛 ${commit_msg}" - commit_type="fix" - # Common translation-related words (fallback) - elif [[ $commit_msg =~ [Tt]ranslat(e|ion|ions)|locales|i18n|[Cc]rowdin ]]; then - formatted_msg="- 🔧 ${commit_msg}" - commit_type="translation" - # Common refactor-related words - elif [[ $commit_msg =~ ^Refactor|^Restructure|^Reorganize ]]; then - formatted_msg="- ♻️ ${commit_msg}" - commit_type="other" - # Common docs-related words - elif [[ $commit_msg =~ ^Document|^Update.*docs|^Add.*docs ]]; then - formatted_msg="- 📝 ${commit_msg}" - commit_type="other" - else - formatted_msg="- ${commit_msg}" - commit_type="other" + content_msg=$commit_msg_no_pr # Ensure content_msg is set for fallbacks + if [[ $commit_msg_no_pr =~ ^Add|^Create|^Implement|^Support ]]; then formatted_msg="- ✨ ${content_msg}"; commit_type="feature"; + elif [[ $commit_msg_no_pr =~ ^Fix|^Resolve|^Correct|improve|^Update ]]; then formatted_msg="- 🐛 ${content_msg}"; commit_type="fix"; + else formatted_msg="- 🔧 ${content_msg}"; commit_type="other"; # Default to wrench emoji fi fi + shopt -u nocasematch # Turn off case-insensitivity - # Add PR link if exists - if [ -n "$pr_num" ]; then - formatted_msg="$formatted_msg\n ([#$pr_num](https://github.com/lyqht/mini-qr/pull/$pr_num))" + # Trim leading/trailing whitespace from content_msg which might be left by sed + # Note: The actual message used in formatted_msg might differ slightly depending on the block above + # For consistency, we perhaps should trim formatted_msg *after* the PR link is added, or ensure content_msg is used consistently + # For now, let's assume the main issue was the rebuild block below and remove it. + + # Ensure content_msg is not empty after potential prefix removal and trimming + # We should check formatted_msg after construction instead, or the base content used. + # Let's refine this check slightly + check_content=${formatted_msg#-* } # Remove prefix like "- ✨ " to check actual message + if [[ -z "$check_content" ]]; then + # If message part is empty after processing, skip + # echo "Warning: Skipping commit with empty message part: $commit_msg" >&2 + continue fi - - # Add to appropriate array - if [ "$commit_type" = "feature" ]; then - features+=("$formatted_msg") - elif [ "$commit_type" = "fix" ]; then - fixes+=("$formatted_msg") - elif [ "$commit_type" = "translation" ]; then - translations+=("$formatted_msg") - else - others+=("$formatted_msg") - fi - - done < <(git log --pretty=format:"%s" "$range") - - # Only add version section if there are any commits - if [ ${#features[@]} -gt 0 ] || [ ${#fixes[@]} -gt 0 ] || [ ${#translations[@]} -gt 0 ] || [ ${#others[@]} -gt 0 ]; then - # Get the date of the tag - tag_date=$(git log -1 --format=%ai "$tag" | cut -d' ' -f1) - # Write the tag and date - echo "## $tag ($tag_date)" >> public/CHANGELOG.md - echo "" >> public/CHANGELOG.md + # Add PR link back if pr_num was found + if [ -n "$pr_num" ]; then + pr_link="([#$pr_num]($repo_url/pull/$pr_num))" + # Append PR link to the formatted_msg + formatted_msg="$formatted_msg $pr_link" + fi - # Write features first - for msg in "${features[@]}"; do - echo -e "$msg" >> public/CHANGELOG.md - done + # Add to appropriate array based on commit_type + if [ "$commit_type" = "feature" ]; then features+=("$formatted_msg"); + elif [ "$commit_type" = "fix" ]; then fixes+=("$formatted_msg"); + elif [ "$commit_type" = "translation" ]; then translations+=("$formatted_msg"); + else others+=("$formatted_msg"); + fi - # Write fixes second - for msg in "${fixes[@]}"; do - echo -e "$msg" >> public/CHANGELOG.md - done + done < <(echo "$commit_data") # Read from the variable containing log output - # Write translations third - for msg in "${translations[@]}"; do - echo -e "$msg" >> public/CHANGELOG.md - done - # Write others last - for msg in "${others[@]}"; do - echo -e "$msg" >> public/CHANGELOG.md - done + # Only add version section if there are any categorized commits for this version + if [ ${#features[@]} -gt 0 ] || [ ${#fixes[@]} -gt 0 ] || [ ${#translations[@]} -gt 0 ] || [ ${#others[@]} -gt 0 ]; then + # Get the date of the current_tag + tag_date=$(git log -1 --format=%ai "$current_tag" | cut -d' ' -f1) + + # Write the current_tag and date header + echo "## $current_tag ($tag_date)" >> public/CHANGELOG.md - echo "" >> public/CHANGELOG.md + # Write features, fixes, translations, others in order + for msg in "${features[@]}"; do echo -e "$msg" >> public/CHANGELOG.md; done + for msg in "${fixes[@]}"; do echo -e "$msg" >> public/CHANGELOG.md; done + for msg in "${translations[@]}"; do echo -e "$msg" >> public/CHANGELOG.md; done + for msg in "${others[@]}"; do echo -e "$msg" >> public/CHANGELOG.md; done + + # Add a newline after each version block for better spacing + echo "" >> public/CHANGELOG.md fi + + # Stop processing if we reach the point where history is manually maintained + # Adjust this tag if the manual section changes + if [ "$current_tag" == "v0.3.0" ]; then + # echo "Reached v0.3.0, stopping git log processing." # Debugging/Info + break # Exit the loop + fi + done -# Directly append the hardcoded historical changelog entries -echo "" >> public/CHANGELOG.md # Add a separator line +# Append the hardcoded historical changelog entries for v0.2.0 and older echo "### v0.2.0 (2023-08-06)" >> public/CHANGELOG.md echo "" >> public/CHANGELOG.md echo "- ✨ Add Presets: Pre-crafted QR code styles available (padletPreset, uiliciousPreset, supabasePreset, vercelLightPreset, vercelDarkPreset)" >> public/CHANGELOG.md @@ -222,4 +204,10 @@ echo "- ✨ Add Copy to clipboard feature" >> public/CHANGELOG.md echo "- ✨ UI respects light/dark mode preferences" >> public/CHANGELOG.md echo "- ✨ Add Randomize style button" >> public/CHANGELOG.md echo "- 🔧 Available in 29 languages (via deepl-translate-github-action)" >> public/CHANGELOG.md -echo "- ✨ Save & Load QR Code config" >> public/CHANGELOG.md \ No newline at end of file +echo "- ✨ Save & Load QR Code config" >> public/CHANGELOG.md + +# Add footer +echo "" >> public/CHANGELOG.md +echo "*Changelog generated by \`scripts/generate-version.sh\`*" >> public/CHANGELOG.md + +echo "Changelog generated successfully in public/CHANGELOG.md" \ No newline at end of file