PowerShell/Scripts/write-changelog.ps1

117 lines
3.5 KiB
PowerShell
Raw Normal View History

2023-09-26 20:55:15 +02:00
<#
2023-09-26 20:41:20 +02:00
.SYNOPSIS
Writes a changelog
.DESCRIPTION
2023-09-27 11:19:03 +02:00
This PowerShell script writes an automated changelog to the console in Markdown format by using the Git commits.
NOTE: You may also redirect the output into a file for later use.
2023-09-26 20:41:20 +02:00
.EXAMPLE
PS> ./write-changelog.ps1
2023-09-27 11:19:03 +02:00
Changelog of PowerShell
=======================
2023-09-26 20:41:20 +02:00
...
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
2023-09-26 20:55:15 +02:00
param([string]$RepoDir = "$PWD")
2023-09-26 20:41:20 +02:00
try {
2023-09-27 11:19:03 +02:00
[system.threading.thread]::currentthread.currentculture = [system.globalization.cultureinfo]"en-US"
2023-09-26 20:41:20 +02:00
2023-09-27 11:19:03 +02:00
Write-Progress "⏳ (1/6) Searching for Git executable..."
2023-09-26 20:55:15 +02:00
$null = (git --version)
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
2023-09-27 11:19:03 +02:00
Write-Progress "⏳ (2/6) Checking local repository..."
2023-09-26 20:55:15 +02:00
if (!(Test-Path "$RepoDir" -pathType container)) { throw "Can't access folder: $RepoDir" }
2023-09-27 11:19:03 +02:00
$RepoDirName = (Get-Item "$RepoDir").Name
2023-09-26 20:55:15 +02:00
2023-09-27 11:19:03 +02:00
Write-Progress "⏳ (3/6) Fetching the latest commits..."
2023-09-26 20:55:15 +02:00
& git -C "$RepoDir" fetch --all --force --quiet
if ($lastExitCode -ne "0") { throw "'git fetch --all' failed with exit code $lastExitCode" }
2023-09-26 20:41:20 +02:00
2023-09-27 11:19:03 +02:00
Write-Progress "⏳ (4/6) Listing all Git commit messages..."
$commits = (git -C "$RepoDir" log --boundary --pretty=oneline --pretty=format:%s | sort -u)
2023-09-26 20:55:15 +02:00
2023-09-27 11:19:03 +02:00
Write-Progress "⏳ (5/6) Sorting the Git commit messages..."
2023-09-26 20:41:20 +02:00
$features = @()
$fixes = @()
$updates = @()
2023-09-27 11:19:03 +02:00
$various = @()
2023-09-26 20:41:20 +02:00
foreach($commit in $commits) {
if ($commit -like "New*") {
$features += $commit
} elseif ($commit -like "Add*") {
$features += $commit
} elseif ($commit -like "Create*") {
$features += $commit
} elseif ($commit -like "Fix*") {
$fixes += $commit
} elseif ($commit -like "Hotfix*") {
$fixes += $commit
2023-09-27 11:19:03 +02:00
} elseif ($commit -like "Bugfix*") {
$fixes += $commit
2023-09-26 20:41:20 +02:00
} elseif ($commit -like "Update*") {
$updates += $commit
2023-09-27 11:19:03 +02:00
} elseif ($commit -like "Updating*") {
$updates += $commit
2023-09-26 20:41:20 +02:00
} elseif ($commit -like "Updaate*") {
$updates += $commit
2023-09-27 11:19:03 +02:00
} elseif ($commit -like "Adapt*") {
$updates += $commit
2023-09-26 20:41:20 +02:00
} elseif ($commit -like "Improve*") {
$updates += $commit
} elseif ($commit -like "Change*") {
$updates += $commit
2023-09-27 11:19:03 +02:00
} elseif ($commit -like "Changing*") {
$updates += $commit
2023-09-26 20:41:20 +02:00
} else {
2023-09-27 11:19:03 +02:00
$various += $commit
2023-09-26 20:41:20 +02:00
}
}
2023-09-27 11:19:03 +02:00
Write-Progress "⏳ (6/6) Listing all contributors..."
$contributors = (git -C "$RepoDir" log --format='%aN' | sort -u)
2023-09-26 20:55:15 +02:00
Write-Progress -completed " "
2023-09-27 11:19:03 +02:00
$Today = (Get-Date).ToShortDateString()
2023-09-26 20:41:20 +02:00
Write-Output " "
2023-09-27 11:19:03 +02:00
Write-Output "Changelog of $RepoDirName as of $Today"
Write-Output "======================================"
Write-Output " "
Write-Output "🚀 New Features"
2023-09-26 20:41:20 +02:00
Write-Output "---------------"
foreach($c in $features) {
2023-09-27 11:19:03 +02:00
Write-Output "* $c"
2023-09-26 20:41:20 +02:00
}
Write-Output " "
2023-09-27 11:19:03 +02:00
Write-Output "⚠️ Bug Fixes"
Write-Output "------------"
2023-09-26 20:41:20 +02:00
foreach($c in $fixes) {
2023-09-27 11:19:03 +02:00
Write-Output "* $c"
2023-09-26 20:41:20 +02:00
}
Write-Output " "
2023-09-27 11:19:03 +02:00
Write-Output "🎉 Updates"
2023-09-26 20:41:20 +02:00
Write-Output "----------"
foreach($c in $updates) {
2023-09-27 11:19:03 +02:00
Write-Output "* $c"
2023-09-26 20:41:20 +02:00
}
Write-Output " "
2023-09-27 11:19:03 +02:00
Write-Output "🔦 Various"
Write-Output "----------"
foreach($c in $various) {
Write-Output "* $c"
}
Write-Output " "
Write-Output "🥇 Contributors"
Write-Output "---------------"
foreach($c in $contributors) {
Write-Output "* $c"
2023-09-26 20:41:20 +02:00
}
exit 0 # success
} catch {
Write-Error $_.Exception.ToString()
exit 1
}