Skip to content

Instantly share code, notes, and snippets.

@JBlond
Created January 26, 2021 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JBlond/9870f84062f8c1f40c0f8d18439b005f to your computer and use it in GitHub Desktop.
Save JBlond/9870f84062f8c1f40c0f8d18439b005f to your computer and use it in GitHub Desktop.
generate Changelog
<?php
$output = "# changelog\n\n";
$previousTag = 0;
$gitTags = shell_exec("git tag --sort=-creatordate");
$gitTagsArray = explode("\n", $gitTags);
foreach ($gitTagsArray as $gitTag) {
if ($previousTag !== 0 && $gitTag !== '') {
$tagDate = shell_exec("git log -1 --pretty=format:'%ad' --date=short $previousTag");
$output .= "## $previousTag ($tagDate)\n\n";
$cmd = 'git log ' .
$gitTag . '...' .
$previousTag .
' --no-merges --pretty=format:"* %s" --reverse';
$logLine = shell_exec($cmd);
$logLine = preg_replace('/(?m)(.*)(\R?\n\1)+$/', '$1', $logLine);
$output .= $logLine . "\n";
}
$previousTag = $gitTag;
$output .= "\n\n";
}
file_put_contents('changelog.md', $output);
@nono303
Copy link

nono303 commented Apr 6, 2022

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment