Skip to content

Instantly share code, notes, and snippets.

@JasonMorgan
Created June 18, 2017 23:13
Show Gist options
  • Save JasonMorgan/e18f181d1dbe2523f99e11d3339e6244 to your computer and use it in GitHub Desktop.
Save JasonMorgan/e18f181d1dbe2523f99e11d3339e6244 to your computer and use it in GitHub Desktop.
enum bump {
Major
Minor
Patch
}
function Update-CookbookVersion {
param (
[string]$path,
[bump]$bump = 'Patch'
)
$string = Get-Content -Path $path -Raw
[version]$version = $string.Split("`n").Where{$_ -match 'version'}.Split("'")[1]
switch ($bump) {
'Major' {
$new = ($version.Major + 1), $version.Minor, $version.Build -join '.'
}
'Minor' {
$new = $version.Major, ($version.Minor + 1), $version.Build -join '.'
}
'Patch' {
$new = $version.Major, $version.Minor, ($version.Build + 1) -join '.'
}
}
$new = "version '$new'"
($string -replace "version '.*'", $new).Split("`n").Where{$_.length -gt 1} > $path
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment