| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
$catgroup = [ |
| 7 |
'💣 Breaking Changes' => [], |
| 8 |
'✨ New Features' => [], |
| 9 |
'🐞 Bug Fixes' => [], |
| 10 |
'🚀 Performance Improvements' => [], |
| 11 |
'♻️ Refactoring' => [], |
| 12 |
'🚨 Testing' => [], |
| 13 |
'📚 Documentation' => [], |
| 14 |
'💎 Style Changes' => [], |
| 15 |
'🔧 Chore' => [], |
| 16 |
'📜 Miscellaneous Changes' => [] |
| 17 |
]; |
| 18 |
|
| 19 |
|
| 20 |
$categories = [ |
| 21 |
'break' => '💣 Breaking Changes', |
| 22 |
'breaking' => '💣 Breaking Changes', |
| 23 |
'feat' => '✨ New Features', |
| 24 |
'feature' => '✨ New Features', |
| 25 |
'add' => '✨ New Features', |
| 26 |
'added' => '✨ New Features', |
| 27 |
'fix' => '🐞 Bug Fixes', |
| 28 |
'bug' => '🐞 Bug Fixes', |
| 29 |
'bugfix' => '🐞 Bug Fixes', |
| 30 |
'fixed' => '🐞 Bug Fixes', |
| 31 |
'fixes' => '🐞 Bug Fixes', |
| 32 |
'perf' => '🚀 Performance Improvements', |
| 33 |
'performance' => '🚀 Performance Improvements', |
| 34 |
'impro' => '♻️ Refactoring', |
| 35 |
'improved' => '♻️ Refactoring', |
| 36 |
'improvement' => '♻️ Refactoring', |
| 37 |
'refactor' => '♻️ Refactoring', |
| 38 |
'refactored' => '♻️ Refactoring', |
| 39 |
'refactoring' => '♻️ Refactoring', |
| 40 |
'deprecated' => '♻️ Refactoring', |
| 41 |
'deprecate' => '♻️ Refactoring', |
| 42 |
'remove' => '♻️ Refactoring', |
| 43 |
'change' => '♻️ Refactoring', |
| 44 |
'changed' => '♻️ Refactoring', |
| 45 |
'test' => '🚨 Testing', |
| 46 |
'tests' => '🚨 Testing', |
| 47 |
'testing' => '🚨 Testing', |
| 48 |
'ci' => '👷 Build/CI', |
| 49 |
'build' => '👷 Build/CI', |
| 50 |
'docs' => '📚 Documentation', |
| 51 |
'documentation' => '📚 Documentation', |
| 52 |
'style' => '💎 Style Changes', |
| 53 |
'chore' => '🔧 Chore', |
| 54 |
'misc' => '📜 Miscellaneous Changes', |
| 55 |
'update' => '📜 Miscellaneous Changes', |
| 56 |
'updated' => '📜 Miscellaneous Changes', |
| 57 |
]; |
| 58 |
|
| 59 |
$changelog = []; |
| 60 |
$githubstyle = true; |
| 61 |
if (count($argv) > 2 && $argv[1] == '--discord') { |
| 62 |
$githubstyle = false; |
| 63 |
} |
| 64 |
$errors = []; |
| 65 |
|
| 66 |
|
| 67 |
exec("git log --oneline --format=\"%s\" $(git log --no-walk --tags | head -n1 | cut -d ' ' -f 2)..HEAD | grep -v '^Merge '", $changelog); |
| 68 |
|
| 69 |
|
| 70 |
$changelog = array_intersect_key($changelog, array_unique(array_map("strtolower", $changelog))); |
| 71 |
|
| 72 |
|
| 73 |
foreach ($changelog as $item) { |
| 74 |
$entryWithoutPrLink = preg_replace('/( \(#\d+\))$/', '', $item); |
| 75 |
if ($entryWithoutPrLink === $item) { |
| 76 |
continue; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
foreach ($changelog as $key => $change) { |
| 81 |
if ($entryWithoutPrLink === $change) { |
| 82 |
unset($changelog[$key]); |
| 83 |
break; |
| 84 |
} |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
function add_change(string $change, string $category, string $scope = null) { |
| 89 |
global $catgroup; |
| 90 |
|
| 91 |
if (isset($scope) && !empty($scope)) { |
| 92 |
|
| 93 |
if (!isset($catgroup[$category][$scope])) { |
| 94 |
$catgroup[$category][$scope] = []; |
| 95 |
} |
| 96 |
$catgroup[$category][$scope][] = $change; |
| 97 |
return; |
| 98 |
} |
| 99 |
$catgroup[$category][] = $change; |
| 100 |
} |
| 101 |
|
| 102 |
foreach ($changelog as $change) { |
| 103 |
|
| 104 |
|
| 105 |
$change = preg_replace('/([a-zA-Z][\w_\/\-]+\.\w+|\S+\(\)|\w+::\w+|dpp::\w+|utility::\w+|(\w+_\w+)+)/', '`$1`', $change); |
| 106 |
$change = preg_replace("/vs(\d+)/", "Visual Studio $1", $change); |
| 107 |
$change = preg_replace("/\bfaq\b/", "FAQ", $change); |
| 108 |
$change = preg_replace("/\bdiscord\b/", "Discord", $change); |
| 109 |
$change = preg_replace("/\bmicrosoft\b/", "Microsoft", $change); |
| 110 |
$change = preg_replace("/\bwindows\b/", "Windows", $change); |
| 111 |
$change = preg_replace("/\blinux\b/", "Linux", $change); |
| 112 |
$change = preg_replace("/\sarm(\d+)\s/i", ' ARM$1 ', $change); |
| 113 |
$change = preg_replace("/\b(was|is|wo)nt\b/i", '$1n\'t', $change); |
| 114 |
$change = preg_replace("/\bfreebsd\b/", 'FreeBSD', $change); |
| 115 |
$change = preg_replace("/``/", "`", $change); |
| 116 |
$change = trim($change); |
| 117 |
|
| 118 |
$matched = false; |
| 119 |
$matches = []; |
| 120 |
|
| 121 |
if (preg_match("/^((?:(?:[\w_]+(?:\([\w_]+\))?+)(?:[\s]*[,\/][\s]*)?)+):/i", $change, $matches) || preg_match("/^\[((?:(?:[\w_]+(?:\([\w_]+\))?+)(?:[\s]*[,\/][\s]*)?)+)\](?:\s*:)?/i", $change, $matches)) { |
| 122 |
$categorysection = $matches[0]; |
| 123 |
$changecategories = $matches[1]; |
| 124 |
$matchflags = PREG_SET_ORDER | PREG_UNMATCHED_AS_NULL; |
| 125 |
|
| 126 |
if (preg_match_all("/(?:[\s]*)([\w_]+)(?:\(([\w_]+)\))?(?:[\s]*)(?:[,\/]+)?/i", $changecategories, $matches, $matchflags) !== false) { |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
$header = $matches[0][1]; |
| 136 |
$scope = $matches[0][2]; |
| 137 |
$change = trim(substr($change, strlen($categorysection))); |
| 138 |
|
| 139 |
foreach ($matches as $nb => $match) { |
| 140 |
if ($nb == 0) |
| 141 |
continue; |
| 142 |
$category = $match[1]; |
| 143 |
if (isset($categories[$category]) && $categories[$category] === '💣 Breaking Changes') |
| 144 |
add_change($change, $categories[$category], $scope); |
| 145 |
} |
| 146 |
if (!isset($categories[$header])) { |
| 147 |
$errors[] = "could not find category \"" . $header . "\" for commit \"" . $change . "\", adding it to misc"; |
| 148 |
$header = $categories['misc']; |
| 149 |
} |
| 150 |
else { |
| 151 |
$header = $categories[$header]; |
| 152 |
} |
| 153 |
if (!isset($catgroup[$header])) { |
| 154 |
$catgroup[$header] = []; |
| 155 |
} |
| 156 |
$matched = true; |
| 157 |
|
| 158 |
if (!preg_match("/^(version )?bump/i", $change)) { |
| 159 |
add_change($change, $header, $scope); |
| 160 |
} |
| 161 |
} |
| 162 |
} |
| 163 |
if (!$matched) { |
| 164 |
|
| 165 |
foreach ($categories as $cat => $header) { |
| 166 |
|
| 167 |
if (strpos($change, ' ') === false || preg_match("/^Merge (branch|pull request|remote-tracking branch) /", $change) || preg_match("/^(version )?bump/i", $change)) { |
| 168 |
$matched = true; |
| 169 |
break; |
| 170 |
} |
| 171 |
if (preg_match("/^" . $cat . " /i", $change)) { |
| 172 |
if (!isset($catgroup[$header])) { |
| 173 |
$catgroup[$header] = []; |
| 174 |
} |
| 175 |
$matched = true; |
| 176 |
$catgroup[$header][] = $change; |
| 177 |
break; |
| 178 |
} |
| 179 |
} |
| 180 |
} |
| 181 |
if (!$matched) { |
| 182 |
$errors[] = "could not guess category for commit \"" . $change . "\", adding it to misc"; |
| 183 |
$header = $categories['misc']; |
| 184 |
if (!isset($catgroup[$header])) { |
| 185 |
$catgroup[$header] = []; |
| 186 |
} |
| 187 |
$matched = true; |
| 188 |
$catgroup[$header][] = $change; |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
if ($githubstyle) { |
| 194 |
echo "The changelog is listed below:\n\nRelease Changelog\n===========\n"; |
| 195 |
} else { |
| 196 |
echo "The changelog is listed below:\n\n## Release Changelog\n"; |
| 197 |
} |
| 198 |
|
| 199 |
function print_change(string $change) { |
| 200 |
global $githubstyle; |
| 201 |
|
| 202 |
|
| 203 |
if (!preg_match("/^(typo|test|fix)\s\w+$/", $change) && strpos($change, ' ') !== false) { |
| 204 |
echo ($githubstyle ? '-' : '•') . ' ' . ucfirst(str_replace('@', '', $change)) . "\n"; |
| 205 |
} |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
foreach ($catgroup as $cat => $list) { |
| 210 |
if (!empty($list)) { |
| 211 |
echo "\n" . ($githubstyle ? '## ' : '### ') . $cat . "\n"; |
| 212 |
foreach ($list as $key => $item) { |
| 213 |
if (is_array($item)) { |
| 214 |
foreach ($item as $change) { |
| 215 |
print_change("$key: $change"); |
| 216 |
} |
| 217 |
} |
| 218 |
else { |
| 219 |
print_change($item); |
| 220 |
} |
| 221 |
} |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
echo "\n\n**Thank you for using D++!**\n\n"; |
| 227 |
if (!$githubstyle) { |
| 228 |
$version = $argv[2]; |
| 229 |
echo 'The ' . $version . ' download can be found here: <https://dl.dpp.dev/' . $version . '>'; |
| 230 |
echo "\n"; |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|