PowerShell/docs/write-changelog.md

159 lines
4.8 KiB
Markdown
Raw Normal View History

2024-11-08 12:38:20 +01:00
The *write-changelog.ps1* Script
===========================
2023-10-19 08:12:00 +02:00
This PowerShell script writes an automated changelog in Markdown format to the console by using the Git commits only.
NOTE: For proper sorting the Git commits should start with verbs such as 'Add', 'Fix', 'Update', etc. You may also redirect the output into a file for later use.
Parameters
----------
```powershell
2024-11-08 12:35:11 +01:00
/home/markus/Repos/PowerShell/scripts/write-changelog.ps1 [[-RepoDir] <String>] [<CommonParameters>]
2023-10-19 08:12:00 +02:00
-RepoDir <String>
Specifies the path to the local Git repository (default is current working dir)
Required? false
Position? 1
Default value "$PWD"
Accept pipeline input? false
Accept wildcard characters? false
[<CommonParameters>]
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
```
Example
-------
```powershell
PS> ./write-changelog.ps1
Changelog of PowerShell
=======================
...
```
Notes
-----
Author: Markus Fleschutz | License: CC0
Related Links
-------------
https://github.com/fleschutz/PowerShell
Script Content
--------------
```powershell
<#
.SYNOPSIS
Writes a changelog from Git commits
.DESCRIPTION
This PowerShell script writes an automated changelog in Markdown format to the console by using the Git commits only.
NOTE: For proper sorting the Git commits should start with verbs such as 'Add', 'Fix', 'Update', etc. You may also redirect the output into a file for later use.
.PARAMETER RepoDir
Specifies the path to the local Git repository (default is current working dir)
.EXAMPLE
PS> ./write-changelog.ps1
Changelog of PowerShell
=======================
...
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
param([string]$RepoDir = "$PWD")
try {
[system.threading.thread]::currentthread.currentculture = [system.globalization.cultureinfo]"en-US"
2023-12-07 20:24:45 +01:00
Write-Progress "(1/6) Searching for Git executable..."
2023-10-19 08:12:00 +02:00
$null = (git --version)
if ($lastExitCode -ne "0") { throw "Can't execute 'git' - make sure Git is installed and available" }
2023-12-07 20:24:45 +01:00
Write-Progress "(2/6) Checking local repository..."
2023-10-19 08:12:00 +02:00
if (!(Test-Path "$RepoDir" -pathType container)) { throw "Can't access folder: $RepoDir" }
$RepoDirName = (Get-Item "$RepoDir").Name
2023-12-07 20:24:45 +01:00
Write-Progress "(3/6) Fetching the latest commits..."
2023-10-19 08:12:00 +02:00
& git -C "$RepoDir" fetch --all --force --quiet
if ($lastExitCode -ne "0") { throw "'git fetch --all' failed with exit code $lastExitCode" }
2023-12-07 20:24:45 +01:00
Write-Progress "(4/6) Listing all Git commit messages..."
2023-10-19 08:12:00 +02:00
$commits = (git -C "$RepoDir" log --boundary --pretty=oneline --pretty=format:%s | sort -u)
2023-12-07 20:24:45 +01:00
Write-Progress "(5/6) Sorting the Git commit messages..."
2023-10-19 08:12:00 +02:00
$new = @()
$fixes = @()
$updates = @()
$various = @()
foreach($commit in $commits) {
if ($commit -like "New*") { $new += $commit
} elseif ($commit -like "Add*") { $new += $commit
} elseif ($commit -like "Create*") { $new += $commit
} elseif ($commit -like "Fix*") { $fixes += $commit
} elseif ($commit -like "Hotfix*") { $fixes += $commit
} elseif ($commit -like "Bugfix*") { $fixes += $commit
} elseif ($commit -like "Update*") { $updates += $commit
} elseif ($commit -like "Updating*") { $updates += $commit
} elseif ($commit -like "Updaate*") { $updates += $commit
} elseif ($commit -like "Adapt*") { $updates += $commit
} elseif ($commit -like "Improve*") { $updates += $commit
} elseif ($commit -like "Change*") { $updates += $commit
} elseif ($commit -like "Changing*") { $updates += $commit
} else {
$various += $commit
}
}
2023-12-07 20:24:45 +01:00
Write-Progress "(6/6) Listing all contributors..."
2023-10-19 08:12:00 +02:00
$contributors = (git -C "$RepoDir" log --format='%aN' | sort -u)
Write-Progress -completed " "
$Today = (Get-Date).ToShortDateString()
Write-Output " "
Write-Output "Changelog of $RepoDirName as of $Today"
Write-Output "======================================"
Write-Output " "
Write-Output "🚀 New Features"
Write-Output "---------------"
foreach($c in $new) {
Write-Output "* $c"
}
Write-Output " "
Write-Output "⚠️ Bug Fixes"
Write-Output "------------"
foreach($c in $fixes) {
Write-Output "* $c"
}
Write-Output " "
Write-Output "🎉 Updates"
Write-Output "----------"
foreach($c in $updates) {
Write-Output "* $c"
}
Write-Output " "
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"
}
exit 0 # success
} catch {
Write-Error $_.Exception.ToString()
exit 1
}
```
2024-11-08 12:38:20 +01:00
*(generated by convert-ps2md.ps1 using the comment-based help of write-changelog.ps1 as of 11/08/2024 12:37:57)*