Last active
August 4, 2023 15:38
-
-
Save nbarnwell/f1a97205f4c34d839899e87100afcc9f to your computer and use it in GitHub Desktop.
Simple PowerShell script to create the appropriate next tag on a git repo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-Version { | |
# TODO: Implement a call to GitVersion on the command line to find the current version from the repo | |
} | |
function New-Tag { | |
[CmdletBinding(SupportsShouldProcess=$true)] | |
param( | |
[Parameter(Mandatory=$true)] | |
[string] $Tag) | |
process { | |
if ($PSCmdlet.ShouldProcess("git tag $Tag")) { | |
Write-Verbose "git tag $Tag" | |
git tag $Tag | |
} | |
} | |
} | |
function New-SemverTag { | |
[CmdletBinding(SupportsShouldProcess = $true)] | |
param( | |
[Parameter(ParameterSetName = "BreakingChange")] | |
[switch] $BreakingChange = $false, | |
[Parameter(ParameterSetName = "NewFeature")] | |
[switch] $NewFeature = $false, | |
[Parameter(ParameterSetName = "BugFix")] | |
[switch] $BugFix = $false) | |
$v = Get-Version | |
[int] $Major = $v.Major; | |
[int] $Minor = $v.Minor; | |
[int] $Build = $v.Build; | |
$oldTag = 'v{0}.{1}.{2}' -f $Major, $Minor, $Build | |
if ($BreakingChange) { | |
$Major += 1; | |
$Minor = 0; | |
$Build = 0; | |
} | |
if ($NewFeature) { | |
$Minor += 1; | |
$Build = 0; | |
} | |
if ($BugFix) { | |
$Build += 1; | |
} | |
$newTag = 'v{0}.{1}.{2}' -f $Major, $Minor, $Build | |
$message = "Moving from $oldTag to $newTag" | |
if ($PsCmdlet.ShouldProcess($message)) { | |
Write-Host $message | |
New-Tag $newTag | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment