|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +RELEASE_VERSION="$1" |
| 4 | + |
| 5 | +# Delete until and including the first line containing "<!-- Release notes generated" |
| 6 | +sed -i '1,/^<!-- Release notes generated/d' temp_change.md |
| 7 | + |
| 8 | +# Check if there is more than one non-empty line (the full changelog line) before we continue |
| 9 | +if [ $(grep -c '^[[:space:]]*[^[:space:]]' temp_change.md) -le 1 ]; then |
| 10 | + echo "No changes to release $RELEASE_VERSION" |
| 11 | + rm temp_change.md |
| 12 | + exit 1 |
| 13 | +fi |
| 14 | + |
| 15 | +# Remove all CR characters from all changelog files |
| 16 | +sed -i 's/\r//g' temp_change.md CHANGELOG.md changelog.txt |
| 17 | + |
| 18 | +# Reverse the order of lines in the file (last line becomes first, etc.) |
| 19 | +sed -i '1h;1d;$!H;$!d;G' temp_change.md |
| 20 | +# Convert "**Full Changelog**: URL" format to markdown link format "[Full Changelog](URL)" |
| 21 | +sed -i -re 's/\*\*Full Changelog\*\*: (.*)/\[Full Changelog\]\(\1\)\n/' temp_change.md |
| 22 | +# Delete everything from "## New Contributors" line to the end of file |
| 23 | +sed -i '/## New Contributors/,$d' temp_change.md |
| 24 | +# Convert GitHub changelog entries to markdown format |
| 25 | +# "* description by (@username1, @username2) in #1310, #1311" → "- description #1310, #1311 (@username1, @username2)" |
| 26 | +sed -i -re 's/^\*\s(.*)\sby\s\(?(@[^)]*[^) ])\)?\s+in\s+(.*)/- \1 \3 (\2)/' temp_change.md |
| 27 | +# Convert @usernames to github links |
| 28 | +# "(@username1, @username2)" → "([username1](https://github.com/username1), [username2](https://github.com/username2))" |
| 29 | +sed -i -re 's/@([a-zA-Z0-9_-]+)/[\1](https:\/\/github.com\/\1)/g' temp_change.md |
| 30 | +# Convert full PR URLs to linked format |
| 31 | +# "https://github.com/repo/pull/1310" → "[\#1310](https://github.com/repo/pull/1310)" |
| 32 | +sed -i -re 's/(https:\/\/[^) ]*\/pull\/([0-9]+))/[\\#\2](\1)/g' temp_change.md |
| 33 | + |
| 34 | +# Username substitutions for preferred display names |
| 35 | +sed -i 's/\[Quotae/\[Quote_a/' temp_change.md |
| 36 | +sed -i 's/\[learn2draw/\[Lexy/' temp_change.md |
| 37 | +sed -i 's/\[Voronoff/\[Tom Clancy Is Dead/' temp_change.md |
| 38 | +sed -i 's/\[PJacek/\[TPlant/' temp_change.md |
| 39 | +sed -i 's/\[justjuangui/\[trompetin17/' temp_change.md |
| 40 | + |
| 41 | +cp temp_change.md changelog_temp.txt |
| 42 | +# Append existing CHANGELOG.md content (excluding first line) to temp_change.md |
| 43 | +cat CHANGELOG.md | sed '1d' >> temp_change.md |
| 44 | +# Create new CHANGELOG.md with header containing version and date, followed by processed changes |
| 45 | +printf "# Changelog\n\n## [$RELEASE_VERSION](https://github.com/PathOfBuildingCommunity/PathOfBuilding-PoE2/tree/$RELEASE_VERSION) ($(date +'%Y/%m/%d'))\n\n" | cat - temp_change.md > CHANGELOG.md |
| 46 | +# Convert changelog entries from markdown link format to simplified "* description (username)" format |
| 47 | +# First remove all PR links |
| 48 | +sed -i -re 's/( \()?\[\\#[0-9]+\]\([^)]*\),? ?\)?//g' changelog_temp.txt |
| 49 | +# Remove markdown link formatting from usernames in parentheses |
| 50 | +sed -i -re 's/\[([^]]*)\]\(https:\/\/github\.com\/[^)]*\)/\1/g' changelog_temp.txt |
| 51 | +# Create new changelog format: add version header, remove lines 2-3, format section headers, remove ## headers with following line, prepend to existing changelog |
| 52 | +echo "VERSION[${RELEASE_VERSION#v}][$(date +'%Y/%m/%d')]" | cat - changelog_temp.txt | sed '2,3d' | sed -re 's/^### (.*)/\n--- \1 ---/' | sed -e '/^##.*/,+1 d' | cat - changelog.txt > changelog_new.txt |
| 53 | +mv changelog_new.txt changelog.txt |
| 54 | + |
| 55 | +# Normalize line endings to CRLF for all output files to ensure consistent checksums with Windows |
| 56 | +sed -i 's/\r*$/\r/' CHANGELOG.md changelog.txt |
| 57 | + |
| 58 | +# Clean up temporary files |
| 59 | +rm temp_change.md |
| 60 | +rm changelog_temp.txt |
0 commit comments