Skip to content

Instantly share code, notes, and snippets.

@nbarnwell
Last active August 4, 2023 15:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nbarnwell/f1a97205f4c34d839899e87100afcc9f to your computer and use it in GitHub Desktop.
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
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